module Evvnt::Persistence

Provides methods for saving an individual record to the API

Public Instance Methods

new_record?() click to toggle source

Is this record an unsaved/fresh record?

Returns a Boolean

# File lib/evvnt/persistence.rb, line 14
def new_record?
  unique_identifier.blank?
end
persisted?() click to toggle source

Has this record been saved on the EVVNT API?

Returns a Boolean

# File lib/evvnt/persistence.rb, line 7
def persisted?
  unique_identifier.present?
end
save() click to toggle source

Save this record to the EVVNT API

Returns {Evvnt::Base} subclass

# File lib/evvnt/persistence.rb, line 21
def save
  new_record? ? save_as_new_record : save_as_persisted_record
end

Private Instance Methods

save_as_new_record() click to toggle source

Save this record to the EVVNT API as a new record using the create action.

# File lib/evvnt/persistence.rb, line 29
def save_as_new_record
  new_attributes = attributes.reject { |k, _v| k.to_s =~ /^(id|uuid)$/ }
  self.class.create(new_attributes)
end
save_as_persisted_record() click to toggle source

Save this record to the EVVNT API as an existing record using the update action.

# File lib/evvnt/persistence.rb, line 36
def save_as_persisted_record
  new_attributes = attributes.reject { |k, _v| k.to_s =~ /^(id|uuid)$/ }
  self.class.update(id, new_attributes)
end