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.



37
38
39
# File 'lib/bolt/result_set.rb', line 37

def initialize(results)
  @results = results
end

Instance Attribute Details

#elapsed_timeObject

Returns the value of attribute elapsed_time.



5
6
7
# File 'lib/bolt/result_set.rb', line 5

def elapsed_time
  @elapsed_time
end

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



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_iterableObject

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_hashObject



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

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

#countObject Also known as: length, size



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

def count
  @results.size
end

#eachObject



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

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

#emptyObject Also known as: empty?



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

def empty
  @results.empty?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#error_setObject



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

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

#filter_setObject



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

#firstObject



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

def first
  @results.first
end

#iteratorObject



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

#namesObject



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

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

#okObject Also known as: ok?



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

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

#ok_setObject



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_hashObject



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

#targetsObject



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

def targets
  results.map(&:target)
end

#to_dataObject 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_sObject



112
113
114
# File 'lib/bolt/result_set.rb', line 112

def to_s
  to_json
end