Module: FoundationApi::Table::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Record
- Defined in:
- lib/foundation_api/table/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #map_attributes ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#destroy ⇒ Object
96 97 98 99 |
# File 'lib/foundation_api/table/persistence.rb', line 96 def destroy raise DestroyNotSupported unless [:destroy] persisted? && remote_destroy(self.id) end |
#destroy! ⇒ Object
101 102 103 104 |
# File 'lib/foundation_api/table/persistence.rb', line 101 def destroy! raise RecordNotPersistent unless persisted? destroy || raise(RecordNotDeleted) end |
#map_attributes ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/foundation_api/table/persistence.rb', line 88 def map_attributes if [:hash_to_array] Hash[attributes.collect { |key, value| [key, value.is_a?( Hash) ? value.to_a : value] } ] else attributes end end |
#new_record? ⇒ Boolean
84 85 86 |
# File 'lib/foundation_api/table/persistence.rb', line 84 def new_record? !persisted? end |
#persisted? ⇒ Boolean
80 81 82 |
# File 'lib/foundation_api/table/persistence.rb', line 80 def persisted? !!self[:id] end |
#save(options = {}) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/foundation_api/table/persistence.rb', line 68 def save( = {}) check_persistence_support rescue false self[:id] ||= remote_create(self) ::Rails.logger.debug "FoundationApi::Table::Persistence.save: after save: #{self.inspect}" self end |
#save!(options = {}) ⇒ Object
75 76 77 78 |
# File 'lib/foundation_api/table/persistence.rb', line 75 def save!( = {}) check_persistence_support self.save || raise( RecordNotSaved) end |