Module: Mongoid::Extensions::Array
- Defined in:
- lib/mongoid/extensions/array.rb
Overview
Adds type-casting behavior to Array class.
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 deprecated Deprecated.
-
#__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.
-
#delete_one(object) ⇒ Object
Delete the first object in the array that is equal to the supplied object and return it.
-
#mongoize ⇒ Array | nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
- #multi_arged? ⇒ true | false deprecated Deprecated.
-
#resizable? ⇒ true
Returns whether the object's size can be changed.
Instance Method Details
#__evolve_object_id__ ⇒ Array<BSON::ObjectId>
Evolve the array into an array of object ids.
13 14 15 16 |
# File 'lib/mongoid/extensions/array.rb', line 13 def __evolve_object_id__ map!(&:__evolve_object_id__) self end |
#__find_args__ ⇒ Array
Get the array of args as arguments for a find query.
25 26 27 |
# File 'lib/mongoid/extensions/array.rb', line 25 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.
36 37 38 39 |
# File 'lib/mongoid/extensions/array.rb', line 36 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.
52 53 54 |
# File 'lib/mongoid/extensions/array.rb', line 52 def __mongoize_time__ ::Time.zone.local(*self) 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 since it does not perform multiple deletes.
89 90 91 92 |
# File 'lib/mongoid/extensions/array.rb', line 89 def delete_one(object) position = index(object) position ? delete_at(position) : nil end |
#mongoize ⇒ Array | nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
75 76 77 |
# File 'lib/mongoid/extensions/array.rb', line 75 def mongoize ::Array.mongoize(self) end |
#multi_arged? ⇒ true | false
Is the array a set of multiple arguments in a method?
63 64 65 |
# File 'lib/mongoid/extensions/array.rb', line 63 def multi_arged? (!first.is_a?(Hash) && first.resizable?) || size > 1 end |
#resizable? ⇒ true
Returns whether the object's size can be changed.
100 101 102 |
# File 'lib/mongoid/extensions/array.rb', line 100 def resizable? true end |