Module: FmRest::Spyke::Model::Orm

Extended by:
ActiveSupport::Concern
Included in:
FmRest::Spyke::Model, Attributes
Defined in:
lib/fmrest/spyke/model/orm.rb

Instance Method Summary collapse

Instance Method Details

#reloadObject



104
105
106
107
108
# File 'lib/fmrest/spyke/model/orm.rb', line 104

def reload
  reloaded = self.class.find(id)
  self.attributes = reloaded.attributes
  self.mod_id = reloaded.mod_id
end

#save(options = {}) ⇒ Object

Completely override Spyke's save to provide a number of features:

  • Validations
  • Data API scripts execution
  • Refresh of dirty attributes


84
85
86
87
88
89
90
91
# File 'lib/fmrest/spyke/model/orm.rb', line 84

def save(options = {})
  callback = persisted? ? :update : :create

  return false unless perform_save_validations(callback, options)
  return false unless perform_save_persistence(callback, options)

  true
end

#save!(options = {}) ⇒ Object



93
94
95
# File 'lib/fmrest/spyke/model/orm.rb', line 93

def save!(options = {})
  save(options.merge(raise_validation_errors: true))
end

#update!(new_attributes) ⇒ Object

API-error-raising version of #update



99
100
101
102
# File 'lib/fmrest/spyke/model/orm.rb', line 99

def update!(new_attributes)
  self.attributes = new_attributes
  save!
end