Module: Kangaroo::Model::Persistence
- Included in:
- Base
- Defined in:
- lib/kangaroo/model/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy this record.
-
#destroyed? ⇒ boolean
Check if this record has been destroyed.
-
#new_record? ⇒ boolean
Check if this record hasnt been persisted yet.
-
#persisted? ⇒ boolean
Check if this record has been persisted yet.
-
#reload(fields = self.class.attribute_names) ⇒ Object
Reload this record, or just a subset of fields.
-
#save(options = {}) ⇒ boolean
Save this record.
-
#save!(options = {}) ⇒ boolean
Save this record or raise an error.
Instance Method Details
#destroy ⇒ Object
Destroy this record
48 49 50 51 52 53 54 55 |
# File 'lib/kangaroo/model/persistence.rb', line 48 def destroy return true if destroyed? || new_record? _run_destroy_callbacks do remote.unlink [id], :context => context end self end |
#destroyed? ⇒ boolean
Check if this record has been destroyed
41 42 43 |
# File 'lib/kangaroo/model/persistence.rb', line 41 def destroyed? @destroyed end |
#new_record? ⇒ boolean
Check if this record hasnt been persisted yet
27 28 29 |
# File 'lib/kangaroo/model/persistence.rb', line 27 def new_record? @new_record end |
#persisted? ⇒ boolean
Check if this record has been persisted yet
34 35 36 |
# File 'lib/kangaroo/model/persistence.rb', line 34 def persisted? !@new_record end |
#reload(fields = self.class.attribute_names) ⇒ Object
Reload this record, or just a subset of fields
80 81 82 83 84 85 86 87 |
# File 'lib/kangaroo/model/persistence.rb', line 80 def reload fields = self.class.attribute_names @attributes = remote.read([id], fields, context).first.except(:id).stringify_keys fields.each do |field| @changed_attributes.delete field.to_s end self end |
#save(options = {}) ⇒ boolean
Save this record
61 62 63 64 65 |
# File 'lib/kangaroo/model/persistence.rb', line 61 def save = {} _run_save_callbacks do create_or_update end end |
#save!(options = {}) ⇒ boolean
Save this record or raise an error
71 72 73 74 |
# File 'lib/kangaroo/model/persistence.rb', line 71 def save! = {} save || raise(RecordSavingFailed) end |