Module: MongoMapper::Finders Private

Included in:
Associations::ManyDocumentsProxy
Defined in:
lib/mongo_mapper.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#dynamic_find(finder, args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mongo_mapper.rb', line 72

def dynamic_find(finder, args)
  attributes = {}
  finder.attributes.each_with_index do |attr, index|
    attributes[attr] = args[index]
  end
  
  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

    if finder.instantiator
      self.send(finder.instantiator, attributes)
    end
  else
    result
  end
end