Module: Filemaker::Model::Fields::ClassMethods

Defined in:
lib/filemaker/model/fields.rb

Instance Method Summary collapse

Instance Method Details

#add_field(name, type, options) ⇒ Object



74
75
76
77
78
# File 'lib/filemaker/model/fields.rb', line 74

def add_field(name, type, options)
  name = name.to_s
  fields[name] = Filemaker::Model::Field.new(name, type, options)
  self.identity = fields[name] if options[:identity]
end

#attribute_namesObject



57
58
59
# File 'lib/filemaker/model/fields.rb', line 57

def attribute_names
  fields.keys
end

#create_accessors(name) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/filemaker/model/fields.rb', line 80

def create_accessors(name)
  name = name.to_s # Normalize it so ActiveModel::Serialization can work

  define_attribute_methods name

  # Reader
  define_method(name) do
    attributes[name]
  end

  # Writer - We try to map to the correct type, if not we just return
  # original.
  define_method("#{name}=") do |value|
    public_send("#{name}_will_change!") unless value == attributes[name]
    attributes[name] = fields[name].coerce(value, self.class)
  end

  # Predicate
  define_method("#{name}?") do
    attributes[name] == true || attributes[name].present?
  end
end

#find_field_by_name(name) ⇒ Object

Find FileMaker’s real name given either the attribute name or the real FileMaker name.



105
106
107
108
109
110
# File 'lib/filemaker/model/fields.rb', line 105

def find_field_by_name(name)
  name = name.to_s
  fields.values.find do |f|
    f.name == name || f.fm_name == name
  end
end