Class: Whysoslow::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/whysoslow/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(printer, opts = {}) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
# File 'lib/whysoslow/runner.rb', line 8

def initialize(printer, opts={})
  @printer = printer
  @time_unit = opts[:time_unit]
  @memory_unit = opts[:memory_unit]
  @results = nil
end

Instance Attribute Details

#descObject

Returns the value of attribute desc.



6
7
8
# File 'lib/whysoslow/runner.rb', line 6

def desc
  @desc
end

#memory_unitObject

Returns the value of attribute memory_unit.



6
7
8
# File 'lib/whysoslow/runner.rb', line 6

def memory_unit
  @memory_unit
end

#time_unitObject

Returns the value of attribute time_unit.



6
7
8
# File 'lib/whysoslow/runner.rb', line 6

def time_unit
  @time_unit
end

#verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/whysoslow/runner.rb', line 6

def verbose
  @verbose
end

Instance Method Details

#run(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/whysoslow/runner.rb', line 15

def run(&block)
  @printer.print :title
  @printer.print(Results.new(@desc, @time_unit, @memory_unit).tap do |results|
    @results = results
    @printer.print :run_start
    self.snapshot('start')
    @results.benchmark(&block)
    self.snapshot('finish')
    @printer.print :run_end
    @results = nil
  end)
end

#snapshot(*args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/whysoslow/runner.rb', line 28

def snapshot(*args)
  if @results.nil?
    raise RuntimeError, "no active results being gathered"\
                        " - be sure and call snapshot during a run session"
  end
  @results.snapshot(*args)
  @printer.print :snapshot
end