Class: ForemanTasks::ContinuousOutput
- Inherits:
-
Object
- Object
- ForemanTasks::ContinuousOutput
- Defined in:
- lib/foreman_tasks/continuous_output.rb
Instance Attribute Summary collapse
-
#raw_outputs ⇒ Object
Returns the value of attribute raw_outputs.
Class Method Summary collapse
Instance Method Summary collapse
- #add_exception(context, exception, timestamp = Time.now.getlocal) ⇒ Object
- #add_output(*args) ⇒ Object
- #add_raw_output(raw_output) ⇒ Object
- #empty? ⇒ Boolean
- #humanize ⇒ Object
-
#initialize(raw_outputs = []) ⇒ ContinuousOutput
constructor
A new instance of ContinuousOutput.
- #last_timestamp ⇒ Object
- #sort! ⇒ Object
Constructor Details
#initialize(raw_outputs = []) ⇒ ContinuousOutput
Returns a new instance of ContinuousOutput.
5 6 7 8 |
# File 'lib/foreman_tasks/continuous_output.rb', line 5 def initialize(raw_outputs = []) @raw_outputs = [] raw_outputs.each { |raw_output| add_raw_output(raw_output) } end |
Instance Attribute Details
#raw_outputs ⇒ Object
Returns the value of attribute raw_outputs.
3 4 5 |
# File 'lib/foreman_tasks/continuous_output.rb', line 3 def raw_outputs @raw_outputs end |
Class Method Details
.format_output(message, type = 'debug', timestamp = Time.now.getlocal) ⇒ Object
44 45 46 47 48 |
# File 'lib/foreman_tasks/continuous_output.rb', line 44 def self.format_output(, type = 'debug', = Time.now.getlocal) { 'output_type' => type, 'output' => , 'timestamp' => .to_f } end |
Instance Method Details
#add_exception(context, exception, timestamp = Time.now.getlocal) ⇒ Object
36 37 38 |
# File 'lib/foreman_tasks/continuous_output.rb', line 36 def add_exception(context, exception, = Time.now.getlocal) add_output(context + ": #{exception.class} - #{exception.}", 'debug', ) end |
#add_output(*args) ⇒ Object
40 41 42 |
# File 'lib/foreman_tasks/continuous_output.rb', line 40 def add_output(*args) add_raw_output(self.class.format_output(*args)) end |
#add_raw_output(raw_output) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/foreman_tasks/continuous_output.rb', line 10 def add_raw_output(raw_output) missing_args = %w[output_type output timestamp] - raw_output.keys unless missing_args.empty? raise ArgumentError, "Missing args for raw output: #{missing_args.inspect}" end @raw_outputs << raw_output end |
#empty? ⇒ Boolean
18 19 20 |
# File 'lib/foreman_tasks/continuous_output.rb', line 18 def empty? @raw_outputs.empty? end |
#humanize ⇒ Object
31 32 33 34 |
# File 'lib/foreman_tasks/continuous_output.rb', line 31 def humanize sort! raw_outputs.map { |output| output['output'] }.join("\n") end |
#last_timestamp ⇒ Object
22 23 24 25 |
# File 'lib/foreman_tasks/continuous_output.rb', line 22 def return if @raw_outputs.empty? @raw_outputs.last.fetch('timestamp') end |
#sort! ⇒ Object
27 28 29 |
# File 'lib/foreman_tasks/continuous_output.rb', line 27 def sort! @raw_outputs.sort_by! { |record| record['timestamp'].to_f } end |