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