lib/mongo_mapper.rb in mongo_mapper-0.5.6 vs lib/mongo_mapper.rb in mongo_mapper-0.5.7

- old
+ new

@@ -1,12 +1,21 @@ require 'active_support' require 'mongo' require 'validatable' module MongoMapper - DocumentNotFound = Class.new(StandardError) - DocumentNotValid = Class.new(StandardError) do + # generic MM error + class MongoMapperError < StandardError; end + + # raised when key expected to exist but not found + class KeyNotFound < MongoMapperError; end + + # raised when document expected but not found + class DocumentNotFound < MongoMapperError; end + + # raised when document not valid and using ! + class DocumentNotValid < MongoMapperError def initialize(document) @document = document super("Validation failed: #{@document.errors.full_messages.join(", ")}") end end @@ -52,16 +61,15 @@ end module Finders def dynamic_find(finder, args) attributes = {} - find_options = args.extract_options!.deep_merge(:conditions => attributes) - finder.attributes.each_with_index do |attr, index| attributes[attr] = args[index] end - - result = find(finder.finder, find_options) + + options = args.extract_options!.merge(attributes) + result = find(finder.finder, options) if result.nil? if finder.bang raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}" end