Class: Hone::Harness
- Inherits:
-
Object
- Object
- Hone::Harness
- Defined in:
- lib/hone/harness.rb
Instance Attribute Summary collapse
-
#exercise_block ⇒ Object
readonly
Returns the value of attribute exercise_block.
-
#iterations ⇒ Object
readonly
Returns the value of attribute iterations.
-
#setup_block ⇒ Object
readonly
Returns the value of attribute setup_block.
-
#teardown_block ⇒ Object
readonly
Returns the value of attribute teardown_block.
Class Method Summary collapse
Instance Method Summary collapse
-
#exercise(iterations: 1, &block) ⇒ Object
Exercise block - the code to profile.
-
#initialize ⇒ Harness
constructor
A new instance of Harness.
- #run_exercise ⇒ Object
- #run_setup ⇒ Object
- #run_teardown ⇒ Object
-
#setup(&block) ⇒ Object
Setup block - runs once before profiling (not profiled) Used for loading the application, creating test data, etc.
-
#teardown(&block) ⇒ Object
Teardown block - runs once after profiling (not profiled) Used for cleanup, closing connections, etc.
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Harness
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_block ⇒ Object (readonly)
Returns the value of attribute exercise_block.
5 6 7 |
# File 'lib/hone/harness.rb', line 5 def exercise_block @exercise_block end |
#iterations ⇒ Object (readonly)
Returns the value of attribute iterations.
5 6 7 |
# File 'lib/hone/harness.rb', line 5 def iterations @iterations end |
#setup_block ⇒ Object (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_block ⇒ Object (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
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
30 31 32 33 |
# File 'lib/hone/harness.rb', line 30 def exercise(iterations: 1, &block) @iterations = iterations @exercise_block = block end |
#run_exercise ⇒ Object
45 46 47 |
# File 'lib/hone/harness.rb', line 45 def run_exercise @exercise_block&.call end |
#run_setup ⇒ Object
41 42 43 |
# File 'lib/hone/harness.rb', line 41 def run_setup @setup_block&.call end |
#run_teardown ⇒ Object
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
53 54 55 |
# File 'lib/hone/harness.rb', line 53 def valid? !@exercise_block.nil? end |