Class: MongoDoc::Scope::CriteriaProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mongodoc/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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mongodoc/scope.rb', line 28

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)



52
53
54
55
56
57
58
59
60
# File 'lib/mongodoc/scope.rb', line 52

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.



24
25
26
# File 'lib/mongodoc/scope.rb', line 24

def criteria
  @criteria
end

#klassObject

Returns the value of attribute klass.



24
25
26
# File 'lib/mongodoc/scope.rb', line 24

def klass
  @klass
end

#parent_scopeObject

Returns the value of attribute parent_scope.



24
25
26
# File 'lib/mongodoc/scope.rb', line 24

def parent_scope
  @parent_scope
end

Instance Method Details

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

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/mongodoc/scope.rb', line 45

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