Class: MultipleMan::ModelPopulator

Inherits:
Object
  • Object
show all
Defined in:
lib/multiple_man/model_populator.rb

Instance Method Summary collapse

Constructor Details

#initialize(record, fields) ⇒ ModelPopulator

Returns a new instance of ModelPopulator.



4
5
6
7
# File 'lib/multiple_man/model_populator.rb', line 4

def initialize(record, fields)
  self.record = record
  self.fields = fields
end

Instance Method Details

#populate(payload) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/multiple_man/model_populator.rb', line 9

def populate(payload)
  data = payload[:id].merge(payload[:data])
  fields_for(data).each do |field|
    source, dest = field.is_a?(Array) ? field : [field, field]
    populate_field(dest, data[source])
  end
  record
end