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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mongo_doc/scope.rb', line 28 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)
52 53 54 55 56 57 58 59 60 |
# File 'lib/mongo_doc/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
#criteria ⇒ Object
Returns the value of attribute criteria.
24 25 26 |
# File 'lib/mongo_doc/scope.rb', line 24 def criteria @criteria end |
#klass ⇒ Object
Returns the value of attribute klass.
24 25 26 |
# File 'lib/mongo_doc/scope.rb', line 24 def klass @klass end |
#parent_scope ⇒ Object
Returns the value of attribute parent_scope.
24 25 26 |
# File 'lib/mongo_doc/scope.rb', line 24 def parent_scope @parent_scope end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
45 46 47 48 |
# File 'lib/mongo_doc/scope.rb', line 45 def respond_to?(method, include_private = false) return true if scopes.include?(method) criteria.respond_to?(method, include_private) end |