diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-27 20:54:53 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-27 20:54:53 +0000 |
commit | 1d5c34c2c27370356e8cd1ef478111802b6a5af4 (patch) | |
tree | a24e73ce006a32b79b80fc09ed74490dffe8a13d /activeresource/lib/active_resource | |
parent | 8326a15784550f8a909e140f828dc0b1c83d617c (diff) | |
download | rails-1d5c34c2c27370356e8cd1ef478111802b6a5af4.tar.gz rails-1d5c34c2c27370356e8cd1ef478111802b6a5af4.tar.bz2 rails-1d5c34c2c27370356e8cd1ef478111802b6a5af4.zip |
Added find-by-path options to ActiveResource::Base.find [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6595 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib/active_resource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 3f7121a7ca..bcc1e8b497 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -113,11 +113,13 @@ module ActiveResource end # Core method for finding resources. Used similarly to Active Record's find method. - # Person.find(1) # => GET /people/1.xml - # Person.find(:all) # => GET /people.xml - # Person.find(:all, :title => "CEO") # => GET /people.xml?title=CEO - # Person.find(:managers) # => GET /people/managers.xml - # StreetAddress.find(1, :person_id => 1) # => GET /people/1/street_addresses/1.xml + # Person.find(1) # => GET /people/1.xml + # Person.find(:all) # => GET /people.xml + # Person.find(:all, :title => "CEO") # => GET /people.xml?title=CEO + # Person.find(:managers) # => GET /people/managers.xml + # Person.find(:all, :from => "/companies/1/people.xml") # => GET /companies/1/people.xml + # Person.find("/companies/1/manager.xml") # => GET /companies/1/manager.xml + # StreetAddress.find(1, :person_id => 1) # => GET /people/1/street_addresses/1.xml def find(*arguments) scope = arguments.slice!(0) options = arguments.slice!(0) || {} @@ -144,8 +146,11 @@ module ActiveResource private # Find every resource. def find_every(options) + from = options.delete(:from) prefix_options, query_options = split_options(options) - instantiate_collection(connection.get(collection_path(prefix_options, query_options)) || []) + from ||= collection_path(prefix_options, query_options) + + instantiate_collection(connection.get(from) || []) end def instantiate_collection(collection, prefix_options = {}) @@ -160,7 +165,9 @@ module ActiveResource # { :person => person1 } def find_single(scope, options) prefix_options, query_options = split_options(options) - returning new(connection.get(element_path(scope, prefix_options, query_options))) do |resource| + from = scope.to_s.include?("/") ? scope : element_path(scope, prefix_options, query_options) + + returning new(connection.get(from)) do |resource| resource.prefix_options = prefix_options end end |