Sha256: 27410766d554f63431ea23dcd84b886c98c5492935d5e30e20f707beaf156a6c

Contents?: true

Size: 884 Bytes

Versions: 11

Compression:

Stored size: 884 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

11 entries across 11 versions & 1 rubygems

Version Path
bozo-scripts-0.3.1 lib/bozo/hooks/timing.rb
bozo-scripts-0.3.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.2.4 lib/bozo/hooks/timing.rb
bozo-scripts-0.2.3 lib/bozo/hooks/timing.rb
bozo-scripts-0.2.2 lib/bozo/hooks/timing.rb
bozo-scripts-0.2.1 lib/bozo/hooks/timing.rb
bozo-scripts-0.2.0 lib/bozo/hooks/timing.rb
bozo-scripts-0.1.10 lib/bozo/hooks/timing.rb
bozo-scripts-0.1.9 lib/bozo/hooks/timing.rb
bozo-scripts-0.1.8 lib/bozo/hooks/timing.rb
bozo-scripts-0.1.7 lib/bozo/hooks/timing.rb