Class: Fuey::Trace
- Inherits:
-
Object
- Object
- Fuey::Trace
- Includes:
- ModelInitializer, Observable
- Defined in:
- lib/fuey_client/fuey/trace.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_step(inspection) ⇒ Object
-
#initialize(args) ⇒ Trace
constructor
A new instance of Trace.
- #receiver=(observer) ⇒ Object
- #run ⇒ Object
- #status ⇒ Object
- #status_message ⇒ Object
- #steps ⇒ Object
- #to_s ⇒ Object
-
#update(status) ⇒ Object
Handle updates from inpsections via observation.
Constructor Details
#initialize(args) ⇒ Trace
Returns a new instance of Trace.
13 14 15 |
# File 'lib/fuey_client/fuey/trace.rb', line 13 def initialize(args) super(args) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/fuey_client/fuey/trace.rb', line 11 def name @name end |
Instance Method Details
#add_step(inspection) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/fuey_client/fuey/trace.rb', line 21 def add_step(inspection) inspection.add_observer(self) inspection.add_observer(error_logger) steps.push inspection inspection end |
#receiver=(observer) ⇒ Object
17 18 19 |
# File 'lib/fuey_client/fuey/trace.rb', line 17 def receiver=(observer) add_observer observer end |
#run ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fuey_client/fuey/trace.rb', line 56 def run changed notify_observers :new, name, steps.map(&:status) ActiveSupport::Notifications.instrument("run.trace", {:trace => self.to_s}) do run, failed, @_current = 0, 0, nil steps.each do |step| run += 1 @_current = step step.execute if step.failed? failed += 1 break end end changed notify_observers :complete, self if failed == 0 %(#{name} passed. #{steps.size} steps, #{run} executed, #{failed} failed.) else %(#{name} failed on #{@_current.name}. #{steps.size} steps, #{run} executed, #{failed} failed.) end end end |
#status ⇒ Object
48 49 50 |
# File 'lib/fuey_client/fuey/trace.rb', line 48 def status @_current ? @_current.state : "pending" end |
#status_message ⇒ Object
52 53 54 |
# File 'lib/fuey_client/fuey/trace.rb', line 52 def @_current.failed? ? @_current. : "" end |
#steps ⇒ Object
28 29 30 |
# File 'lib/fuey_client/fuey/trace.rb', line 28 def steps @_steps ||= Array.new end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/fuey_client/fuey/trace.rb', line 37 def to_s %(#{name}: [#{steps.join(', ')}]) end |
#update(status) ⇒ Object
Handle updates from inpsections via observation
42 43 44 45 46 |
# File 'lib/fuey_client/fuey/trace.rb', line 42 def update(status) changed notify_observers :update, name, [status] true end |