Class: Chef::DataCollector::ResourceReport
- Inherits:
-
Object
- Object
- Chef::DataCollector::ResourceReport
- Defined in:
- lib/chef/data_collector/resource_report.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#conditional ⇒ Object
Returns the value of attribute conditional.
-
#current_resource ⇒ Object
Returns the value of attribute current_resource.
-
#elapsed_time ⇒ Object
readonly
Returns the value of attribute elapsed_time.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#new_resource ⇒ Object
readonly
Returns the value of attribute new_resource.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #elapsed_time_in_milliseconds ⇒ Object
- #failed(exception) ⇒ Object
- #finish ⇒ Object
-
#initialize(new_resource, action, current_resource = nil) ⇒ ResourceReport
constructor
A new instance of ResourceReport.
- #potentially_changed? ⇒ Boolean
- #skipped(conditional) ⇒ Object
- #to_hash ⇒ Object (also: #to_h, #for_json)
- #up_to_date ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(new_resource, action, current_resource = nil) ⇒ ResourceReport
Returns a new instance of ResourceReport.
28 29 30 31 32 33 |
# File 'lib/chef/data_collector/resource_report.rb', line 28 def initialize(new_resource, action, current_resource = nil) @new_resource = new_resource @action = action @current_resource = current_resource @status = "unprocessed" end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
25 26 27 |
# File 'lib/chef/data_collector/resource_report.rb', line 25 def action @action end |
#conditional ⇒ Object
Returns the value of attribute conditional.
26 27 28 |
# File 'lib/chef/data_collector/resource_report.rb', line 26 def conditional @conditional end |
#current_resource ⇒ Object
Returns the value of attribute current_resource.
26 27 28 |
# File 'lib/chef/data_collector/resource_report.rb', line 26 def current_resource @current_resource end |
#elapsed_time ⇒ Object (readonly)
Returns the value of attribute elapsed_time.
25 26 27 |
# File 'lib/chef/data_collector/resource_report.rb', line 25 def elapsed_time @elapsed_time end |
#exception ⇒ Object
Returns the value of attribute exception.
26 27 28 |
# File 'lib/chef/data_collector/resource_report.rb', line 26 def exception @exception end |
#new_resource ⇒ Object (readonly)
Returns the value of attribute new_resource.
25 26 27 |
# File 'lib/chef/data_collector/resource_report.rb', line 25 def new_resource @new_resource end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
25 26 27 |
# File 'lib/chef/data_collector/resource_report.rb', line 25 def status @status end |
Instance Method Details
#elapsed_time_in_milliseconds ⇒ Object
58 59 60 |
# File 'lib/chef/data_collector/resource_report.rb', line 58 def elapsed_time_in_milliseconds elapsed_time.nil? ? nil : (elapsed_time * 1000).to_i end |
#failed(exception) ⇒ Object
44 45 46 47 48 |
# File 'lib/chef/data_collector/resource_report.rb', line 44 def failed(exception) @current_resource = nil @status = "failed" @exception = exception end |
#finish ⇒ Object
54 55 56 |
# File 'lib/chef/data_collector/resource_report.rb', line 54 def finish @elapsed_time = new_resource.elapsed_time end |
#potentially_changed? ⇒ Boolean
62 63 64 |
# File 'lib/chef/data_collector/resource_report.rb', line 62 def potentially_changed? %w{updated failed}.include?(status) end |
#skipped(conditional) ⇒ Object
35 36 37 38 |
# File 'lib/chef/data_collector/resource_report.rb', line 35 def skipped(conditional) @status = "skipped" @conditional = conditional end |
#to_hash ⇒ Object Also known as: to_h, for_json
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/chef/data_collector/resource_report.rb', line 66 def to_hash hash = { "type" => new_resource.resource_name.to_sym, "name" => new_resource.name.to_s, "id" => new_resource.identity.to_s, "after" => new_resource.state_for_resource_reporter, "before" => current_resource ? current_resource.state_for_resource_reporter : {}, "duration" => elapsed_time_in_milliseconds.to_s, "delta" => new_resource.respond_to?(:diff) && potentially_changed? ? new_resource.diff : "", "ignore_failure" => new_resource.ignore_failure, "result" => action.to_s, "status" => status, } if new_resource.cookbook_name hash["cookbook_name"] = new_resource.cookbook_name hash["cookbook_version"] = new_resource.cookbook_version.version hash["recipe_name"] = new_resource.recipe_name end hash["conditional"] = conditional.to_text if status == "skipped" hash["error_message"] = exception. unless exception.nil? hash end |
#up_to_date ⇒ Object
50 51 52 |
# File 'lib/chef/data_collector/resource_report.rb', line 50 def up_to_date @status = "up-to-date" end |
#updated ⇒ Object
40 41 42 |
# File 'lib/chef/data_collector/resource_report.rb', line 40 def updated @status = "updated" end |