Module: Hibachi::Persistence
Overview
Backend data store methods for the Hibachi::Model
Instance Method Summary collapse
-
#destroy ⇒ Object
Remove the given id from the JSON and re-run Chef.
-
#new_record? ⇒ Boolean
Returns ‘true` if it’s not currently being persisted.
-
#persisted? ⇒ Boolean
Test if this model appears in the Node JSON.
-
#save ⇒ Object
Merge attrs and write to JSON.
-
#update_attributes(attrs = {}) ⇒ Object
Update an existing model’s attributes.
Instance Method Details
#destroy ⇒ Object
Remove the given id from the JSON and re-run Chef.
17 18 19 |
# File 'lib/hibachi/persistence.rb', line 17 def destroy clear and chef end |
#new_record? ⇒ Boolean
Returns ‘true` if it’s not currently being persisted.
31 32 33 |
# File 'lib/hibachi/persistence.rb', line 31 def new_record? (not persisted?) end |
#persisted? ⇒ Boolean
Test if this model appears in the Node JSON.
22 23 24 25 26 27 28 |
# File 'lib/hibachi/persistence.rb', line 22 def persisted? if collection? node[recipe][id].present? else node[recipe].present? end end |
#save ⇒ Object
Merge attrs and write to JSON.
7 8 9 |
# File 'lib/hibachi/persistence.rb', line 7 def save persist and chef end |
#update_attributes(attrs = {}) ⇒ Object
Update an existing model’s attributes.
12 13 14 |
# File 'lib/hibachi/persistence.rb', line 12 def update_attributes(attrs={}) merge(attrs) and save end |