Sha256: c0fa141b153d054485c11b56b82883ec16f8433677783579c10b07a74b4f44a9

Contents?: true

Size: 924 Bytes

Versions: 41

Compression:

Stored size: 924 Bytes

Contents

module Bozo::Hooks
  
  class Timing
  
    def initialize
      @timings = {}
    end
    
    def print_timings
      puts ''
      @timings.each do |stage, times|
        puts format_timing(stage, times).bright.color(stage == :build ? :cyan : :black)
      end
    end
    
    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
    
    def record(stage, point)
      @timings[stage] ||= {}
      @timings[stage][point] = Time.now
    end
    
    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
    
    def respond_to?(method)
      method.to_s =~ /^(pre|post)_(.+)/ or super
    end
  
  end
  
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
bozo-scripts-0.18.5 lib/bozo/hooks/timing.rb
bozo-scripts-0.18.4 lib/bozo/hooks/timing.rb
bozo-scripts-0.18.3 lib/bozo/hooks/timing.rb
bozo-scripts-0.18.2 lib/bozo/hooks/timing.rb
bozo-scripts-0.18.1 lib/bozo/hooks/timing.rb
bozo-scripts-0.18.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.17.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.16.3 lib/bozo/hooks/timing.rb
bozo-scripts-0.16.2 lib/bozo/hooks/timing.rb
bozo-scripts-0.16.1 lib/bozo/hooks/timing.rb
bozo-scripts-0.16.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.15.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.14.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.13.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.12.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.11.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.10.6 lib/bozo/hooks/timing.rb
bozo-scripts-0.10.5 lib/bozo/hooks/timing.rb
bozo-scripts-0.10.4 lib/bozo/hooks/timing.rb
bozo-scripts-0.10.3 lib/bozo/hooks/timing.rb