Class: FmStore::Builders::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/fm_store/builders/collection.rb

Class Method Summary collapse

Class Method Details

.build(records, model) ⇒ Object

Build an array of native object (i.e. Job, Payroll, etc) from the FileMaker records.

Pass in the desired model



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fm_store/builders/collection.rb', line 9

def self.build(records, model)
  target = []

  records.each do |record|
    fm_fields = record.keys

    obj = model.new

    fm_fields.each do |fm_field|
      field = model.fields[fm_field] # Field
      obj.instance_variable_set("@#{field.name}", record[fm_field]) if field.respond_to?(:name)
    end

    obj.instance_variable_set("@new_record", false)
    obj.instance_variable_set("@mod_id", record.mod_id)
    obj.instance_variable_set("@record_id", record.record_id)

    target << obj
  end

  return target
end