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
80 81 82 |
# File 'lib/mor/model.rb', line 80 def attributes @attributes ||= ActiveSupport::HashWithIndifferentAccess.new end |
#attributes=(attributes) ⇒ Object
84 85 86 |
# File 'lib/mor/model.rb', line 84 def attributes= attributes @attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes) end |
#destroy ⇒ Object
113 114 115 116 117 |
# File 'lib/mor/model.rb', line 113 def destroy run_callbacks :destroy do Mor.cache.delete(self.key) end end |
#id ⇒ Object
92 93 94 |
# File 'lib/mor/model.rb', line 92 def id self.attributes[self.class.primary_key] end |
#id=(val) ⇒ Object
96 97 98 |
# File 'lib/mor/model.rb', line 96 def id=val self.attributes[self.class.primary_key]=val end |
#key ⇒ Object
88 89 90 |
# File 'lib/mor/model.rb', line 88 def key self.class.key(self.id) end |
#save ⇒ Object
107 108 109 110 111 |
# File 'lib/mor/model.rb', line 107 def save if self.valid? save_or_update end end |
#update(attributes = {}) ⇒ Object
CRUD
102 103 104 105 |
# File 'lib/mor/model.rb', line 102 def update attributes = {} self.attributes.update attributes self.save end |