Class: MCollective::Util::BoltSupport::TaskResults
- Inherits:
-
Object
- Object
- MCollective::Util::BoltSupport::TaskResults
- Includes:
- Enumerable
- Defined in:
- lib/mcollective/util/bolt_support/task_results.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
- #message ⇒ Object
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
-
.from_asserted_hash(results, exception = nil) ⇒ TaskResults
Method used by Puppet to create the TaskResults from a array.
- .include_iterable ⇒ Object
Instance Method Summary collapse
-
#count ⇒ Integer
Determines the count of results in the set.
-
#each {|TaskResult| ... } ⇒ Object
Iterate over all results.
-
#empty ⇒ Boolean
(also: #empty?)
Determines if the resultset is empty.
-
#error_set ⇒ TaskResults
Set of all the results that are errors regardless of fail_ok.
- #fail_ok ⇒ Object (also: #fail_ok?)
-
#find(host) ⇒ TaskResult?
Finds a result by name.
-
#first ⇒ TaskResult
First result in the set.
-
#hosts ⇒ Array<String>
List of node names for all results.
-
#initialize(results, exception = nil) ⇒ TaskResults
constructor
A new instance of TaskResults.
- #iterator ⇒ Object
-
#ok ⇒ Boolean
(also: #ok?)
Determines if all results are ok, considers fail_ok.
-
#ok_set ⇒ TaskResults
Set of all the results that are ok regardless of fail_ok.
- #to_json(obj = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(results, exception = nil) ⇒ TaskResults
Returns a new instance of TaskResults.
24 25 26 27 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 24 def initialize(results, exception=nil) @results = results @exception = exception end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
5 6 7 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 5 def exception @exception end |
#message ⇒ Object
67 68 69 70 71 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 67 def return exception.to_s if exception @message end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
5 6 7 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 5 def results @results end |
Class Method Details
.from_asserted_hash(results, exception = nil) ⇒ TaskResults
Method used by Puppet to create the TaskResults from a array
19 20 21 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 19 def self.from_asserted_hash(results, exception=nil) new(results, exception) end |
.include_iterable ⇒ Object
10 11 12 13 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 10 def self.include_iterable include(Puppet::Pops::Types::Iterable) include(Puppet::Pops::Types::IteratorProducer) end |
Instance Method Details
#count ⇒ Integer
Determines the count of results in the set
106 107 108 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 106 def count @results.size end |
#each {|TaskResult| ... } ⇒ Object
Iterate over all results
36 37 38 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 36 def each(&block) @results.each(&block) end |
#empty ⇒ Boolean Also known as: empty?
Determines if the resultset is empty
98 99 100 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 98 def empty @results.empty? end |
#error_set ⇒ TaskResults
Set of all the results that are errors regardless of fail_ok
43 44 45 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 43 def error_set TaskResults.new(@results.select(&:error)) end |
#fail_ok ⇒ Object Also known as: fail_ok?
62 63 64 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 62 def fail_ok @results.all?(&:fail_ok) end |
#find(host) ⇒ TaskResult?
Finds a result by name
91 92 93 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 91 def find(host) @results.find {|r| r.host == host} end |
#first ⇒ TaskResult
First result in the set
83 84 85 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 83 def first @results.first end |
#hosts ⇒ Array<String>
List of node names for all results
76 77 78 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 76 def hosts @results.map(&:host) end |
#iterator ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 118 def iterator if Object.const_defined?(:Puppet) && Puppet.const_defined?(:Pops) && self.class.included_modules.include?(Puppet::Pops::Types::Iterable) return Puppet::Pops::Types::Iterable.on(@results, TaskResult) end raise(NotImplementedError, "iterator requires puppet code to be loaded.") end |
#ok ⇒ Boolean Also known as: ok?
Determines if all results are ok, considers fail_ok
57 58 59 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 57 def ok @results.all?(&:ok) end |
#ok_set ⇒ TaskResults
Set of all the results that are ok regardless of fail_ok
50 51 52 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 50 def ok_set TaskResults.new(@results.reject(&:error)) end |
#to_json(obj = {}) ⇒ Object
29 30 31 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 29 def to_json(obj={}) @results.to_json(obj) end |
#to_s ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/mcollective/util/bolt_support/task_results.rb', line 110 def to_s if Object.const_defined?(:Puppet) Puppet::Pops::Types::StringConverter.convert(self, "%p") else super end end |