Class: MongoDoc::Scope::CriteriaProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_doc/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_scope, criteria, options, &block) ⇒ CriteriaProxy

Returns a new instance of CriteriaProxy.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongo_doc/scope.rb', line 36

def initialize(parent_scope, criteria, options, &block)
  [options.delete(:extend)].flatten.each { |extension| extend extension } if options.include?(:extend)
  extend Module.new(&block) if block_given?
  if CriteriaProxy === parent_scope
    chained = Mongoid::Criteria.new(klass)
    chained.merge(parent_scope)
    chained.merge(criteria)
    self.criteria = chained
    self.klass = criteria.klass
  else
    self.criteria = criteria
    self.klass = parent_scope
  end

  self.parent_scope = parent_scope
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



60
61
62
63
64
65
66
67
68
# File 'lib/mongo_doc/scope.rb', line 60

def method_missing(method, *args, &block)
  if scopes.include?(method)
    scopes[method].call(self, *args)
  else
    chained = Mongoid::Criteria.new(klass)
    chained.merge(criteria)
    chained.send(method, *args, &block)
  end
end

Instance Attribute Details

#criteriaObject

Returns the value of attribute criteria.



32
33
34
# File 'lib/mongo_doc/scope.rb', line 32

def criteria
  @criteria
end

#klassObject

Returns the value of attribute klass.



32
33
34
# File 'lib/mongo_doc/scope.rb', line 32

def klass
  @klass
end

#parent_scopeObject

Returns the value of attribute parent_scope.



32
33
34
# File 'lib/mongo_doc/scope.rb', line 32

def parent_scope
  @parent_scope
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:



53
54
55
56
# File 'lib/mongo_doc/scope.rb', line 53

def respond_to?(method, include_private = false)
  return true if scopes.include?(method)
  criteria.respond_to?(method, include_private)
end