Module: Filemaker::Model::Fields::ClassMethods
- Defined in:
- lib/filemaker/model/fields.rb
Instance Method Summary collapse
- #add_field(name, type, options) ⇒ Object
- #attribute_names ⇒ Object
- #create_accessors(name) ⇒ Object
-
#find_field_by_name(name) ⇒ Object
Find FileMaker’s real name given either the attribute name or the real FileMaker name.
Instance Method Details
#add_field(name, type, options) ⇒ Object
89 90 91 92 93 |
# File 'lib/filemaker/model/fields.rb', line 89 def add_field(name, type, ) name = name.to_s.freeze fields[name] = Filemaker::Model::Field.new(name, type, ) self.identity = fields[name] if [:identity] end |
#attribute_names ⇒ Object
55 56 57 |
# File 'lib/filemaker/model/fields.rb', line 55 def attribute_names fields.keys end |
#create_accessors(name) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# 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) ⇒ Object
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.
128 129 130 131 132 133 134 135 136 137 138 |
# 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 |