# class Chef::ResourceReporter::ResourceReport

### Public Class Methods

new_for_exception(new_resource, action) click to toggle source

    # File lib/chef/resource_reporter.rb, line 43
    def self.new_for_exception(new_resource, action)
      report = new
      report.new_resource = new_resource
      report.action = action
      report
    end

new_with_current_state(new_resource, action, current_resource) click to toggle source

    # File lib/chef/resource_reporter.rb, line 35
    def self.new_with_current_state(new_resource, action, current_resource)
      report = new
      report.new_resource = new_resource
      report.action = action
      report.current_resource = current_resource
      report
    end

### Public Instance Methods

finish() click to toggle source

    # File lib/chef/resource_reporter.rb, line 75
    def finish
      self.elapsed_time = new_resource.elapsed_time
    end

for_json() click to toggle source

    # File lib/chef/resource_reporter.rb, line 50
    def for_json
      as_hash = {}
      as_hash["type"]   = new_resource.class.dsl_name
      as_hash["name"]   = new_resource.name.to_s
      as_hash["id"]     = new_resource.identity.to_s
      as_hash["after"]  = state(new_resource)
      as_hash["before"] = current_resource ? state(current_resource) : {}
      as_hash["duration"] = (elapsed_time * 1000).to_i.to_s
      as_hash["delta"]  = new_resource.diff if new_resource.respond_to?("diff")
      as_hash["delta"]  = "" if as_hash["delta"].nil?

      # TODO: rename as "action"
      as_hash["result"] = action.to_s
      if success?
      else
        #as_hash["result"] = "failed"
      end
      if new_resource.cookbook_name
        as_hash["cookbook_name"] = new_resource.cookbook_name
        as_hash["cookbook_version"] = new_resource.cookbook_version.version
      end

      as_hash
    end

state(r) click to toggle source

    # File lib/chef/resource_reporter.rb, line 83
    def state(r)
      r.class.state_attrs.inject({}) do |state_attrs, attr_name|
        state_attrs[attr_name] = r.send(attr_name)
        state_attrs
      end
    end

success?() click to toggle source

    # File lib/chef/resource_reporter.rb, line 79
    def success?
      !self.exception
    end