module Filemaker::Model::Fields

`Fields` help to give `Model` their perceived schema. To find out your fields, use `Model.fm_fields` or use Rails generator like:

rails generate filemaker:model filename database layout

@example

class Model
  include Filemaker::Model

  string :id, identity: true
  string :title, fm_name: 'A_Title', default: 'Untitled'
  money  :salary
end

Public Instance Methods

apply_defaults() click to toggle source

Apply default value when you instantiate a new model. @See Model.new

# File lib/filemaker/model/fields.rb, line 29
def apply_defaults
  attribute_names.each do |name|
    field = fields[name]
    instance_variable_set("@#{name}", field.default_value)
  end
end
attribute_names() click to toggle source
# File lib/filemaker/model/fields.rb, line 36
def attribute_names
  self.class.attribute_names
end
attributes() click to toggle source
# File lib/filemaker/model/fields.rb, line 44
def attributes
  fields.keys.each_with_object({}) do |field, hash|
    # Attributes must be strings, not symbols - See
    # http://api.rubyonrails.org/classes/ActiveModel/Serialization.html
    hash[field.to_s] = instance_variable_get("@#{field}")

    # If we use public_send(field) will encounter Stack Too Deep
  end
end
fm_names() click to toggle source
# File lib/filemaker/model/fields.rb, line 40
def fm_names
  fields.values.map(&:fm_name)
end