module Filemaker::Model

Attributes

mod_id[R]
new_record[R]
portals[R]
record_id[R]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/filemaker/model.rb, line 15
def initialize(attributes = {})
  # We did not manage to use `ActiveModel::AttributeAssignment`
  # super

  @new_record = true
  @relations = {}
  apply_defaults
  process_attributes(attributes)
  clear_changes_information
end

Public Instance Methods

cache_key() click to toggle source
# File lib/filemaker/model.rb, line 42
def cache_key
  return "#{model_key}/new" if new_record?
  return "#{model_key}/#{id}-#{updated_at.to_datetime.utc.to_s(:number)}" if respond_to?(:updated_at) && send(:updated_at)

  "#{model_key}/#{id}"
end
create_attributes() click to toggle source
# File lib/filemaker/model.rb, line 65
def create_attributes
  self.class.with_model_fields_for_creation(attributes)
end
dirty_attributes() click to toggle source
# File lib/filemaker/model.rb, line 69
def dirty_attributes
  dirty = {}
  changed.each do |attr_name|
    dirty[attr_name] = attributes[attr_name]
  end

  # We need to use serialize_for_update instead
  self.class.with_model_fields_for_update(dirty)
end
fm_attributes() click to toggle source
# File lib/filemaker/model.rb, line 61
def fm_attributes
  self.class.with_model_fields_for_query(attributes)
end
id() click to toggle source
# File lib/filemaker/model.rb, line 49
def id
  self.class.identity ? identity_id : record_id
end
identity_id() click to toggle source
# File lib/filemaker/model.rb, line 53
def identity_id
  public_send(identity.name) if identity
end
model_key() click to toggle source
# File lib/filemaker/model.rb, line 38
def model_key
  @model_key ||= self.class.model_name.cache_key
end
new_record?() click to toggle source
# File lib/filemaker/model.rb, line 26
def new_record?
  new_record
end
persisted?() click to toggle source
# File lib/filemaker/model.rb, line 30
def persisted?
  !new_record?
end
to_a() click to toggle source
# File lib/filemaker/model.rb, line 34
def to_a
  [self]
end
to_param() click to toggle source
# File lib/filemaker/model.rb, line 57
def to_param
  id&.to_s
end

Private Instance Methods

process_attributes(attributes) click to toggle source
# File lib/filemaker/model.rb, line 81
def process_attributes(attributes)
  return if attributes.empty?

  attributes.each_pair do |key, value|
    setter = :"#{key}="
    public_send(setter, value) if respond_to?(setter)
  end
end