Class: Chef::Reporting::ResourceReporter::ResourceReport

Inherits:
Struct
  • Object
show all
Defined in:
lib/chef_reporting/resource_reporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



28
29
30
# File 'lib/chef_reporting/resource_reporter.rb', line 28

def action
  @action
end

#current_resourceObject

Returns the value of attribute current_resource

Returns:

  • (Object)

    the current value of current_resource



28
29
30
# File 'lib/chef_reporting/resource_reporter.rb', line 28

def current_resource
  @current_resource
end

#elapsed_timeObject

Returns the value of attribute elapsed_time

Returns:

  • (Object)

    the current value of elapsed_time



28
29
30
# File 'lib/chef_reporting/resource_reporter.rb', line 28

def elapsed_time
  @elapsed_time
end

#exceptionObject

Returns the value of attribute exception

Returns:

  • (Object)

    the current value of exception



28
29
30
# File 'lib/chef_reporting/resource_reporter.rb', line 28

def exception
  @exception
end

#new_resourceObject

Returns the value of attribute new_resource

Returns:

  • (Object)

    the current value of new_resource



28
29
30
# File 'lib/chef_reporting/resource_reporter.rb', line 28

def new_resource
  @new_resource
end

Class Method Details

.new_for_exception(new_resource, action) ⇒ Object



42
43
44
45
46
47
# File 'lib/chef_reporting/resource_reporter.rb', line 42

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) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/chef_reporting/resource_reporter.rb', line 34

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

Instance Method Details

#finishObject



71
72
73
# File 'lib/chef_reporting/resource_reporter.rb', line 71

def finish
  self.elapsed_time = new_resource.elapsed_time
end

#for_jsonObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef_reporting/resource_reporter.rb', line 49

def for_json
  as_hash = {}
  as_hash["type"]   = new_resource.class.dsl_name
  as_hash["name"]   = new_resource.name
  as_hash["id"]     = new_resource.identity
  as_hash["after"]  = new_resource.state
  as_hash["before"] = current_resource ? current_resource.state : {}
  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
  as_hash["cookbook_name"] = new_resource.cookbook_name
  as_hash["cookbook_version"] = new_resource.cookbook_version ? new_resource.cookbook_version.version : "0.0.0"
  as_hash
end

#success?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/chef_reporting/resource_reporter.rb', line 75

def success?
  !self.exception
end