Module: Filemaker::Model::Persistable

Extended by:
ActiveSupport::Concern
Included in:
Components
Defined in:
lib/filemaker/model/persistable.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(new_attributes) ⇒ Object



69
70
71
72
73
74
# File 'lib/filemaker/model/persistable.rb', line 69

def assign_attributes(new_attributes)
  return if new_attributes.blank?
  new_attributes.each_pair do |key, value|
    public_send("#{key}=", value) if respond_to?("#{key}=")
  end
end

#createObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/filemaker/model/persistable.rb', line 24

def create
  return false unless valid?

  run_callbacks :create do
    options = {}
    yield options if block_given?
    resultset = api.new(fm_attributes, options)
    replace_new_data(resultset)
  end
  self
end

#destroyFilemaker::Model Also known as: delete

Use -delete to remove the record backed by the model.

Returns:



57
58
59
60
61
62
63
64
65
66
# File 'lib/filemaker/model/persistable.rb', line 57

def destroy
  return if new_record?

  run_callbacks :destroy do
    options = {}
    yield options if block_given?
    api.delete(record_id, options)
  end
  freeze
end

#saveObject

Call save! but do not raise error.



11
12
13
14
15
16
# File 'lib/filemaker/model/persistable.rb', line 11

def save
  save!
rescue
  errors.add(:base) << $! # Does this works?
  nil
end

#save!Object



18
19
20
21
22
# File 'lib/filemaker/model/persistable.rb', line 18

def save!
  run_callbacks :save do
    new_record? ? create : update
  end
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/filemaker/model/persistable.rb', line 36

def update
  return false unless valid?

  run_callbacks :update do
    # Will raise `RecordModificationIdMismatchError` if does not match
    options = { modid: mod_id } # Always pass in?
    yield options if block_given?
    resultset = api.edit(record_id, fm_attributes, options)
    replace_new_data(resultset)
  end
  self
end

#update_attributes(attrs = {}) ⇒ Object



49
50
51
52
53
# File 'lib/filemaker/model/persistable.rb', line 49

def update_attributes(attrs = {})
  return self if attrs.blank?
  assign_attributes(attrs)
  save
end