Class: Bolt::ResultSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bolt/result_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#resultsObject (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_hashObject



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_iterableObject

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_hashObject



23
24
25
# File 'lib/bolt/result_set.rb', line 23

def _pcore_init_hash
  { 'results' => @results }
end

#countObject Also known as: length, size



56
57
58
# File 'lib/bolt/result_set.rb', line 56

def count
  @results.size
end

#eachObject



40
41
42
43
# File 'lib/bolt/result_set.rb', line 40

def each
  @results.each { |r| yield r }
  self
end

#emptyObject Also known as: empty?



62
63
64
# File 'lib/bolt/result_set.rb', line 62

def empty
  @results.empty?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/bolt/result_set.rb', line 98

def eql?(other)
  self.class == other.class && @results == other.results
end

#error_setObject



80
81
82
83
# File 'lib/bolt/result_set.rb', line 80

def error_set
  filtered = @results.reject(&:ok?)
  ResultSet.new(filtered)
end

#filter_setObject



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

#firstObject



94
95
96
# File 'lib/bolt/result_set.rb', line 94

def first
  @results.first
end

#iteratorObject



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

#namesObject



71
72
73
# File 'lib/bolt/result_set.rb', line 71

def names
  @results.map { |r| r.target.name }
end

#okObject Also known as: ok?



75
76
77
# File 'lib/bolt/result_set.rb', line 75

def ok
  @results.all?(&:ok?)
end

#ok_setObject



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_hashObject



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

#targetsObject



67
68
69
# File 'lib/bolt/result_set.rb', line 67

def targets
  results.map(&:target)
end

#to_aObject



102
103
104
# File 'lib/bolt/result_set.rb', line 102

def to_a
  @results.map(&:status_hash)
end

#to_dataObject



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_sObject



114
115
116
# File 'lib/bolt/result_set.rb', line 114

def to_s
  to_json
end