From 0ee1cb2cd32bfaf47deaf5440dd5b9cf0915ab6a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 2 Oct 2007 05:32:14 +0000 Subject: Ruby 1.9 compat, consistent load paths git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activeresource/lib/active_resource/base.rb | 4 ++-- .../lib/active_resource/custom_methods.rb | 24 ++++++++++------------ activeresource/lib/active_resource/http_mock.rb | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index d99a047df1..9fb347d2c3 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -604,7 +604,7 @@ module ActiveResource # next_invoice.customer # # => That Company def dup - returning new do |resource| + returning self.class.new do |resource| resource.attributes = @attributes resource.prefix_options = @prefix_options end @@ -848,7 +848,7 @@ module ActiveResource end def split_options(options = {}) - self.class.send(:split_options, options) + self.class.send!(:split_options, options) end def method_missing(method_symbol, *arguments) #:nodoc: diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index a8857b8461..e08c664307 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -33,23 +33,24 @@ module ActiveResource module CustomMethods def self.included(within) within.class_eval do + extend ActiveResource::CustomMethods::ClassMethods + include ActiveResource::CustomMethods::InstanceMethods + class << self - include ActiveResource::CustomMethods::ClassMethods - alias :orig_delete :delete - + def get(method_name, options = {}) connection.get(custom_method_collection_url(method_name, options), headers) end - + def post(method_name, options = {}, body = '') connection.post(custom_method_collection_url(method_name, options), body, headers) end - + def put(method_name, options = {}, body = '') connection.put(custom_method_collection_url(method_name, options), body, headers) end - + # Need to jump through some hoops to retain the original class 'delete' method def delete(custom_method_name, options = {}) if (custom_method_name.is_a?(Symbol)) @@ -59,12 +60,9 @@ module ActiveResource end end end - end - - within.send(:include, ActiveResource::CustomMethods::InstanceMethods) end - + module ClassMethods def custom_method_collection_url(method_name, options = {}) prefix_options, query_options = split_options(options) @@ -96,12 +94,12 @@ module ActiveResource private def custom_method_element_url(method_name, options = {}) - "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.xml#{self.class.send(:query_string, options)}" + "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.xml#{self.class.send!(:query_string, options)}" end def custom_method_new_element_url(method_name, options = {}) - "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.xml#{self.class.send(:query_string, options)}" + "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.xml#{self.class.send!(:query_string, options)}" end end end -end \ No newline at end of file +end diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index c9a2c21f31..37fc1f2bfe 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -75,7 +75,7 @@ module ActiveResource attr_accessor :path, :method, :body, :headers def initialize(method, path, body = nil, headers = {}) - @method, @path, @body, @headers = method, path, body, headers + @method, @path, @body, @headers = method, path, body, headers.dup @headers.update('Content-Type' => 'application/xml') end -- cgit v1.2.3