Module: Mongoid::Criterion::Scoping
- Included in:
- Mongoid::Criteria
- Defined in:
- lib/mongoid/criterion/scoping.rb
Instance Attribute Summary collapse
-
#default_scopable ⇒ Object
Returns the value of attribute default_scopable.
Instance Method Summary collapse
-
#apply_default_scope ⇒ Criteria
Apply the model’s default scope to this criteria.
-
#clear_scoping ⇒ nil
Remove all scoping from the criteria.
-
#default_scopable? ⇒ true, false
Is the default scope of the class allowed to be applied?.
-
#scoped ⇒ Criteria
Force the default scope to be applied to the criteria.
-
#unscoped ⇒ Criteria
Get the criteria with the default scoping removed.
Instance Attribute Details
#default_scopable ⇒ Object
Returns the value of attribute default_scopable.
6 7 8 |
# File 'lib/mongoid/criterion/scoping.rb', line 6 def default_scopable @default_scopable end |
Instance Method Details
#apply_default_scope ⇒ Criteria
Apply the model’s default scope to this criteria.
16 17 18 19 20 21 22 23 |
# File 'lib/mongoid/criterion/scoping.rb', line 16 def apply_default_scope if klass.default_scoping && default_scopable? self.default_scopable = false fuse(klass.default_scoping) else self end end |
#clear_scoping ⇒ nil
Remove all scoping from the criteria.
77 78 79 80 |
# File 'lib/mongoid/criterion/scoping.rb', line 77 def clear_scoping selector.clear .clear end |
#default_scopable? ⇒ true, false
Is the default scope of the class allowed to be applied?
33 34 35 |
# File 'lib/mongoid/criterion/scoping.rb', line 33 def default_scopable? default_scopable != false end |
#scoped ⇒ Criteria
Force the default scope to be applied to the criteria.
45 46 47 48 |
# File 'lib/mongoid/criterion/scoping.rb', line 45 def scoped self.default_scopable = true apply_default_scope end |
#unscoped ⇒ Criteria
This has slightly different behaviour than AR - will remove the default scoping if no other criteria have been chained and tampered with the criterion instead of clearing everything.
Get the criteria with the default scoping removed.
62 63 64 65 66 67 |
# File 'lib/mongoid/criterion/scoping.rb', line 62 def unscoped clone.tap do |criteria| criteria.clear_scoping criteria.default_scopable = false end end |