Class: Fuey::Trace

Inherits:
Object
  • Object
show all
Includes:
ModelInitializer, Observable
Defined in:
lib/fuey_client/fuey/trace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

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

#runObject



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

#statusObject



48
49
50
# File 'lib/fuey_client/fuey/trace.rb', line 48

def status
  @_current ? @_current.state : "pending"
end

#status_messageObject



52
53
54
# File 'lib/fuey_client/fuey/trace.rb', line 52

def status_message
  @_current.failed? ? @_current.status_message : ""
end

#stepsObject



28
29
30
# File 'lib/fuey_client/fuey/trace.rb', line 28

def steps
  @_steps ||= Array.new
end

#to_sObject



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