Class: Hone::Harness

Inherits:
Object
  • Object
show all
Defined in:
lib/hone/harness.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHarness

Returns a new instance of Harness.



15
16
17
18
19
20
# File 'lib/hone/harness.rb', line 15

def initialize
  @setup_block = nil
  @exercise_block = nil
  @teardown_block = nil
  @iterations = 1
end

Instance Attribute Details

#exercise_blockObject (readonly)

Returns the value of attribute exercise_block.



5
6
7
# File 'lib/hone/harness.rb', line 5

def exercise_block
  @exercise_block
end

#iterationsObject (readonly)

Returns the value of attribute iterations.



5
6
7
# File 'lib/hone/harness.rb', line 5

def iterations
  @iterations
end

#setup_blockObject (readonly)

Returns the value of attribute setup_block.



5
6
7
# File 'lib/hone/harness.rb', line 5

def setup_block
  @setup_block
end

#teardown_blockObject (readonly)

Returns the value of attribute teardown_block.



5
6
7
# File 'lib/hone/harness.rb', line 5

def teardown_block
  @teardown_block
end

Class Method Details

.load(path) ⇒ Object

Raises:



7
8
9
10
11
12
13
# File 'lib/hone/harness.rb', line 7

def self.load(path)
  raise Hone::Error, "Harness file not found: #{path}" unless File.exist?(path)

  harness = new
  harness.instance_eval(File.read(path), path)
  harness
end

Instance Method Details

#exercise(iterations: 1, &block) ⇒ Object

Exercise block - the code to profile

Parameters:

  • iterations (Integer) (defaults to: 1)

    Number of times to run the block during profiling



30
31
32
33
# File 'lib/hone/harness.rb', line 30

def exercise(iterations: 1, &block)
  @iterations = iterations
  @exercise_block = block
end

#run_exerciseObject



45
46
47
# File 'lib/hone/harness.rb', line 45

def run_exercise
  @exercise_block&.call
end

#run_setupObject



41
42
43
# File 'lib/hone/harness.rb', line 41

def run_setup
  @setup_block&.call
end

#run_teardownObject



49
50
51
# File 'lib/hone/harness.rb', line 49

def run_teardown
  @teardown_block&.call
end

#setup(&block) ⇒ Object

Setup block - runs once before profiling (not profiled) Used for loading the application, creating test data, etc.



24
25
26
# File 'lib/hone/harness.rb', line 24

def setup(&block)
  @setup_block = block
end

#teardown(&block) ⇒ Object

Teardown block - runs once after profiling (not profiled) Used for cleanup, closing connections, etc.



37
38
39
# File 'lib/hone/harness.rb', line 37

def teardown(&block)
  @teardown_block = block
end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/hone/harness.rb', line 53

def valid?
  !@exercise_block.nil?
end