Module: CurlyMustache::Crud::InstanceMethods
- Defined in:
- lib/curly_mustache/crud.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
Delete a record from the data store, invoking the *_destroy callbacks.
-
#initialize(attributes = {}) ⇒ Object
Make a new record in memory with supplied attributes.
-
#new_record? ⇒ Boolean
Returns true if the record has been saved yet.
-
#reload ⇒ Object
Reload the record from the data store, overwriting any attribute changes.
-
#save ⇒ Object
Save the record to the data store.
-
#save! ⇒ Object
Save the record to the data store.
Instance Method Details
#destroy ⇒ Object
Delete a record from the data store, invoking the *_destroy callbacks.
133 134 135 |
# File 'lib/curly_mustache/crud.rb', line 133 def destroy delete end |
#initialize(attributes = {}) ⇒ Object
Make a new record in memory with supplied attributes.
103 104 105 106 107 |
# File 'lib/curly_mustache/crud.rb', line 103 def initialize(attributes = {}) @attributes = {} @new_record = true self.attributes = attributes end |
#new_record? ⇒ Boolean
Returns true if the record has been saved yet.
110 111 112 |
# File 'lib/curly_mustache/crud.rb', line 110 def new_record? !!@new_record end |
#reload ⇒ Object
Reload the record from the data store, overwriting any attribute changes.
115 116 117 |
# File 'lib/curly_mustache/crud.rb', line 115 def reload returning(self){ read } end |
#save ⇒ Object
Save the record to the data store. Returns false if validation fails.
120 121 122 123 |
# File 'lib/curly_mustache/crud.rb', line 120 def save new_record? ? create : update (errors.count > 0) ? false : self end |
#save! ⇒ Object
Save the record to the data store. Raises RecordInvalid if validation fails.
126 127 128 129 130 |
# File 'lib/curly_mustache/crud.rb', line 126 def save! returning(save) do errors.count > 0 and raise(RecordInvalid, "Validation failed: #{errors..join(', ')}") end end |