Module: ActiveResource::Singleton::ClassMethods
- Defined in:
- lib/active_resource/singleton.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#find(options = {}) ⇒ Object
Core method for finding singleton resources.
-
#singleton_path(prefix_options = {}, query_options = nil) ⇒ Object
Gets the singleton path for the object.
Instance Attribute Details
#singleton_name ⇒ Object
10 11 12 |
# File 'lib/active_resource/singleton.rb', line 10 def singleton_name @singleton_name ||= model_name.element end |
Instance Method Details
#find(options = {}) ⇒ Object
Core method for finding singleton resources.
Arguments
Takes a single argument of options
Options
-
:params
- Sets the query and prefix (nested URL) parameters.
Examples
Weather.find
# => GET /weather.json
Weather.find(:params => {:degrees => 'fahrenheit'})
# => GET /weather.json?degrees=fahrenheit
Failure or missing data
A failure to find the requested object raises a ResourceNotFound exception.
Inventory.find
# => raises ResourceNotFound
65 66 67 |
# File 'lib/active_resource/singleton.rb', line 65 def find( = {}) find_singleton() end |
#singleton_path(prefix_options = {}, query_options = nil) ⇒ Object
Gets the singleton path for the object. If the query_options
parameter is omitted, Rails will split from the prefix options.
Options
-
prefix_options
- A hash to add a prefix to the request for nested URLs (e.g.,:account_id => 19
would yield a URL like /accounts/19/purchases.json
).
-
query_options
- A hash to add items to the query string for the request.
Examples
Weather.singleton_path
# => /weather.json
class Inventory < ActiveResource::Base
self.site = "https://37s.sunrise.com"
self.prefix = "/products/:product_id/"
end
Inventory.singleton_path(:product_id => 5)
# => /products/5/inventory.json
Inventory.singleton_path({:product_id => 5}, {:sold => true})
# => /products/5/inventory.json?sold=true
38 39 40 41 42 43 |
# File 'lib/active_resource/singleton.rb', line 38 def singleton_path( = {}, = nil) () , = () if .nil? "#{prefix()}#{singleton_name}#{format_extension}#{query_string()}" end |