module Filemaker::Model::Fields::ClassMethods

Public Instance Methods

add_field(name, type, options) click to toggle source
# File lib/filemaker/model/fields.rb, line 89
def add_field(name, type, options)
  name = name.to_s.freeze
  fields[name] = Filemaker::Model::Field.new(name, type, options)
  self.identity = fields[name] if options[:identity]
end
attribute_names() click to toggle source
# File lib/filemaker/model/fields.rb, line 55
def attribute_names
  fields.keys
end
create_accessors(name) click to toggle source
# File lib/filemaker/model/fields.rb, line 95
def create_accessors(name)
  # Normalize it so ActiveModel::Serialization can work
  name = name.to_s

  define_attribute_methods name

  # Reader
  define_method(name) do
    instance_variable_get("@#{name}")
  end

  # Writer - We try to map to the correct type, if not we just return
  # original.
  define_method("#{name}=") do |value|
    new_value = fields[name].serialize_for_update(value)

    public_send("#{name}_will_change!") \
      if new_value != public_send(name)

    instance_variable_set("@#{name}", new_value)
  end

  # Predicate
  define_method("#{name}?") do
    # See ActiveRecord::AttributeMethods::Query implementation
    public_send(name) == true || public_send(name).present?
  end
end
find_field_by_name(name) click to toggle source

Find FileMaker's real name given either the attribute name or the real FileMaker name. FIXME - This may have ordering problem. If fm_name is the same as the field name.

# File lib/filemaker/model/fields.rb, line 128
def find_field_by_name(name)
  name = name.to_s
  fields.values.find do |f|
    f.name == name || f.fm_name == name

    # Unfortunately can't use this as builder.rb need to find field based
    # on fm_name
    # Always find by attribute name for now
    # f.name == name
  end
end