module Allotment
Allotment
“Time is what we want most, but what we use worst.”
require ‘allotment’
Allotment.record
‘my_event’ do
# code here
end
Allotment.start
‘my_event’ # code here Allotment.stop
‘my_event’
Constants
- DATE
Date version created
- VERSION
Current
Allotment
verion
Public Class Methods
on_start(&block)
click to toggle source
Called when a recording is started @return [Proc] the stored request proc
# File lib/allotment.rb, line 29 def on_start &block block_given? ? @on_start = block : @on_start end
on_stop(&block)
click to toggle source
Called when a recording is stopped @return [Proc] the stored request proc
# File lib/allotment.rb, line 36 def on_stop &block block_given? ? @on_stop = block : @on_stop end
record(name = 'unnamed_event') { || ... }
click to toggle source
Record event Expects a block to be passed @param name [String] the name of the event @yield [] runs the event
# File lib/allotment.rb, line 67 def record name = 'unnamed_event' start name begin yield ensure result = stop name end result end
results()
click to toggle source
Results at that present moment @return [Hashie::Mash] the current results
# File lib/allotment.rb, line 80 def results @results end
start(name = 'unnamed_recording')
click to toggle source
Start recording @param name [String] the name of the event
# File lib/allotment.rb, line 43 def start name = 'unnamed_recording' on_start.call if on_start @watches[name] = Stopwatch.new(name).start end
stop(name)
click to toggle source
Stop recording @param name [String] the name of the event @raise [NameError] if the recording does not exist
# File lib/allotment.rb, line 52 def stop name result = @watches.delete(name){ |n| raise NameError, "Unknown recording:" + n }.stop on_stop.call if on_stop # Dealing with the results @results[name] ||= Array.new @results[name] << result return result end