Module: Mongoid::Criteria::Queryable::Extensions::Array
- Defined in:
- lib/mongoid/criteria/queryable/extensions/array.rb
Overview
The array module adds custom behaviour for Origin onto the Array class.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__add__(object) ⇒ Object
Combine the two objects using the add strategy.
-
#__array__ ⇒ Array
Return the object as an array.
-
#__deep_copy__ ⇒ Array
Makes a deep copy of the array, deep copying every element inside the array.
-
#__evolve_date__ ⇒ Array<Time>
Evolve the array into an array of mongo friendly dates.
-
#__evolve_time__ ⇒ Array<Time>
Evolve the array to an array of times.
-
#__expand_complex__ ⇒ Array
Get the object as expanded.
-
#__intersect__(object) ⇒ Object
Combine the two objects using an intersection strategy.
-
#__sort_option__ ⇒ Hash
Gets the array as options in the proper format to pass as MongoDB sort criteria.
-
#__sort_pair__ ⇒ Hash
Get the array as a sort pair.
-
#update_values(&block) ⇒ Array
Update all the values in the hash with the provided block.
Instance Method Details
#__add__(object) ⇒ Object
Combine the two objects using the add strategy.
20 21 22 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 20 def __add__(object) object.__add_from_array__(self) end |
#__array__ ⇒ Array
Return the object as an array.
32 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 32 def __array__; self; end |
#__deep_copy__ ⇒ Array
Makes a deep copy of the array, deep copying every element inside the array.
43 44 45 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 43 def __deep_copy__ map { |value| value.__deep_copy__ } end |
#__evolve_date__ ⇒ Array<Time>
Evolve the array into an array of mongo friendly dates. (Times at midnight).
56 57 58 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 56 def __evolve_date__ map { |value| value.__evolve_date__ } end |
#__evolve_time__ ⇒ Array<Time>
Evolve the array to an array of times.
82 83 84 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 82 def __evolve_time__ map { |value| value.__evolve_time__ } end |
#__expand_complex__ ⇒ Array
Get the object as expanded.
68 69 70 71 72 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 68 def map do |value| value. end end |
#__intersect__(object) ⇒ Object
Combine the two objects using an intersection strategy.
96 97 98 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 96 def __intersect__(object) object.__intersect_from_array__(self) end |
#__sort_option__ ⇒ Hash
Gets the array as options in the proper format to pass as MongoDB sort criteria.
109 110 111 112 113 114 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 109 def __sort_option__ multi.inject({}) do |, criteria| .merge!(criteria.__sort_pair__) end end |
#__sort_pair__ ⇒ Hash
Get the array as a sort pair.
124 125 126 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 124 def __sort_pair__ { first => last.to_direction } end |
#update_values(&block) ⇒ Array
Update all the values in the hash with the provided block.
138 139 140 |
# File 'lib/mongoid/criteria/queryable/extensions/array.rb', line 138 def update_values(&block) replace(map(&block)) end |