Module: Mor::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/mor/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attributesObject



98
99
100
# File 'lib/mor/model.rb', line 98

def attributes
  @attributes ||= ActiveSupport::HashWithIndifferentAccess.new
end

#attributes=(attributes) ⇒ Object



102
103
104
# File 'lib/mor/model.rb', line 102

def attributes= attributes
  @attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
end

#destroyObject



131
132
133
134
135
# File 'lib/mor/model.rb', line 131

def destroy
  run_callbacks :destroy do
    Mor.cache.delete(self.key)
  end
end

#idObject



110
111
112
# File 'lib/mor/model.rb', line 110

def id
  self.attributes[self.class.primary_key]
end

#id=(val) ⇒ Object



114
115
116
# File 'lib/mor/model.rb', line 114

def id=val
  self.attributes[self.class.primary_key]=val
end

#keyObject



106
107
108
# File 'lib/mor/model.rb', line 106

def key
  self.class.key(self.id)
end

#saveObject



125
126
127
128
129
# File 'lib/mor/model.rb', line 125

def save
  if self.valid?
    save_or_update
  end
end

#update(attributes = {}) ⇒ Object

CRUD



120
121
122
123
# File 'lib/mor/model.rb', line 120

def update attributes = {}
  self.attributes.update attributes
  self.save
end