Class: Bozo::Hooks::Timing
- Inherits:
-
Object
- Object
- Bozo::Hooks::Timing
show all
- Defined in:
- lib/bozo/hooks/timing.rb
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Timing
Returns a new instance of Timing.
5
6
7
|
# File 'lib/bozo/hooks/timing.rb', line 5
def initialize
@timings = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/bozo/hooks/timing.rb', line 26
def method_missing(method, *args)
if method.to_s =~ /^(pre|post)_(.+)/
record $2.to_sym, $1.to_sym
print_timings if $1 == 'post' and $2 == 'build'
else
super
end
end
|
Instance Method Details
16
17
18
19
|
# File 'lib/bozo/hooks/timing.rb', line 16
def format_timing(stage, args)
time_taken = (args[:post] - args[:pre]).round(1)
"#{stage.to_s.capitalize.ljust(14)} #{time_taken.to_s.rjust(5)}s"
end
|
#print_timings ⇒ Object
9
10
11
12
13
14
|
# File 'lib/bozo/hooks/timing.rb', line 9
def print_timings
puts ''
@timings.each do |stage, times|
puts format_timing(stage, times).bright.color(stage == :build ? :cyan : :black)
end
end
|
#record(stage, point) ⇒ Object
21
22
23
24
|
# File 'lib/bozo/hooks/timing.rb', line 21
def record(stage, point)
@timings[stage] ||= {}
@timings[stage][point] = Time.now
end
|
#respond_to?(method) ⇒ Boolean
35
36
37
|
# File 'lib/bozo/hooks/timing.rb', line 35
def respond_to?(method)
method.to_s =~ /^(pre|post)_(.+)/ or super
end
|