Class: XP5K::Rake::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/xp5k/rake/timer.rb

Constant Summary collapse

@@initial_timer =
nil
@@current =
nil
@@ignore_summary =
false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Timer

Returns a new instance of Timer.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xp5k/rake/timer.rb', line 11

def initialize(name)
  @start_time = Time.now
  @stop_time = nil
  @parent = nil
  @childs ||= []
  @task_name = name
  @@initial_timer ||= self
  if @@current
    if @@current.stop_time
      @parent = @@current.parent
    else
      @parent = @@current
    end
  end
  @@current = self
end

Instance Attribute Details

#childsObject

Returns the value of attribute childs.



9
10
11
# File 'lib/xp5k/rake/timer.rb', line 9

def childs
  @childs
end

#parentObject

Returns the value of attribute parent.



9
10
11
# File 'lib/xp5k/rake/timer.rb', line 9

def parent
  @parent
end

#start_timeObject

Returns the value of attribute start_time.



9
10
11
# File 'lib/xp5k/rake/timer.rb', line 9

def start_time
  @start_time
end

#stop_timeObject

Returns the value of attribute stop_time.



9
10
11
# File 'lib/xp5k/rake/timer.rb', line 9

def stop_time
  @stop_time
end

#task_nameObject

Returns the value of attribute task_name.



9
10
11
# File 'lib/xp5k/rake/timer.rb', line 9

def task_name
  @task_name
end

Class Method Details

.ignore_summary(value) ⇒ Object



28
29
30
# File 'lib/xp5k/rake/timer.rb', line 28

def self.ignore_summary(value)
  @@ignore_summary = value
end

.summaryObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/xp5k/rake/timer.rb', line 38

def self.summary
  level = 1
  return if @@ignore_summary
  @@initial_timer.stop unless @@initial_timer.stop_time
  puts "|   " * (level - 1) + "|-- #{@@initial_timer.task_name} : #{self.duration(@@initial_timer)}"
  timer = @@initial_timer
  until (@@initial_timer.childs.count == 0 and level == 0) do
    if timer.childs.count > 0
      timer = timer.childs.shift
      level += 1
      puts "|   " * (level - 1) + "|-- #{timer.task_name} -> #{self.duration(timer)}"
    else
      level -= 1
      timer = timer.parent
    end
  end

end

Instance Method Details

#stopObject



32
33
34
35
36
# File 'lib/xp5k/rake/timer.rb', line 32

def stop()
  @stop_time = Time.now
  self.parent.childs << self if self.parent
  @@current = self.parent
end