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



89
90
91
# File 'lib/mor/model.rb', line 89

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

#attributes=(attributes) ⇒ Object



93
94
95
# File 'lib/mor/model.rb', line 93

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

#destroyObject



122
123
124
125
126
# File 'lib/mor/model.rb', line 122

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

#idObject



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

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

#id=(val) ⇒ Object



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

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

#keyObject



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

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

#saveObject



116
117
118
119
120
# File 'lib/mor/model.rb', line 116

def save
  if self.valid?
    save_or_update
  end
end

#update(attributes = {}) ⇒ Object

CRUD



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

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