Method: ChefAPI::Resource::Base#diff

Defined in:
lib/chef-api/resources/base.rb

#diffHash

Note:

This is a VERY expensive operation - use it sparringly!

Calculate a differential of the attributes on the local resource with it’s remote Chef Server counterpart.

Examples:

when the local resource is in sync with the remote resource

bacon = Bacon.first
bacon.diff #=> {}

when the local resource differs from the remote resource

bacon = Bacon.first
bacon.description = "My new description"
bacon.diff #=> { :description => { :local => "My new description", :remote => "Old description" } }

Returns:

  • (Hash)


864
865
866
867
868
869
870
871
872
873
874
875
# File 'lib/chef-api/resources/base.rb', line 864

def diff
  diff = {}

  remote = self.class.fetch(id, _prefix) || self.class.new({}, _prefix)
  remote._attributes.each do |key, value|
    unless _attributes[key] == value
      diff[key] = { local: _attributes[key], remote: value }
    end
  end

  diff
end