Module: Filemaker::Model::Persistable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Components
- Defined in:
- lib/filemaker/model/persistable.rb
Instance Method Summary collapse
-
#assign_attributes(new_attributes) ⇒ Object
If value is nil, we convert to empty string so it will get pick up by ‘fm_attributes`.
- #create ⇒ Object
-
#destroy ⇒ Filemaker::Model
(also: #delete)
Use -delete to remove the record backed by the model.
- #reload! ⇒ Object
-
#save ⇒ Object
Call save! but do not raise error.
- #save! ⇒ Object
- #update ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
Instance Method Details
#assign_attributes(new_attributes) ⇒ Object
If value is nil, we convert to empty string so it will get pick up by ‘fm_attributes`
74 75 76 77 78 79 80 81 82 |
# File 'lib/filemaker/model/persistable.rb', line 74 def assign_attributes(new_attributes) return if new_attributes.blank? new_attributes.each_pair do |key, value| next unless respond_to?("#{key}=") public_send("#{key}=", (value || '')) end end |
#create ⇒ Object
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 = {} yield if block_given? resultset = api.new(fm_attributes, ) replace_new_data(resultset) end self end |
#destroy ⇒ Filemaker::Model Also known as: delete
Use -delete to remove the record backed by the model.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/filemaker/model/persistable.rb', line 59 def destroy return if new_record? run_callbacks :destroy do = {} yield if block_given? api.delete(record_id, ) end freeze end |
#reload! ⇒ Object
84 85 86 87 88 89 |
# File 'lib/filemaker/model/persistable.rb', line 84 def reload! reset_changes resultset = api.find(record_id) replace_new_data(resultset) self end |
#save ⇒ Object
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 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 |
#update ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/filemaker/model/persistable.rb', line 36 def update return false unless valid? return true if dirty_attributes.empty? run_callbacks :update do # Will raise `RecordModificationIdMismatchError` if does not match = { modid: mod_id } # Always pass in? yield if block_given? resultset = api.edit(record_id, dirty_attributes, ) changes_applied replace_new_data(resultset) end self end |
#update_attributes(attrs = {}) ⇒ Object
51 52 53 54 55 |
# File 'lib/filemaker/model/persistable.rb', line 51 def update_attributes(attrs = {}) return self if attrs.blank? assign_attributes(attrs) save end |