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
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 |
#destroy ⇒ Object
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 |
#id ⇒ Object
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 |
#key ⇒ Object
97 98 99 |
# File 'lib/mor/model.rb', line 97 def key self.class.key(self.id) end |
#save ⇒ Object
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 |