Module: Hibachi::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Model
Defined in:
lib/hibachi/persistence.rb

Overview

Backend data store methods for the Hibachi::Model

Instance Method Summary collapse

Instance Method Details

#destroyObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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

#saveObject

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