lib/daywalker/legislator.rb in technicalpickles-daywalker-0.1.1 vs lib/daywalker/legislator.rb in technicalpickles-daywalker-0.1.2

- old
+ new

@@ -75,11 +75,13 @@ end # Find one or many legislators, based on a set of conditions. See # VALID_ATTRIBUTES for possible attributes you can search for. # - # If you want one legislators, and you expect there is exactly one legislator, use :one. An error will be raised if there are more than one result. + # If you want one legislators, and you expect there is exactly one + # legislator, use :one. An error will be raised if there are more than + # one result. An ArgumentErrror will be raised if multiple results come back. # # Daywalker::Legislator.find(:one, :state => 'NY', :district => 4) # # Otherwise, use :all. # @@ -113,11 +115,10 @@ send(method_id, *args, &block) else super end end - def self.respond_to?(method_id) # :nodoc: match = DynamicFinderMatch.new(method_id) if match.match? true @@ -125,9 +126,16 @@ super end end protected + + def self.handle_bad_request(body) # :nodoc: + case body + when "Multiple Legislators Returned" then raise(ArgumentError, "The conditions provided returned multiple results, by only one is expected") + else super + end + end def self.create_finder_method(method, finder, attribute_names) # :nodoc: class_eval %{ def self.#{method}(*args) # def self.find_all_by_district_number_and_state(*args)