Module: Superstore::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/superstore/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroyObject



91
92
93
94
# File 'lib/superstore/persistence.rb', line 91

def destroy
  self.class.delete(id)
  @destroyed = true
end

#destroyed?Boolean



79
80
81
# File 'lib/superstore/persistence.rb', line 79

def destroyed?
  @destroyed
end

#new_record?Boolean



75
76
77
# File 'lib/superstore/persistence.rb', line 75

def new_record?
  @new_record
end

#persisted?Boolean



83
84
85
# File 'lib/superstore/persistence.rb', line 83

def persisted?
  !(new_record? || destroyed?)
end

#reloadObject



116
117
118
119
120
# File 'lib/superstore/persistence.rb', line 116

def reload
  clear_association_cache
  @attributes = self.class.find(id).instance_variable_get('@attributes')
  self
end

#saveObject



87
88
89
# File 'lib/superstore/persistence.rb', line 87

def save(*)
  create_or_update
end

#update(attributes) ⇒ Object Also known as: update_attributes



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

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

#update!(attributes) ⇒ Object Also known as: update_attributes!



109
110
111
112
# File 'lib/superstore/persistence.rb', line 109

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

#update_attribute(name, value) ⇒ Object



96
97
98
99
100
# File 'lib/superstore/persistence.rb', line 96

def update_attribute(name, value)
  name = name.to_s
  send("#{name}=", value)
  save(validate: false)
end