Class: MongoDoc::NamedScope::CriteriaProxy
- Defined in:
- lib/mongodoc/named_scope.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#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, conditions, &block) ⇒ CriteriaProxy
constructor
A new instance of CriteriaProxy.
- #respond_to?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(parent_scope, conditions, &block) ⇒ CriteriaProxy
Returns a new instance of CriteriaProxy.
25 26 27 28 29 30 31 |
# File 'lib/mongodoc/named_scope.rb', line 25 def initialize(parent_scope, conditions, &block) conditions ||= {} [conditions.delete(:extend)].flatten.each { |extension| extend extension } if conditions.include?(:extend) extend Module.new(&block) if block_given? self.klass = parent_scope unless CriteriaProxy === parent_scope self.parent_scope, self.conditions = parent_scope, conditions end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mongodoc/named_scope.rb', line 49 def method_missing(method, *args, &block) if scopes.include?(method) scopes[method].call(self, *args) elsif klass proxy_found.send(method, *args, &block) else parent_scope.criteria(conditions) parent_scope.send(method, *args, &block) end end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
21 22 23 |
# File 'lib/mongodoc/named_scope.rb', line 21 def conditions @conditions end |
#klass ⇒ Object
Returns the value of attribute klass.
21 22 23 |
# File 'lib/mongodoc/named_scope.rb', line 21 def klass @klass end |
#parent_scope ⇒ Object
Returns the value of attribute parent_scope.
21 22 23 |
# File 'lib/mongodoc/named_scope.rb', line 21 def parent_scope @parent_scope end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
33 34 35 36 37 38 39 |
# File 'lib/mongodoc/named_scope.rb', line 33 def respond_to?(method, include_private = false) super || if klass proxy_found.respond_to?(method, include_private) else parent_scope.respond_to?(method, include_private) end end |