Module: Mongoid::Extensions::Array
- Defined in:
- lib/mongoid/extensions/array.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__evolve_object_id__ ⇒ Array<BSON::ObjectId>
Evolve the array into an array of object ids.
-
#__find_args__ ⇒ Array
Get the array of args as arguments for a find query.
-
#__mongoize_object_id__ ⇒ Array<BSON::ObjectId>
Mongoize the array into an array of object ids.
-
#__mongoize_time__ ⇒ Time | ActiveSupport::TimeWithZone
Converts the array for storing as a time.
- #blank_criteria? ⇒ false deprecated Deprecated.
-
#delete_one(object) ⇒ Object
Delete the first object in the array that is equal to the supplied object and return it.
-
#mongoize ⇒ Array
Turn the object from the ruby type we deal with to a Mongo friendly type.
-
#multi_arged? ⇒ true, false
Is the array a set of multiple arguments in a method?.
-
#resizable? ⇒ true
Is the object’s size changable?.
Instance Method Details
#__evolve_object_id__ ⇒ Array<BSON::ObjectId>
Evolve the array into an array of object ids.
16 17 18 19 |
# File 'lib/mongoid/extensions/array.rb', line 16 def __evolve_object_id__ map!(&:__evolve_object_id__) self end |
#__find_args__ ⇒ Array
Get the array of args as arguments for a find query.
29 30 31 |
# File 'lib/mongoid/extensions/array.rb', line 29 def __find_args__ flat_map{ |a| a.__find_args__ }.uniq{ |a| a.to_s } end |
#__mongoize_object_id__ ⇒ Array<BSON::ObjectId>
Mongoize the array into an array of object ids.
41 42 43 44 |
# File 'lib/mongoid/extensions/array.rb', line 41 def __mongoize_object_id__ map!(&:__mongoize_object_id__).compact! self end |
#__mongoize_time__ ⇒ Time | ActiveSupport::TimeWithZone
Returns a local time in the default time zone.
Converts the array for storing as a time.
59 60 61 |
# File 'lib/mongoid/extensions/array.rb', line 59 def __mongoize_time__ ::Time.configured.local(*self) end |
#blank_criteria? ⇒ false
Checks whether conditions given in this array are known to be unsatisfiable, i.e., querying with this array will always return no documents.
This method used to assume that the array is the list of criteria to be used with an $and operator. This assumption is no longer made; therefore, since the interpretation of conditions in the array differs between $and, $or and $nor operators, this method now always returns false.
This method is deprecated. Mongoid now uses _mongoid_unsatisfiable_criteria?
internally; this method is retained for backwards compatibility only. It always returns false.
81 82 83 |
# File 'lib/mongoid/extensions/array.rb', line 81 def blank_criteria? false end |
#delete_one(object) ⇒ Object
Delete the first object in the array that is equal to the supplied object and return it. This is much faster than performing a standard delete for large arrays ince it attempt to delete multiple in the other.
123 124 125 126 |
# File 'lib/mongoid/extensions/array.rb', line 123 def delete_one(object) position = index(object) position ? delete_at(position) : nil end |
#mongoize ⇒ Array
Turn the object from the ruby type we deal with to a Mongo friendly type.
106 107 108 |
# File 'lib/mongoid/extensions/array.rb', line 106 def mongoize ::Array.mongoize(self) end |
#multi_arged? ⇒ true, false
Is the array a set of multiple arguments in a method?
93 94 95 |
# File 'lib/mongoid/extensions/array.rb', line 93 def multi_arged? !first.is_a?(Hash) && first.resizable? || size > 1 end |
#resizable? ⇒ true
Is the object’s size changable?
136 137 138 |
# File 'lib/mongoid/extensions/array.rb', line 136 def resizable? true end |