Class: Event

Inherits:
Object
  • Object
show all
Defined in:
lib/event.rb

Overview

An Event instance tracks the title of the task, and the required indentation to display the task in the log. This is required to store an Array of events that took place–but below the verbosity threshhold–to replay them into the log at the appropriate indention level should an exception be thrown.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#failureObject (readonly)

Publically read-only attributes



28
29
30
# File 'lib/event.rb', line 28

def failure
  @failure
end

#hierObject (readonly)

shows nested levels



29
30
31
# File 'lib/event.rb', line 29

def hier
  @hier
end

#procObject (readonly)

Proc to call before a retry



30
31
32
# File 'lib/event.rb', line 30

def proc
  @proc
end

#titleObject (readonly)

event title



32
33
34
# File 'lib/event.rb', line 32

def title
  @title
end

#triesObject (readonly)

number of tries remaining



31
32
33
# File 'lib/event.rb', line 31

def tries
  @tries
end

Instance Method Details

#childObject

Get an Event which is the child of this event



35
36
37
# File 'lib/event.rb', line 35

def child
  self.dup.child!
end

#child!Object

Make this event into its child



40
41
42
43
44
45
46
47
# File 'lib/event.rb', line 40

def child!
  if @hier.count('.') % 2 == 0 # if even number of periods
    @hier << '.a'
  else
    @hier << '.0'
  end
  self
end

#siblingObject

Get copy of Event hier to the next task at the same level of the call-stack



50
51
52
# File 'lib/event.rb', line 50

def sibling
  self.dup.sibling!
end

#sibling!Object

Take this Event hier to the next task at the same level of the call-stack



55
56
57
58
59
# File 'lib/event.rb', line 55

def sibling!
  # Now change the last hier to its successor
  @hier.sub!(/[^.]+$/) { $&.succ }
  self
end

#to_sObject

Return String ready for log



62
63
64
# File 'lib/event.rb', line 62

def to_s
  @time + ': ' + @hier + ' ### ' + @title
end