Module: Mongoid::Criteria::Queryable::Extensions::Hash
- Defined in:
- lib/mongoid/criteria/queryable/extensions/hash.rb
Overview
This module contains additional hash behavior.
Instance Method Summary collapse
-
#__add__(object) ⇒ Hash
Add an object to a hash using the merge strategies.
-
#__add_from_array__(array) ⇒ Hash
Merge this hash into the provided array.
-
#__deep_copy__ ⇒ Hash
Make a deep copy of this hash.
-
#__expand_complex__ ⇒ Hash
Get the object as expanded.
-
#__intersect__(object) ⇒ Hash
Add an object to a hash using the merge strategies.
-
#__intersect_from_array__(array) ⇒ Hash
Merge this hash into the provided array.
-
#__intersect_from_object__(object) ⇒ Hash
Merge this hash into the provided object.
-
#__sort_option__ ⇒ Hash
Get the hash as a sort option.
-
#__union__(object) ⇒ Hash
Add an object to a hash using the merge strategies.
-
#__union_from_object__(object) ⇒ Hash
Merge this hash into the provided object.
-
#update_values(&block) ⇒ Hash
Update all the values in the hash with the provided block.
Instance Method Details
#__add__(object) ⇒ Hash
Add an object to a hash using the merge strategies.
19 20 21 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 19 def __add__(object) apply_strategy(:__add__, object) end |
#__add_from_array__(array) ⇒ Hash
Merge this hash into the provided array.
31 32 33 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 31 def __add_from_array__(array) { keys.first => array.__add__(values.first) } end |
#__deep_copy__ ⇒ Hash
Make a deep copy of this hash.
101 102 103 104 105 106 107 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 101 def __deep_copy__ {}.tap do |copy| each_pair do |key, value| copy.store(key, value.__deep_copy__) end end end |
#__expand_complex__ ⇒ Hash
Get the object as expanded.
129 130 131 132 133 134 135 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 129 def replacement = {} each_pair do |key, value| replacement.merge!(key.__expr_part__(value.)) end replacement end |
#__intersect__(object) ⇒ Hash
Add an object to a hash using the merge strategies.
43 44 45 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 43 def __intersect__(object) apply_strategy(:__intersect__, object) end |
#__intersect_from_array__(array) ⇒ Hash
Merge this hash into the provided array.
55 56 57 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 55 def __intersect_from_array__(array) { keys.first => array.__intersect__(values.first) } end |
#__intersect_from_object__(object) ⇒ Hash
Merge this hash into the provided object.
67 68 69 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 67 def __intersect_from_object__(object) { keys.first => object.__intersect__(values.first) } end |
#__sort_option__ ⇒ Hash
Get the hash as a sort option.
115 116 117 118 119 120 121 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 115 def __sort_option__ tap do |hash| hash.each_pair do |key, value| hash.store(key, value.to_direction) end end end |
#__union__(object) ⇒ Hash
Add an object to a hash using the merge strategies.
79 80 81 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 79 def __union__(object) apply_strategy(:__union__, object) end |
#__union_from_object__(object) ⇒ Hash
Merge this hash into the provided object.
91 92 93 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 91 def __union_from_object__(object) { keys.first => object.__union__(values.first) } end |
#update_values(&block) ⇒ Hash
Update all the values in the hash with the provided block.
145 146 147 148 149 |
# File 'lib/mongoid/criteria/queryable/extensions/hash.rb', line 145 def update_values(&block) each_pair do |key, value| store(key, block[value]) end end |