Module: Mongoid::Criteria::Scopable
- Included in:
- Mongoid::Criteria
- Defined in:
- build/mongoid-7.3/lib/mongoid/criteria/scopable.rb
Instance Method Summary collapse
-
#apply_default_scope ⇒ Criteria
Applies the default scope to the criteria.
-
#remove_scoping(other) ⇒ Criteria
Given another criteria, remove the other criteria’s scoping from this criteria.
-
#scoped(options = nil) ⇒ Criteria
Forces the criteria to be scoped, unless its inside an unscoped block.
-
#scoped? ⇒ true, false
Has the criteria had the default scope applied?.
-
#scoping_options ⇒ Array
Get the criteria scoping options, as a pair (scoped, unscoped).
-
#scoping_options=(options) ⇒ Array
Set the criteria scoping options, as a pair (scoped, unscoped).
-
#unscoped ⇒ Criteria
Clears all scoping from the criteria.
-
#unscoped? ⇒ true, false
Is the criteria unscoped?.
-
#with_default_scope ⇒ Criteria
Get the criteria with the default scope applied, if the default scope is able to be applied.
Instance Method Details
#apply_default_scope ⇒ Criteria
Applies the default scope to the criteria.
16 17 18 19 20 21 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 16 def apply_default_scope klass.without_default_scope do merge!(klass.default_scoping.call) end self. = true, false end |
#remove_scoping(other) ⇒ Criteria
Given another criteria, remove the other criteria’s scoping from this criteria.
34 35 36 37 38 39 40 41 42 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 34 def remove_scoping(other) if other reject_matching(other, :selector, :options) other.inclusions.each do || inclusions.delete_one() end end self end |
#scoped(options = nil) ⇒ Criteria
Forces the criteria to be scoped, unless its inside an unscoped block.
54 55 56 57 58 59 60 61 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 54 def scoped( = nil) crit = clone crit..merge!( || {}) if klass.default_scopable? && !scoped? crit.apply_default_scope end crit end |
#scoped? ⇒ true, false
Has the criteria had the default scope applied?
71 72 73 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 71 def scoped? !!(defined?(@scoped) ? @scoped : nil) end |
#scoping_options ⇒ Array
Get the criteria scoping options, as a pair (scoped, unscoped).
112 113 114 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 112 def [ (defined?(@scoped) ? @scoped : nil), (defined?(@unscoped) ? @unscoped : nil) ] end |
#scoping_options=(options) ⇒ Array
Set the criteria scoping options, as a pair (scoped, unscoped).
126 127 128 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 126 def () @scoped, @unscoped = end |
#unscoped ⇒ Criteria
Clears all scoping from the criteria.
83 84 85 86 87 88 89 90 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 83 def unscoped crit = clone unless unscoped? crit. = false, true crit.selector.clear; crit..clear end crit end |
#unscoped? ⇒ true, false
Is the criteria unscoped?
100 101 102 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 100 def unscoped? !!(defined?(@unscoped) ? @unscoped : nil) end |
#with_default_scope ⇒ Criteria
Get the criteria with the default scope applied, if the default scope is able to be applied. Cases in which it cannot are: If we are in an unscoped block, if the criteria is already forced unscoped, or the default scope has already been applied.
141 142 143 144 145 146 147 |
# File 'build/mongoid-7.3/lib/mongoid/criteria/scopable.rb', line 141 def with_default_scope crit = clone if klass.default_scopable? && !unscoped? && !scoped? crit.apply_default_scope end crit end |