Module: Timer

Included in:
Prick::Build::BuildBatch
Defined in:
lib/prick/local/timer.rb

Overview

TODO: Move class method implementations to Timer::Timer

Defined Under Namespace

Classes: Timer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fileObject

Output file used by #emit. Default is STDERR (this is set at load-time)



10
# File 'lib/prick/local/timer.rb', line 10

def self.file() @file end

.file=(file) ⇒ Object



11
# File 'lib/prick/local/timer.rb', line 11

def self.file=(file) @file = file end

.new(*args) ⇒ Object



34
35
36
37
38
# File 'lib/prick/local/timer.rb', line 34

def self.new(*args)
  object = Timer.allocate
  object.send(:initialize, *args)
  object
end

.off!Object



5
# File 'lib/prick/local/timer.rb', line 5

def self.off!() @on = false end

.off?Boolean

Returns:

  • (Boolean)


7
# File 'lib/prick/local/timer.rb', line 7

def self.off?() !@on end

.on!Object



4
# File 'lib/prick/local/timer.rb', line 4

def self.on!() @on = true end

.on?Boolean

Returns:

  • (Boolean)


6
# File 'lib/prick/local/timer.rb', line 6

def self.on?() @on end

.scaleObject

Number of digits after the decimal point. Default 0



18
# File 'lib/prick/local/timer.rb', line 18

def self.scale() @scale end

.scale=(scale) ⇒ Object



19
# File 'lib/prick/local/timer.rb', line 19

def self.scale=(scale) @scale = scale end

.time(label, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/prick/local/timer.rb', line 21

def self.time(label, &block)
  if on?
    timer = Timer.new(label)
    r = yield
    timer.emit
    r
  else
    yield
  end
end

.unitObject

Currently only :s, or :ms. Default is :ms



14
# File 'lib/prick/local/timer.rb', line 14

def self.unit() @unit end

.unit=(unit) ⇒ Object



15
# File 'lib/prick/local/timer.rb', line 15

def self.unit=(unit) @unit = unit end

Instance Method Details

#time(label, &block) ⇒ Object



32
# File 'lib/prick/local/timer.rb', line 32

def time(label, &block) ::Timer.time(label, &block) end