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

Instance Method Details

#destroyObject



97
98
99
100
# File 'lib/foundation_api/table/persistence.rb', line 97

def destroy
  raise DestroyNotSupported unless persistence_options[:destroy]
  persisted? && remote_destroy(self.id)
end

#destroy!Object



102
103
104
105
# File 'lib/foundation_api/table/persistence.rb', line 102

def destroy!
  raise RecordNotPersistent unless persisted?
  destroy || raise(RecordNotDeleted)
end

#map_attributesObject



89
90
91
92
93
94
95
# File 'lib/foundation_api/table/persistence.rb', line 89

def map_attributes
  if persistence_options[:hash_to_array]
    Hash[attributes.collect { |key, value| [key, value.is_a?( Hash) ? value.to_a : value] } ]
  else
    attributes
  end
end

#new_record?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/foundation_api/table/persistence.rb', line 85

def new_record?
  !persisted?
end

#persisted?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/foundation_api/table/persistence.rb', line 81

def persisted?
  !!self[:id] 
end

#save(options = {}) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/foundation_api/table/persistence.rb', line 68

def save(options = {})
  check_persistence_support rescue false
  self[:id] ||= remote_create(self)
  @id = self[:id].to_i if self[:id].to_i != 0 rescue
  ::Rails.logger.debug "FoundationApi::Table::Persistence.save: after save: #{self.inspect}"
  self
end

#save!(options = {}) ⇒ Object



76
77
78
79
# File 'lib/foundation_api/table/persistence.rb', line 76

def save!(options = {})
  check_persistence_support
  self.save || raise( RecordNotSaved)
end