Module: ActiveSerialize::Relation
- Defined in:
- lib/active_serialize/relation.rb
Instance Method Summary collapse
Instance Method Details
#to_ha(pluck: [ ], plucked: nil, **args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/active_serialize/relation.rb', line 5 def to_ha(pluck: [ ], plucked: nil, **args) plucked ||= if pluck.is_a?(Proc) instance_eval(&pluck) else (_active_serialize[:pluck] + pluck).map { |key| [ key, instance_eval(&method(key)) ] }.to_h end if plucked.present? each_with_index.map do |record, i| record.to_h(plucked: plucked.each_key.map { |k| [ k, plucked[k][i] ] }.to_h, **args) end else map { |record| record.to_h(**args) } end end |
#with_ha(*args) ⇒ Object
22 23 24 |
# File 'lib/active_serialize/relation.rb', line 22 def with_ha(*args) return to_ha(*args), self end |