Class: Bolt::ResultSet
- Inherits:
-
Object
- Object
- Bolt::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/bolt/result_set.rb
Instance Attribute Summary collapse
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
- ._pcore_init_from_hash ⇒ Object
-
.include_iterable ⇒ Object
We only want want to include these when puppet is loaded.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](from, up_to = nil) ⇒ Object
- #_pcore_init_from_hash(init_hash) ⇒ Object
- #_pcore_init_hash ⇒ Object
- #count ⇒ Object (also: #length, #size)
- #each ⇒ Object
- #empty ⇒ Object (also: #empty?)
- #eql?(other) ⇒ Boolean
- #error_set ⇒ Object
- #filter_set ⇒ Object
- #find(target_name) ⇒ Object
- #first ⇒ Object
-
#initialize(results) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #iterator ⇒ Object
- #names ⇒ Object
- #ok ⇒ Object (also: #ok?)
- #ok_set ⇒ Object
- #result_hash ⇒ Object
- #targets ⇒ Object
- #to_data ⇒ Object (also: #to_a)
- #to_json(opts = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(results) ⇒ ResultSet
Returns a new instance of ResultSet.
37 38 39 |
# File 'lib/bolt/result_set.rb', line 37 def initialize(results) @results = results end |
Instance Attribute Details
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
5 6 7 |
# File 'lib/bolt/result_set.rb', line 5 def elapsed_time @elapsed_time end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
6 7 8 |
# File 'lib/bolt/result_set.rb', line 6 def results @results end |
Class Method Details
._pcore_init_from_hash ⇒ Object
16 17 18 |
# File 'lib/bolt/result_set.rb', line 16 def self._pcore_init_from_hash raise "ResultSet shouldn't be instantiated from a pcore_init class method. How did this get called?" end |
.include_iterable ⇒ Object
We only want want to include these when puppet is loaded
11 12 13 14 |
# File 'lib/bolt/result_set.rb', line 11 def self.include_iterable include(Puppet::Pops::Types::Iterable) include(Puppet::Pops::Types::IteratorProducer) end |
Instance Method Details
#==(other) ⇒ Object
116 117 118 |
# File 'lib/bolt/result_set.rb', line 116 def ==(other) eql?(other) end |
#[](from, up_to = nil) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/bolt/result_set.rb', line 120 def [](from, up_to = nil) if up_to @results[from..up_to] else @results[from] end end |
#_pcore_init_from_hash(init_hash) ⇒ Object
20 21 22 |
# File 'lib/bolt/result_set.rb', line 20 def _pcore_init_from_hash(init_hash) initialize(init_hash['results']) end |
#_pcore_init_hash ⇒ Object
24 25 26 |
# File 'lib/bolt/result_set.rb', line 24 def _pcore_init_hash { 'results' => @results } end |
#count ⇒ Object Also known as: length, size
57 58 59 |
# File 'lib/bolt/result_set.rb', line 57 def count @results.size end |
#each ⇒ Object
41 42 43 44 |
# File 'lib/bolt/result_set.rb', line 41 def each @results.each { |r| yield r } self end |
#empty ⇒ Object Also known as: empty?
63 64 65 |
# File 'lib/bolt/result_set.rb', line 63 def empty @results.empty? end |
#eql?(other) ⇒ Boolean
99 100 101 |
# File 'lib/bolt/result_set.rb', line 99 def eql?(other) self.class == other.class && @results == other.results end |
#error_set ⇒ Object
81 82 83 84 |
# File 'lib/bolt/result_set.rb', line 81 def error_set filtered = @results.reject(&:ok?) ResultSet.new(filtered) end |
#filter_set ⇒ Object
46 47 48 49 |
# File 'lib/bolt/result_set.rb', line 46 def filter_set filtered = @results.select { |r| yield r } self.class.new(filtered) end |
#find(target_name) ⇒ Object
91 92 93 |
# File 'lib/bolt/result_set.rb', line 91 def find(target_name) result_hash[target_name] end |
#first ⇒ Object
95 96 97 |
# File 'lib/bolt/result_set.rb', line 95 def first @results.first end |
#iterator ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/bolt/result_set.rb', line 28 def iterator if Object.const_defined?(:Puppet) && Puppet.const_defined?(:Pops) && self.class.included_modules.include?(Puppet::Pops::Types::Iterable) Puppet::Pops::Types::Iterable.on(@results, Bolt::Result) else raise NotImplementedError, "iterator requires puppet code to be loaded." end end |
#names ⇒ Object
72 73 74 |
# File 'lib/bolt/result_set.rb', line 72 def names @results.map { |r| r.target.name } end |
#ok ⇒ Object Also known as: ok?
76 77 78 |
# File 'lib/bolt/result_set.rb', line 76 def ok @results.all?(&:ok?) end |
#ok_set ⇒ Object
86 87 88 89 |
# File 'lib/bolt/result_set.rb', line 86 def ok_set filtered = @results.select(&:success?) self.class.new(filtered) end |
#result_hash ⇒ Object
51 52 53 54 55 |
# File 'lib/bolt/result_set.rb', line 51 def result_hash @result_hash ||= @results.each_with_object({}) do |result, acc| acc[result.target.name] = result end end |
#targets ⇒ Object
68 69 70 |
# File 'lib/bolt/result_set.rb', line 68 def targets results.map(&:target) end |
#to_data ⇒ Object Also known as: to_a
107 108 109 |
# File 'lib/bolt/result_set.rb', line 107 def to_data @results.map(&:to_data) end |
#to_json(opts = nil) ⇒ Object
103 104 105 |
# File 'lib/bolt/result_set.rb', line 103 def to_json(opts = nil) to_data.to_json(opts) end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/bolt/result_set.rb', line 112 def to_s to_json end |