Module: Mor::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mor/model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
- #id=(val) ⇒ Object
- #key ⇒ Object
- #save ⇒ Object
-
#update(attributes = {}) ⇒ Object
CRUD.
Instance Method Details
#attributes ⇒ Object
82 83 84 |
# File 'lib/mor/model.rb', line 82 def attributes @attributes ||= ActiveSupport::HashWithIndifferentAccess.new end |
#attributes=(attributes) ⇒ Object
86 87 88 |
# File 'lib/mor/model.rb', line 86 def attributes= attributes @attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes) end |
#destroy ⇒ Object
115 116 117 118 119 |
# File 'lib/mor/model.rb', line 115 def destroy run_callbacks :destroy do Mor.cache.delete(self.key) end end |
#id ⇒ Object
94 95 96 |
# File 'lib/mor/model.rb', line 94 def id self.attributes[self.class.primary_key] end |
#id=(val) ⇒ Object
98 99 100 |
# File 'lib/mor/model.rb', line 98 def id=val self.attributes[self.class.primary_key]=val end |
#key ⇒ Object
90 91 92 |
# File 'lib/mor/model.rb', line 90 def key self.class.key(self.id) end |
#save ⇒ Object
109 110 111 112 113 |
# File 'lib/mor/model.rb', line 109 def save if self.valid? save_or_update end end |
#update(attributes = {}) ⇒ Object
CRUD
104 105 106 107 |
# File 'lib/mor/model.rb', line 104 def update attributes = {} self.attributes.update attributes self.save end |