Module: Filemaker::Model::Fields
- Extended by:
- ActiveSupport::Concern
- Included in:
- Components
- Defined in:
- lib/filemaker/model/fields.rb
Overview
‘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
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#apply_defaults ⇒ Object
Apply default value when you instantiate a new model.
- #attribute_names ⇒ Object
- #attributes ⇒ Object
- #fm_names ⇒ Object
Instance Method Details
#apply_defaults ⇒ Object
Apply default value when you instantiate a new model.
29 30 31 32 33 34 |
# 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 ⇒ Object
36 37 38 |
# File 'lib/filemaker/model/fields.rb', line 36 def attribute_names self.class.attribute_names end |
#attributes ⇒ Object
44 45 46 47 48 49 50 51 52 |
# 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 ⇒ Object
40 41 42 |
# File 'lib/filemaker/model/fields.rb', line 40 def fm_names fields.values.map(&:fm_name) end |