Module: NinjaModel::Persistence::InstanceMethods
- 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
18 19 20 21 22 23 24 25 |
# File 'lib/ninja_model/persistence.rb', line 18 def create run_callbacks :create do if self.class.adapter.create(self) @persisted = true end @persisted end end |
#destroy ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/ninja_model/persistence.rb', line 45 def destroy run_callbacks :destroy do if self.class.adapter.destroy(self) @destroyed = true end @destroyed end end |
#destroyed? ⇒ Boolean
37 38 39 |
# File 'lib/ninja_model/persistence.rb', line 37 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
33 34 35 |
# File 'lib/ninja_model/persistence.rb', line 33 def new_record? !@persisted end |
#persisted? ⇒ Boolean
41 42 43 |
# File 'lib/ninja_model/persistence.rb', line 41 def persisted? @persisted && !destroyed? end |
#reload ⇒ Object
54 55 56 |
# File 'lib/ninja_model/persistence.rb', line 54 def reload self.class.adapter.reload(self) end |
#save ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ninja_model/persistence.rb', line 10 def save(*) run_callbacks :save do result = new_record? ? create : update changed_attributes.clear if result result end end |
#update ⇒ Object
27 28 29 30 31 |
# File 'lib/ninja_model/persistence.rb', line 27 def update run_callbacks :update do self.class.adapter.update(self) end end |
#update_attributes(attributes) ⇒ Object
58 59 60 61 |
# File 'lib/ninja_model/persistence.rb', line 58 def update_attributes(attributes) self.attributes = attributes save end |