Class: Bolt::ResultSet
- Inherits:
-
Object
- Object
- Bolt::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/bolt/result_set.rb
Instance Attribute Summary collapse
-
#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_a ⇒ Object
- #to_data ⇒ Object
- #to_json(opts = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(results) ⇒ ResultSet
Returns a new instance of ResultSet.
36 37 38 |
# File 'lib/bolt/result_set.rb', line 36 def initialize(results) @results = results end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
5 6 7 |
# File 'lib/bolt/result_set.rb', line 5 def results @results end |
Class Method Details
._pcore_init_from_hash ⇒ Object
15 16 17 |
# File 'lib/bolt/result_set.rb', line 15 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
10 11 12 13 |
# File 'lib/bolt/result_set.rb', line 10 def self.include_iterable include(Puppet::Pops::Types::Iterable) include(Puppet::Pops::Types::IteratorProducer) end |
Instance Method Details
#==(other) ⇒ Object
118 119 120 |
# File 'lib/bolt/result_set.rb', line 118 def ==(other) eql?(other) end |
#[](from, up_to = nil) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/bolt/result_set.rb', line 122 def [](from, up_to = nil) if up_to @results[from..up_to] else @results[from] end end |
#_pcore_init_from_hash(init_hash) ⇒ Object
19 20 21 |
# File 'lib/bolt/result_set.rb', line 19 def _pcore_init_from_hash(init_hash) initialize(init_hash['results']) end |
#_pcore_init_hash ⇒ Object
23 24 25 |
# File 'lib/bolt/result_set.rb', line 23 def _pcore_init_hash { 'results' => @results } end |
#count ⇒ Object Also known as: length, size
56 57 58 |
# File 'lib/bolt/result_set.rb', line 56 def count @results.size end |
#each ⇒ Object
40 41 42 43 |
# File 'lib/bolt/result_set.rb', line 40 def each @results.each { |r| yield r } self end |
#empty ⇒ Object Also known as: empty?
62 63 64 |
# File 'lib/bolt/result_set.rb', line 62 def empty @results.empty? end |
#eql?(other) ⇒ Boolean
98 99 100 |
# File 'lib/bolt/result_set.rb', line 98 def eql?(other) self.class == other.class && @results == other.results end |
#error_set ⇒ Object
80 81 82 83 |
# File 'lib/bolt/result_set.rb', line 80 def error_set filtered = @results.reject(&:ok?) ResultSet.new(filtered) end |
#filter_set ⇒ Object
45 46 47 48 |
# File 'lib/bolt/result_set.rb', line 45 def filter_set filtered = @results.select { |r| yield r } self.class.new(filtered) end |
#find(target_name) ⇒ Object
90 91 92 |
# File 'lib/bolt/result_set.rb', line 90 def find(target_name) result_hash[target_name] end |
#first ⇒ Object
94 95 96 |
# File 'lib/bolt/result_set.rb', line 94 def first @results.first end |
#iterator ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/bolt/result_set.rb', line 27 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
71 72 73 |
# File 'lib/bolt/result_set.rb', line 71 def names @results.map { |r| r.target.name } end |
#ok ⇒ Object Also known as: ok?
75 76 77 |
# File 'lib/bolt/result_set.rb', line 75 def ok @results.all?(&:ok?) end |
#ok_set ⇒ Object
85 86 87 88 |
# File 'lib/bolt/result_set.rb', line 85 def ok_set filtered = @results.select(&:success?) self.class.new(filtered) end |
#result_hash ⇒ Object
50 51 52 53 54 |
# File 'lib/bolt/result_set.rb', line 50 def result_hash @result_hash ||= @results.each_with_object({}) do |result, acc| acc[result.target.name] = result end end |
#targets ⇒ Object
67 68 69 |
# File 'lib/bolt/result_set.rb', line 67 def targets results.map(&:target) end |
#to_a ⇒ Object
102 103 104 |
# File 'lib/bolt/result_set.rb', line 102 def to_a @results.map(&:status_hash) end |
#to_data ⇒ Object
110 111 112 |
# File 'lib/bolt/result_set.rb', line 110 def to_data @results.map(&:to_data) end |
#to_json(opts = nil) ⇒ Object
106 107 108 |
# File 'lib/bolt/result_set.rb', line 106 def to_json(opts = nil) @results.map(&:status_hash).to_json(opts) end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/bolt/result_set.rb', line 114 def to_s to_json end |