Module: NinjaModel::Persistence
- Included in:
- Base
- Defined in:
- lib/ninja_model/persistence.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
- #update ⇒ Object
- #update_attributes(attributes) ⇒ Object
Instance Method Details
#create ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ninja_model/persistence.rb', line 16 def create run_callbacks :create do if self.class.adapter.create(self) @persisted = true end @persisted end end |
#destroy ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/ninja_model/persistence.rb', line 43 def destroy run_callbacks :destroy do if self.class.adapter.destroy(self) @destroyed = true end @destroyed end end |
#destroyed? ⇒ Boolean
35 36 37 |
# File 'lib/ninja_model/persistence.rb', line 35 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
31 32 33 |
# File 'lib/ninja_model/persistence.rb', line 31 def new_record? !@persisted end |
#persisted? ⇒ Boolean
39 40 41 |
# File 'lib/ninja_model/persistence.rb', line 39 def persisted? @persisted && !destroyed? end |
#reload ⇒ Object
52 53 54 |
# File 'lib/ninja_model/persistence.rb', line 52 def reload self.class.adapter.reload(self) end |
#save ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/ninja_model/persistence.rb', line 8 def save(*) run_callbacks :save do result = new_record? ? create : update changed_attributes.clear if result result end end |
#update ⇒ Object
25 26 27 28 29 |
# File 'lib/ninja_model/persistence.rb', line 25 def update run_callbacks :update do self.class.adapter.update(self) end end |
#update_attributes(attributes) ⇒ Object
56 57 58 59 |
# File 'lib/ninja_model/persistence.rb', line 56 def update_attributes(attributes) self.attributes = attributes save end |