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

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
# 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(create_attributes, options)
    changes_applied
    replace_new_data(resultset)
  end
  self
end

#destroyFilemaker::Model Also known as: delete

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

Returns:



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

def destroy
  return if new_record?

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

#reload!Object

public_send(“#key=”, (value || ”))

end

end



93
94
95
96
97
# File 'lib/filemaker/model/persistable.rb', line 93

def reload!
  resultset = api.find(record_id)
  replace_new_data(resultset)
  self
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 StandardError => e
  errors.add(:base) << e.message # Does this works?
  false
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



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

def update
  return false unless valid?
  return true if dirty_attributes.empty?

  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, dirty_attributes, options)
    changes_applied
    replace_new_data(resultset)
  end
  self
end

#update_attributes(attrs = {}) ⇒ Object



52
53
54
55
56
57
# File 'lib/filemaker/model/persistable.rb', line 52

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

  assign_attributes(attrs)
  save
end

#update_attributes!(attrs = {}) ⇒ Object



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

def update_attributes!(attrs = {})
  return self if attrs.blank?

  assign_attributes(attrs)
  save!
end