Sha256: 30089e2f6f0a33b2699d8e6eb7c4f1a8dfdf22f4efeb0a0232f9a234d07f95c6

Contents?: true

Size: 939 Bytes

Versions: 2

Compression:

Stored size: 939 Bytes

Contents

require 'whysoslow/results'

module Whysoslow
  class Runner

    attr_accessor :desc, :verbose, :time_unit, :memory_unit

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

    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

    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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whysoslow-1.0.1 lib/whysoslow/runner.rb
whysoslow-1.0.0 lib/whysoslow/runner.rb