Module: MongoMapper::Plugins::Querying::Decorator

Includes:
DynamicQuerying::ClassMethods
Defined in:
lib/mongo_mapper/plugins/querying/decorator.rb

Instance Method Summary collapse

Methods included from DynamicQuerying::ClassMethods

#dynamic_find

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



25
26
27
28
29
30
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 25

def method_missing(method, *args, &block)
  return super unless model.respond_to?(method)
  result = model.send(method, *args, &block)
  return super unless result.is_a?(Plucky::Query)
  merge(result)
end

Instance Method Details

#find!(*ids) ⇒ Object

Raises:



14
15
16
17
18
19
20
21
22
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 14

def find!(*ids)
  raise DocumentNotFound, "Couldn't find without an ID" if ids.size == 0

  find(*ids).tap do |result|
    if result.nil? || ids.size != Array(result).size
      raise DocumentNotFound, "Couldn't find all of the ids (#{ids.join(',')}). Found #{Array(result).size}, but was expecting #{ids.size}"
    end
  end
end

#model(model = nil) ⇒ Object



8
9
10
11
12
# File 'lib/mongo_mapper/plugins/querying/decorator.rb', line 8

def model(model=nil)
  return @model if model.nil?
  @model = model
  self
end