diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-06-09 10:29:55 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-06-09 10:29:55 -0300 |
commit | 103b282130dd340143654801430aed787da4c9c6 (patch) | |
tree | eddbe800d02f1a3c23f6266b808e74656af31f82 /activeresource/lib | |
parent | fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90 (diff) | |
parent | a94e7d7897a300a95d5d5a00c5efc573b42bcb58 (diff) | |
download | rails-103b282130dd340143654801430aed787da4c9c6.tar.gz rails-103b282130dd340143654801430aed787da4c9c6.tar.bz2 rails-103b282130dd340143654801430aed787da4c9c6.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activeresource/lib')
-rw-r--r-- | activeresource/lib/active_resource.rb | 19 | ||||
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 23 | ||||
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 2 | ||||
-rw-r--r-- | activeresource/lib/active_resource/custom_methods.rb | 73 | ||||
-rw-r--r-- | activeresource/lib/active_resource/formats/json_format.rb | 4 | ||||
-rw-r--r-- | activeresource/lib/active_resource/http_mock.rb | 1 | ||||
-rw-r--r-- | activeresource/lib/active_resource/validations.rb | 13 |
7 files changed, 56 insertions, 79 deletions
diff --git a/activeresource/lib/active_resource.rb b/activeresource/lib/active_resource.rb index b46801affc..1dcb795a7d 100644 --- a/activeresource/lib/active_resource.rb +++ b/activeresource/lib/active_resource.rb @@ -25,18 +25,15 @@ activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib" $:.unshift(activesupport_path) if File.directory?(activesupport_path) require 'active_support' -begin - require 'active_model' -rescue LoadError - $:.unshift "#{File.dirname(__FILE__)}/../../activemodel/lib" - require 'active_model' -end - -require 'active_resource/formats' -require 'active_resource/base' -require 'active_resource/validations' -require 'active_resource/custom_methods' +activemodel_path = "#{File.dirname(__FILE__)}/../../activemodel/lib" +$:.unshift(activemodel_path) if File.directory?(activemodel_path) +require 'active_model' module ActiveResource autoload :Base, 'active_resource/base' + autoload :Connection, 'active_resource/connection' + autoload :CustomMethods, 'active_resource/custom_methods' + autoload :Formats, 'active_resource/formats' + autoload :Validations, 'active_resource/validations' + autoload :HttpMock, 'active_resource/http_mock' end diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 11a7bbba3e..a4f2a7e16a 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -10,10 +10,9 @@ require 'active_support/core_ext/object/misc' require 'set' require 'uri' -module ActiveResource - autoload :Formats, 'active_resource/formats' - autoload :Connection, 'active_resource/connection' +require 'active_resource/exceptions' +module ActiveResource # ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application. # # For an outline of what Active Resource is capable of, see link:files/vendor/rails/activeresource/README.html. @@ -873,7 +872,7 @@ module ActiveResource attributes.to_xml({:root => self.class.element_name}.merge(options)) end - # Converts the resource to a JSON string representation. + # Coerces to a hash for JSON encoding. # # ==== Options # The +options+ are passed to the +to_json+ method on each @@ -897,8 +896,8 @@ module ActiveResource # # person.to_json(:except => ["first_name"]) # # => {"last_name": "Smith"} - def to_json(options={}) - ActiveSupport::JSON.encode(attributes, options) + def as_json(options = nil) + attributes.as_json(options) end # Returns the serialized string representation of the resource in the configured @@ -1072,11 +1071,6 @@ module ActiveResource self.class.__send__(:split_options, options) end - # For compatibility with ActiveSupport::JSON.encode - def rails_to_json(options, *args) - to_json(options) - end - def method_missing(method_symbol, *arguments) #:nodoc: method_name = method_symbol.to_s @@ -1090,7 +1084,8 @@ module ActiveResource end end end -end -require 'active_resource/validations' -require 'active_resource/custom_methods' + class Base + include CustomMethods, Validations + end +end diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 6661469c5b..fb3fde59d6 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -1,5 +1,3 @@ -require 'active_resource/exceptions' -require 'active_resource/formats' require 'active_support/core_ext/benchmark' require 'net/https' require 'date' diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index 0d05d06035..ff14b49b07 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -31,47 +31,44 @@ module ActiveResource # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}] # module CustomMethods - def self.included(base) - base.class_eval do - extend ActiveResource::CustomMethods::ClassMethods - include ActiveResource::CustomMethods::InstanceMethods + extend ActiveSupport::Concern - class << self - alias :orig_delete :delete + included do + class << self + alias :orig_delete :delete - # Invokes a GET to a given custom REST method. For example: - # - # Person.get(:active) # GET /people/active.xml - # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}] - # - # Person.get(:active, :awesome => true) # GET /people/active.xml?awesome=true - # # => [{:id => 1, :name => 'Ryan'}] - # - # Note: the objects returned from this method are not automatically converted - # into ActiveResource::Base instances - they are ordinary Hashes. If you are expecting - # ActiveResource::Base instances, use the <tt>find</tt> class method with the - # <tt>:from</tt> option. For example: - # - # Person.find(:all, :from => :active) - def get(custom_method_name, options = {}) - connection.get(custom_method_collection_url(custom_method_name, options), headers) - end + # Invokes a GET to a given custom REST method. For example: + # + # Person.get(:active) # GET /people/active.xml + # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}] + # + # Person.get(:active, :awesome => true) # GET /people/active.xml?awesome=true + # # => [{:id => 1, :name => 'Ryan'}] + # + # Note: the objects returned from this method are not automatically converted + # into ActiveResource::Base instances - they are ordinary Hashes. If you are expecting + # ActiveResource::Base instances, use the <tt>find</tt> class method with the + # <tt>:from</tt> option. For example: + # + # Person.find(:all, :from => :active) + def get(custom_method_name, options = {}) + connection.get(custom_method_collection_url(custom_method_name, options), headers) + end - def post(custom_method_name, options = {}, body = '') - connection.post(custom_method_collection_url(custom_method_name, options), body, headers) - end + def post(custom_method_name, options = {}, body = '') + connection.post(custom_method_collection_url(custom_method_name, options), body, headers) + end - def put(custom_method_name, options = {}, body = '') - connection.put(custom_method_collection_url(custom_method_name, options), body, headers) - end + def put(custom_method_name, options = {}, body = '') + connection.put(custom_method_collection_url(custom_method_name, options), body, headers) + end - def delete(custom_method_name, options = {}) - # Need to jump through some hoops to retain the original class 'delete' method - if custom_method_name.is_a?(Symbol) - connection.delete(custom_method_collection_url(custom_method_name, options), headers) - else - orig_delete(custom_method_name, options) - end + def delete(custom_method_name, options = {}) + # Need to jump through some hoops to retain the original class 'delete' method + if custom_method_name.is_a?(Symbol) + connection.delete(custom_method_collection_url(custom_method_name, options), headers) + else + orig_delete(custom_method_name, options) end end end @@ -117,8 +114,4 @@ module ActiveResource end end end - - class Base - include CustomMethods - end end diff --git a/activeresource/lib/active_resource/formats/json_format.rb b/activeresource/lib/active_resource/formats/json_format.rb index 101027d99e..9980634921 100644 --- a/activeresource/lib/active_resource/formats/json_format.rb +++ b/activeresource/lib/active_resource/formats/json_format.rb @@ -13,8 +13,8 @@ module ActiveResource "application/json" end - def encode(hash, options={}) - hash.to_json(options) + def encode(hash, options = nil) + ActiveSupport::JSON.encode(hash, options) end def decode(json) diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index aae2d6508c..e5891300a6 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -1,4 +1,3 @@ -require 'active_resource/connection' require 'active_support/core_ext/kernel/reporting' module ActiveResource diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index 95c5467647..a2ba224998 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -1,4 +1,3 @@ -require 'active_resource/exceptions' require 'active_support/core_ext/array/wrap' module ActiveResource @@ -46,10 +45,10 @@ module ActiveResource # person.save # => true (and person is now saved to the remote service) # module Validations - def self.included(base) # :nodoc: - base.class_eval do - alias_method_chain :save, :validation - end + extend ActiveSupport::Concern + + included do + alias_method_chain :save, :validation end # Validate a resource and save (POST) it to the remote web service. @@ -80,8 +79,4 @@ module ActiveResource @errors ||= Errors.new(self) end end - - class Base - include Validations - end end |