Sha256: dd929db108745ae1c5a3372cb5ed56378062511980c4394868d100375972486e

Contents?: true

Size: 712 Bytes

Versions: 12

Compression:

Stored size: 712 Bytes

Contents

require 'cap-util/timer'

module CapUtil

  def self.time(timer_set, name, &block)
    timer_set[name] ||= CapUtil::Timer.new(name)
    if !block.nil?
      begin
        timer_set[name].start
        block.call
      ensure
        timer_set[name].end
      end
    end
    timer_set[name]
  end

  module Time

    def self.included(receiver)
      receiver.send(:extend,  ClassMethods)
      receiver.send(:include, InstanceMethods)
    end

    module ClassMethods
      def time(*args, &block); CapUtil.time(*args, &block); end
    end

    module InstanceMethods
      def time(name, &block)
        @cap_util_timers ||= {}
        CapUtil.time(@cap_util_timers, name, &block)
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cap-util-1.5.2 lib/cap-util/time.rb
cap-util-1.5.1 lib/cap-util/time.rb
cap-util-1.5.0 lib/cap-util/time.rb
cap-util-1.4.0 lib/cap-util/time.rb
cap-util-1.3.0 lib/cap-util/time.rb
cap-util-1.2.0 lib/cap-util/time.rb
cap-util-1.1.0 lib/cap-util/time.rb
cap-util-1.0.1 lib/cap-util/time.rb
cap-util-1.0.0 lib/cap-util/time.rb
cap-util-1.0.0.rc1 lib/cap-util/time.rb
cap-util-0.4.0 lib/cap-util/time.rb
cap-util-0.3.0 lib/cap-util/time.rb