Class: MongoDoc::Scope::CriteriaProxy
Instance Attribute Summary collapse
-
#criteria ⇒ Object
Returns the value of attribute criteria.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#parent_scope ⇒ Object
Returns the value of attribute parent_scope.
Instance Method Summary collapse
-
#initialize(parent_scope, criteria, options, &block) ⇒ CriteriaProxy
constructor
A new instance of CriteriaProxy.
- #respond_to?(method, include_private = false) ⇒ Boolean
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, , &block) [.delete(:extend)].flatten.each { |extension| extend extension } if .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
#criteria ⇒ Object
Returns the value of attribute criteria.
32 33 34 |
# File 'lib/mongo_doc/scope.rb', line 32 def criteria @criteria end |
#klass ⇒ Object
Returns the value of attribute klass.
32 33 34 |
# File 'lib/mongo_doc/scope.rb', line 32 def klass @klass end |
#parent_scope ⇒ Object
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
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 |