Module: Filemaker::Model::Builder
- Defined in:
- lib/filemaker/model/builder.rb
Class Method Summary collapse
-
.collection(resultset, klass) ⇒ Object
Given an array of resultset, build out the exact same number of model objects.
- .single(resultset, klass) ⇒ Object
Class Method Details
.collection(resultset, klass) ⇒ Object
Given an array of resultset, build out the exact same number of model objects.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/filemaker/model/builder.rb', line 8 def collection(resultset, klass) models = [] resultset.each do |record| object = klass.new object.instance_variable_set('@new_record', false) object.instance_variable_set('@record_id', record.record_id) object.instance_variable_set('@mod_id', record.mod_id) object.instance_variable_set('@portals', record.portals) record.keys.each do |fm_field_name| # record.keys are all lowercase field = klass.find_field_by_name(fm_field_name) next unless field # Because we are using ActiveModel::Dirty, so we hydrate directly. object.attributes[field.name] = field.coerce(record[fm_field_name]) end models << object end models end |
.single(resultset, klass) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/filemaker/model/builder.rb', line 34 def single(resultset, klass) record = resultset.first object = klass.new object.instance_variable_set('@new_record', false) object.instance_variable_set('@record_id', record.record_id) object.instance_variable_set('@mod_id', record.mod_id) object.instance_variable_set('@portals', record.portals) record.keys.each do |fm_field_name| # record.keys are all lowercase field = klass.find_field_by_name(fm_field_name) next unless field object.public_send("#{field.name}=", record[fm_field_name]) end object end |