From 3e0951632c52018eefb86d9e0bfe77383f9622fb Mon Sep 17 00:00:00 2001 From: Roy Nicholson Date: Sun, 9 Aug 2009 13:57:20 -0400 Subject: Add ability to set SSL options on ARes connections. [#2370 state:committed] Signed-off-by: Jeremy Kemper --- activeresource/lib/active_resource/base.rb | 41 ++++++++++++++++++++++++ activeresource/lib/active_resource/connection.rb | 35 ++++++++++++++++++-- activeresource/lib/active_resource/exceptions.rb | 8 +++++ 3 files changed, 81 insertions(+), 3 deletions(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 9db35881b8..a66ce4c23f 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -103,6 +103,8 @@ module ActiveResource # # Many REST APIs will require authentication, usually in the form of basic # HTTP authentication. Authentication can be specified by: + # + # === HTTP Basic Authentication # * putting the credentials in the URL for the +site+ variable. # # class Person < ActiveResource::Base @@ -123,6 +125,19 @@ module ActiveResource # Note: Some values cannot be provided in the URL passed to site. e.g. email addresses # as usernames. In those situations you should use the separate user and password option. # + # === Certificate Authentication + # + # * End point uses an X509 certificate for authentication. See ssl_options= for all options. + # + # class Person < ActiveResource::Base + # self.site = "https://secure.api.people.com/" + # self.ssl_options = {:cert => OpenSSL::X509::Certificate.new(File.open(pem_file)) + # :key => OpenSSL::PKey::RSA.new(File.open(pem_file)), + # :ca_path => "/path/to/OpenSSL/formatted/CA_Certs", + # :verify_mode => OpenSSL::SSL::VERIFY_PEER} + # end + # + # # == Errors & Validation # # Error handling and validation is handled in much the same manner as you're used to seeing in @@ -342,6 +357,31 @@ module ActiveResource end end + # Options that will get applied to an SSL connection. + # + # * :key - An OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object. + # * :cert - An OpenSSL::X509::Certificate object as client certificate + # * :ca_file - Path to a CA certification file in PEM format. The file can contrain several CA certificates. + # * :ca_path - Path of a CA certification directory containing certifications in PEM format. + # * :verify_mode - Flags for server the certification verification at begining of SSL/TLS session. (OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER is acceptable) + # * :verify_callback - The verify callback for the server certification verification. + # * :verify_depth - The maximum depth for the certificate chain verification. + # * :cert_store - OpenSSL::X509::Store to verify peer certificate. + # * :ssl_timeout -The SSL timeout in seconds. + def ssl_options=(opts={}) + @connection = nil + @ssl_options = opts + end + + # Returns the SSL options hash. + def ssl_options + if defined?(@ssl_options) + @ssl_options + elsif superclass != Object && superclass.ssl_options + superclass.ssl_options + end + end + # An instance of ActiveResource::Connection that is the base \connection to the remote service. # The +refresh+ parameter toggles whether or not the \connection is refreshed at every request # or not (defaults to false). @@ -352,6 +392,7 @@ module ActiveResource @connection.user = user if user @connection.password = password if password @connection.timeout = timeout if timeout + @connection.ssl_options = ssl_options if ssl_options @connection else superclass.connection diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index ef57c1f8b2..c08b7272ae 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -16,7 +16,7 @@ module ActiveResource :delete => 'Accept' } - attr_reader :site, :user, :password, :timeout, :proxy + attr_reader :site, :user, :password, :timeout, :proxy, :ssl_options attr_accessor :format class << self @@ -61,6 +61,11 @@ module ActiveResource @timeout = timeout end + # Hash of options applied to Net::HTTP instance when +site+ protocol is 'https'. + def ssl_options=(opts={}) + @ssl_options = opts + end + # Executes a GET request. # Used to get (find) resources. def get(path, headers = {}) @@ -102,6 +107,8 @@ module ActiveResource handle_response(result) rescue Timeout::Error => e raise TimeoutError.new(e.message) + rescue OpenSSL::SSL::SSLError => e + raise SSLError.new(e.message) end # Handles response and error codes from the remote service. @@ -149,8 +156,7 @@ module ActiveResource end def configure_http(http) - http.use_ssl = @site.is_a?(URI::HTTPS) - http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl? + http = apply_ssl_options(http) # Net::HTTP timeouts default to 60 seconds. if @timeout @@ -161,6 +167,29 @@ module ActiveResource http end + def apply_ssl_options(http) + return http unless @site.is_a?(URI::HTTPS) + + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + return http unless defined?(@ssl_options) + + http.ca_path = @ssl_options[:ca_path] if @ssl_options[:ca_path] + http.ca_file = @ssl_options[:ca_file] if @ssl_options[:ca_file] + + http.cert = @ssl_options[:cert] if @ssl_options[:cert] + http.key = @ssl_options[:key] if @ssl_options[:key] + + http.cert_store = @ssl_options[:cert_store] if @ssl_options[:cert_store] + http.ssl_timeout = @ssl_options[:ssl_timeout] if @ssl_options[:ssl_timeout] + + http.verify_mode = @ssl_options[:verify_mode] if @ssl_options[:verify_mode] + http.verify_callback = @ssl_options[:verify_callback] if @ssl_options[:verify_callback] + http.verify_depth = @ssl_options[:verify_depth] if @ssl_options[:verify_depth] + + http + end + def default_header @default_header ||= {} end diff --git a/activeresource/lib/active_resource/exceptions.rb b/activeresource/lib/active_resource/exceptions.rb index 5e4b1d4487..dd59146b1a 100644 --- a/activeresource/lib/active_resource/exceptions.rb +++ b/activeresource/lib/active_resource/exceptions.rb @@ -20,6 +20,14 @@ module ActiveResource def to_s; @message ;end end + # Raised when a OpenSSL::SSL::SSLError occurs. + class SSLError < ConnectionError + def initialize(message) + @message = message + end + def to_s; @message ;end + end + # 3xx Redirection class Redirection < ConnectionError # :nodoc: def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end -- cgit v1.2.3 From 1fc1986d6deacd71ec4bea2287d9cfed6123b898 Mon Sep 17 00:00:00 2001 From: Jatinder Singh Date: Sun, 9 Aug 2009 22:24:50 +0100 Subject: Make ActiveResource#exists? work [#3020 state:resolved] Signed-off-by: Pratik Naik --- activeresource/lib/active_resource/connection.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index c08b7272ae..884c425c1d 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -13,7 +13,8 @@ module ActiveResource HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept', :put => 'Content-Type', :post => 'Content-Type', - :delete => 'Accept' + :delete => 'Accept', + :head => 'Accept' } attr_reader :site, :user, :password, :timeout, :proxy, :ssl_options @@ -93,7 +94,7 @@ module ActiveResource # Executes a HEAD request. # Used to obtain meta-information about resources, such as whether they exist and their size (via response headers). def head(path, headers = {}) - request(:head, path, build_request_headers(headers)) + request(:head, path, build_request_headers(headers, :head)) end -- cgit v1.2.3 From 916b18adeb0a1ae09fdaff21dda8d0bc8ed4ffa9 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Sun, 9 Aug 2009 22:53:04 +0100 Subject: Active Resource recognizes 410 as Resource Gone now [#2316 state:resolved] [Jordan Brough, Jatinder Singh] Signed-off-by: Pratik Naik --- activeresource/lib/active_resource/base.rb | 3 ++- activeresource/lib/active_resource/connection.rb | 2 ++ activeresource/lib/active_resource/exceptions.rb | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index a66ce4c23f..0311419fd6 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -164,6 +164,7 @@ module ActiveResource # * 404 - ActiveResource::ResourceNotFound # * 405 - ActiveResource::MethodNotAllowed # * 409 - ActiveResource::ResourceConflict + # * 410 - ActiveResource::ResourceGone # * 422 - ActiveResource::ResourceInvalid (rescued by save as validation errors) # * 401..499 - ActiveResource::ClientError # * 500..599 - ActiveResource::ServerError @@ -626,7 +627,7 @@ module ActiveResource response.code.to_i == 200 end # id && !find_single(id, options).nil? - rescue ActiveResource::ResourceNotFound + rescue ActiveResource::ResourceNotFound, ActiveResource::ResourceGone false end diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 884c425c1d..9d551f04e7 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -131,6 +131,8 @@ module ActiveResource raise(MethodNotAllowed.new(response)) when 409 raise(ResourceConflict.new(response)) + when 410 + raise(ResourceGone.new(response)) when 422 raise(ResourceInvalid.new(response)) when 401...500 diff --git a/activeresource/lib/active_resource/exceptions.rb b/activeresource/lib/active_resource/exceptions.rb index dd59146b1a..0631cdcf9f 100644 --- a/activeresource/lib/active_resource/exceptions.rb +++ b/activeresource/lib/active_resource/exceptions.rb @@ -51,6 +51,9 @@ module ActiveResource # 409 Conflict class ResourceConflict < ClientError; end # :nodoc: + # 410 Gone + class ResourceGone < ClientError; end # :nodoc: + # 5xx Server Error class ServerError < ConnectionError; end # :nodoc: -- cgit v1.2.3 From e391c7a97cdefa172fcba214fb0a6cd3bd5b0bf4 Mon Sep 17 00:00:00 2001 From: Grzegorz Forysinski Date: Sun, 9 Aug 2009 18:24:49 -0400 Subject: Ensure ActiveResource#load works with numeric arrays [Grzegorz Forysinski, Elad Meidar] [#2305 state:resolved] Signed-off-by: Pratik Naik --- activeresource/lib/active_resource/base.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 0311419fd6..41ffb5413b 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1020,7 +1020,13 @@ module ActiveResource case value when Array resource = find_or_create_resource_for_collection(key) - value.map { |attrs| attrs.is_a?(String) ? attrs.dup : resource.new(attrs) } + value.map do |attrs| + if attrs.is_a?(String) || attrs.is_a?(Numeric) + attrs.duplicable? ? attrs.dup : attrs + else + resource.new(attrs) + end + end when Hash resource = find_or_create_resource_for(key) resource.new(value) -- cgit v1.2.3 From 797588543ed70b4c5dcf51d7f1e4a77082172f0b Mon Sep 17 00:00:00 2001 From: Fabien Jakimowicz Date: Sun, 9 Aug 2009 15:24:06 +0200 Subject: Add support for errors in JSON format. [#1956 state:committed] Signed-off-by: Jeremy Kemper --- activeresource/lib/active_resource/base.rb | 6 +++++- activeresource/lib/active_resource/validations.rb | 24 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 41ffb5413b..88de8b1c66 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -185,7 +185,7 @@ module ActiveResource # # Active Resource supports validations on resources and will return errors if any of these validations fail # (e.g., "First name can not be blank" and so on). These types of errors are denoted in the response by - # a response code of 422 and an XML representation of the validation errors. The save operation will + # a response code of 422 and an XML or JSON representation of the validation errors. The save operation will # then fail (with a false return value) and the validation errors can be accessed on the resource in question. # # ryan = Person.find(1) @@ -194,10 +194,14 @@ module ActiveResource # # # When # # PUT http://api.people.com:3000/people/1.xml + # # or + # # PUT http://api.people.com:3000/people/1.json # # is requested with invalid values, the response is: # # # # Response (422): # # First cannot be empty + # # or + # # {"errors":["First cannot be empty"]} # # # # ryan.errors.invalid?(:first) # => true diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index a2ba224998..4ff7be6a9e 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -7,11 +7,10 @@ module ActiveResource # Active Resource validation is reported to and from this object, which is used by Base#save # to determine whether the object in a valid state to be saved. See usage example in Validations. class Errors < ActiveModel::Errors - # Grabs errors from the XML response. - def from_xml(xml) + # Grabs errors from an array of messages (like ActiveRecord::Validations) + def from_array(messages) clear humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) } - messages = Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue [] messages.each do |message| attr_message = humanized_attributes.keys.detect do |attr_name| if message[0, attr_name.size + 1] == "#{attr_name} " @@ -22,6 +21,18 @@ module ActiveResource self[:base] << message if attr_message.nil? end end + + # Grabs errors from the json response. + def from_json(json) + array = ActiveSupport::JSON.decode(json)['errors'] rescue [] + from_array array + end + + # Grabs errors from the XML response. + def from_xml(xml) + array = Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue [] + from_array array + end end # Module to support validation and errors with Active Resource objects. The module overrides @@ -56,7 +67,12 @@ module ActiveResource save_without_validation true rescue ResourceInvalid => error - errors.from_xml(error.response.body) + case error.response['Content-Type'] + when 'application/xml' + errors.from_xml(error.response.body) + when 'application/json' + errors.from_json(error.response.body) + end false end -- cgit v1.2.3 From c2f90d6530dfd0ed68df9f4c429d0f498235e1d4 Mon Sep 17 00:00:00 2001 From: taryn Date: Wed, 19 Aug 2009 11:57:50 +0100 Subject: Added validations to ActiveResource. Added a smoke test to see if we can add a validation and use it, and add a validates callback and use it. Signed-off-by: Joshua Peek --- activeresource/lib/active_resource/validations.rb | 64 +++++++++++++++++------ 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index 4ff7be6a9e..d4d282e273 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -8,8 +8,10 @@ module ActiveResource # to determine whether the object in a valid state to be saved. See usage example in Validations. class Errors < ActiveModel::Errors # Grabs errors from an array of messages (like ActiveRecord::Validations) - def from_array(messages) - clear + # The second parameter directs the errors cache to be cleared (default) + # or not (by passing true) + def from_array(messages, save_cache = false) + clear unless save_cache humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) } messages.each do |message| attr_message = humanized_attributes.keys.detect do |attr_name| @@ -22,16 +24,16 @@ module ActiveResource end end - # Grabs errors from the json response. - def from_json(json) + # Grabs errors from a json response. + def from_json(json, save_cache = false) array = ActiveSupport::JSON.decode(json)['errors'] rescue [] - from_array array + from_array array, save_cache end - # Grabs errors from the XML response. - def from_xml(xml) + # Grabs errors from an XML response. + def from_xml(xml, save_cache = false) array = Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue [] - from_array array + from_array array, save_cache end end @@ -57,26 +59,55 @@ module ActiveResource # module Validations extend ActiveSupport::Concern + include ActiveModel::Validations + extend ActiveModel::Validations::ClassMethods included do alias_method_chain :save, :validation end # Validate a resource and save (POST) it to the remote web service. - def save_with_validation - save_without_validation - true + # If any local validations fail - the save (POST) will not be attempted. + def save_with_validation(perform_validation = true) + # clear the remote validations so they don't interfere with the local + # ones. Otherwise we get an endless loop and can never change the + # fields so as to make the resource valid + @remote_errors = nil + if perform_validation && valid? || !perform_validation + save_without_validation + true + else + false + end rescue ResourceInvalid => error - case error.response['Content-Type'] + # cache the remote errors because every call to valid? clears + # all errors. We must keep a copy to add these back after local + # validations + @remote_errors = error + load_remote_errors(@remote_errors, true) + false + end + + + # Loads the set of remote errors into the object's Errors based on the + # content-type of the error-block received + def load_remote_errors(remote_errors, save_cache = false ) #:nodoc: + case remote_errors.response['Content-Type'] when 'application/xml' - errors.from_xml(error.response.body) + errors.from_xml(remote_errors.response.body, save_cache) when 'application/json' - errors.from_json(error.response.body) + errors.from_json(remote_errors.response.body, save_cache) end - false end # Checks for errors on an object (i.e., is resource.errors empty?). + # + # Runs all the specified local validations and returns true if no errors + # were added, otherwise false. + # Runs local validations (eg those on your Active Resource model), and + # also any errors returned from the remote system the last time we + # saved. + # Remote errors can only be cleared by trying to re-save the resource. # # ==== Examples # my_person = Person.create(params[:person]) @@ -86,7 +117,10 @@ module ActiveResource # my_person.errors.add('login', 'can not be empty') if my_person.login == '' # my_person.valid? # # => false + # def valid? + super + load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present? errors.empty? end -- cgit v1.2.3 From 4dc05bc8a9824b9404cebecaba28f9f248f9995e Mon Sep 17 00:00:00 2001 From: taryn Date: Wed, 19 Aug 2009 12:20:30 +0100 Subject: Swallow ResourceNotFound error on find_every Active Record does not explode with RecordNotFound if you go looking for a collection of objects - it just returns nil. Thus Active Resource should also not explode. After all - finding no objects that match a set of conditions is not exceptional behaviour - unlike looking for a specific object with a given id (which you'd expect to exist). I've also added documentation to +find+ to reflect this. Signed-off-by: Joshua Peek --- activeresource/lib/active_resource/base.rb | 39 ++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 88de8b1c66..293ba75ee0 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -585,6 +585,19 @@ module ActiveResource # # StreetAddress.find(1, :params => { :person_id => 1 }) # # => GET /people/1/street_addresses/1.xml + # + # == Failure or missing data + # A failure to find the requested object raises a ResourceNotFound + # exception if the find was called with an id. + # With any other scope, find returns nil when no data is returned. + # + # Person.find(1) + # # => raises ResourcenotFound + # + # Person.find(:all) + # Person.find(:first) + # Person.find(:last) + # # => nil def find(*arguments) scope = arguments.slice!(0) options = arguments.slice!(0) || {} @@ -638,16 +651,22 @@ module ActiveResource private # Find every resource def find_every(options) - case from = options[:from] - when Symbol - instantiate_collection(get(from, options[:params])) - when String - path = "#{from}#{query_string(options[:params])}" - instantiate_collection(connection.get(path, headers) || []) - else - prefix_options, query_options = split_options(options[:params]) - path = collection_path(prefix_options, query_options) - instantiate_collection( (connection.get(path, headers) || []), prefix_options ) + begin + case from = options[:from] + when Symbol + instantiate_collection(get(from, options[:params])) + when String + path = "#{from}#{query_string(options[:params])}" + instantiate_collection(connection.get(path, headers) || []) + else + prefix_options, query_options = split_options(options[:params]) + path = collection_path(prefix_options, query_options) + instantiate_collection( (connection.get(path, headers) || []), prefix_options ) + end + rescue ActiveResource::ResourceNotFound + # Swallowing ResourceNotFound exceptions and return nil - as per + # ActiveRecord. + nil end end -- cgit v1.2.3 From 328ba3b333777bbc1269cbe0e9f590c845006c9d Mon Sep 17 00:00:00 2001 From: taryn Date: Wed, 19 Aug 2009 12:25:05 +0100 Subject: Added save! which raises ResourceInvalid unless valid? Similar to Active Record - it will raise ActiveResouce::ResourceInvalid if the resource is not valid (ie if valid? returns false) However - does not raise ActiveResource::ResourceNotFound if the callbacks fail (callbacks have not yet been implemented) - it will just try to save and raise if the callbacks all fail. This is not ideal behaviour - but will do until we decide to change the behaviour of save_with_validations to actually raise (rather than catch) the ResourceInvalid exception. Signed-off-by: Joshua Peek --- activeresource/lib/active_resource/base.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 293ba75ee0..f27febb7ef 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -893,6 +893,23 @@ module ActiveResource def save new? ? create : update end + + # Saves the resource. + # + # If the resource is new, it is created via +POST+, otherwise the + # existing resource is updated via +PUT+. + # + # With save! validations always run. If any of them fail + # ActiveResource::ResourceInvalid gets raised, and nothing is POSTed to + # the remote system. + # See ActiveResource::Validations for more information. + # + # There's a series of callbacks associated with save!. If any + # of the before_* callbacks return +false+ the action is + # cancelled and save! raises ActiveResource::ResourceInvalid. + def save! + save || raise(ResourceInvalid.new(self)) + end # Deletes the resource from the remote service. # -- cgit v1.2.3 From ce61a6bd551a96205892a125c8835c4bc69c4fad Mon Sep 17 00:00:00 2001 From: taryn Date: Fri, 21 Aug 2009 09:45:29 +0100 Subject: Added first/last/all aliases for equivalent find scopes Just a copy from Active Record (with tests). Each is a warpper function for the equivalent scoped call to find eg first is a wrapper for find(:first) Signed-off-by: Joshua Peek --- activeresource/lib/active_resource/base.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'activeresource/lib') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index f27febb7ef..e5b8589fb3 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -611,6 +611,28 @@ module ActiveResource end end + + # A convenience wrapper for find(:first, *args). You can pass + # in all the same arguments to this method as you can to + # find(:first). + def first(*args) + find(:first, *args) + end + + # A convenience wrapper for find(:last, *args). You can pass + # in all the same arguments to this method as you can to + # find(:last). + def last(*args) + find(:last, *args) + end + + # This is an alias for find(:all). You can pass in all the same + # arguments to this method as you can to find(:all) + def all(*args) + find(:all, *args) + end + + # Deletes the resources with the ID in the +id+ parameter. # # ==== Options -- cgit v1.2.3