Class: Proxy::Dynflow::ContinuousOutput
- Inherits:
-
Object
- Object
- Proxy::Dynflow::ContinuousOutput
- Defined in:
- lib/smart_proxy_dynflow/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.
7 8 9 10 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 7 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.
5 6 7 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 5 def raw_outputs @raw_outputs end |
Class Method Details
.format_output(message, type = 'debug', timestamp = Time.now.getlocal) ⇒ Object
48 49 50 51 52 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 48 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
40 41 42 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 40 def add_exception(context, exception, = Time.now.getlocal) add_output(context + ": #{exception.class} - #{exception.}", 'debug', ) end |
#add_output(*args) ⇒ Object
44 45 46 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 44 def add_output(*args) add_raw_output(self.class.format_output(*args)) end |
#add_raw_output(raw_output) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 12 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
21 22 23 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 21 def empty? @raw_outputs.empty? end |
#humanize ⇒ Object
35 36 37 38 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 35 def humanize sort! raw_outputs.map { |output| output['output'] }.join("\n") end |
#last_timestamp ⇒ Object
25 26 27 28 29 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 25 def return if @raw_outputs.empty? @raw_outputs.last.fetch('timestamp') end |
#sort! ⇒ Object
31 32 33 |
# File 'lib/smart_proxy_dynflow/continuous_output.rb', line 31 def sort! @raw_outputs.sort_by! { |record| record['timestamp'].to_f } end |