Module: Mongoid::Extensions::Array
- Defined in:
- lib/mongoid/extensions/array.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#__evolve_object_id__ ⇒ Array<Moped::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<Moped::BSON::ObjectId>
Mongoize the array into an array of object ids.
-
#__mongoize_time__ ⇒ Time
Converts the array for storing as a time.
-
#blank_criteria? ⇒ true, false
Check if the array is part of a blank relation criteria.
-
#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<Moped::BSON::ObjectId>
Evolve the array into an array of object ids.
14 15 16 17 |
# File 'lib/mongoid/extensions/array.rb', line 14 def __evolve_object_id__ map!(&:__evolve_object_id__) self end |
#__find_args__ ⇒ Array
Get the array of args as arguments for a find query.
27 28 29 |
# File 'lib/mongoid/extensions/array.rb', line 27 def __find_args__ flat_map{ |a| a.__find_args__ }.uniq{ |a| a.to_s } end |
#__mongoize_object_id__ ⇒ Array<Moped::BSON::ObjectId>
Mongoize the array into an array of object ids.
39 40 41 42 |
# File 'lib/mongoid/extensions/array.rb', line 39 def __mongoize_object_id__ map!(&:__mongoize_object_id__).compact! self end |
#__mongoize_time__ ⇒ Time
Converts the array for storing as a time.
52 53 54 |
# File 'lib/mongoid/extensions/array.rb', line 52 def __mongoize_time__ ::Time.configured.local(*self) end |
#blank_criteria? ⇒ true, false
Check if the array is part of a blank relation criteria.
64 65 66 |
# File 'lib/mongoid/extensions/array.rb', line 64 def blank_criteria? any?(&:blank_criteria?) 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.
106 107 108 109 |
# File 'lib/mongoid/extensions/array.rb', line 106 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.
89 90 91 |
# File 'lib/mongoid/extensions/array.rb', line 89 def mongoize ::Array.mongoize(self) end |
#multi_arged? ⇒ true, false
Is the array a set of multiple arguments in a method?
76 77 78 |
# File 'lib/mongoid/extensions/array.rb', line 76 def multi_arged? !first.is_a?(Hash) && first.resizable? || size > 1 end |
#resizable? ⇒ true
Is the object’s size changable?
119 120 121 |
# File 'lib/mongoid/extensions/array.rb', line 119 def resizable? true end |