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



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

def destroy
  raise DestroyNotSupported unless persistence_options[: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_attributesObject



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

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)


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

def new_record?
  !persisted?
end

#persisted?Boolean

Returns:

  • (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(options = {})
  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!(options = {})
  check_persistence_support
  self.save || raise( RecordNotSaved)
end