module MarkMapper::Plugins::DynamicQuerying::ClassMethods

Public Instance Methods

dynamic_find(finder, args) click to toggle source
# File lib/mark_mapper/plugins/dynamic_querying.rb, line 10
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)

  if result = send(finder.finder, options)
    result
  else
    if finder.raise?
      raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
    end

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

Protected Instance Methods

method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/mark_mapper/plugins/dynamic_querying.rb, line 33
def method_missing(method, *args, &block)
  finder = DynamicFinder.new(method)

  if finder.found?
    dynamic_find(finder, args)
  else
    super
  end
end