Class: Benchmark::Sweet::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/sweet/item.rb

Overview

borrowed heavily from Benchmark::IPS::Job::Entry may be able to fallback on that - will need to generate a &block friendly proc for that structure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, action = nil) ⇒ Item

Returns a new instance of Item.



7
8
9
10
# File 'lib/benchmark/sweet/item.rb', line 7

def initialize(label, action = nil)
  @label = label
  @action = action || @label[:method] #raise("Item needs an action")
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/benchmark/sweet/item.rb', line 6

def action
  @action
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/benchmark/sweet/item.rb', line 6

def label
  @label
end

Instance Method Details

#blockObject



12
13
14
# File 'lib/benchmark/sweet/item.rb', line 12

def block
  @block ||= action.kind_of?(String) ? compile(action) : action
end

#compile(str) ⇒ Object

to use with Job::Entry… def call_once ; call_times(1) ; end def callback_proc

lambda(&method(:call_once))

end



21
22
23
24
25
26
27
# File 'lib/benchmark/sweet/item.rb', line 21

def compile(str)
  eval <<-CODE
    Proc.new do
      #{str}
    end
  CODE
end