Class: Mongoid::Contextual::Mongo
- Inherits:
-
Object
- Object
- Mongoid::Contextual::Mongo
- Defined in:
- lib/pluck_all/models/mongoid_extension.rb
Instance Method Summary collapse
Instance Method Details
#pluck_all(*fields) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/pluck_all/models/mongoid_extension.rb', line 57 def pluck_all(*fields) normalized_select = get_normalized_select(fields) get_query_data(normalized_select).reduce([]) do |plucked, doc| values = normalized_select.keys.map(&plucked_value_mapper(:all, doc)) plucked << values.to_h end end |
#pluck_array(*fields) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/pluck_all/models/mongoid_extension.rb', line 49 def pluck_array(*fields) normalized_select = get_normalized_select(fields) get_query_data(normalized_select).reduce([]) do |plucked, doc| values = normalized_select.keys.map(&plucked_value_mapper(:array, doc)) plucked << (values.size == 1 ? values.first : values) end end |