Class: Tryouts::Drill::Sergeant::API
- Inherits:
-
Object
- Object
- Tryouts::Drill::Sergeant::API
- Defined in:
- lib/tryouts/drill/sergeant/api.rb
Overview
API
The sergeant responsible for running Ruby code (API) drills.
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(output = nil) ⇒ API
constructor
opts
is a Hash with the following optional keys:. - #run(block, context, &inline) ⇒ Object
Constructor Details
#initialize(output = nil) ⇒ API
opts
is a Hash with the following optional keys:
-
:output
specify a return value. This will be
used if no block is specified for the drill.
18 19 20 |
# File 'lib/tryouts/drill/sergeant/api.rb', line 18 def initialize(output=nil) @output = output end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
12 13 14 |
# File 'lib/tryouts/drill/sergeant/api.rb', line 12 def output @output end |
Instance Method Details
#run(block, context, &inline) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tryouts/drill/sergeant/api.rb', line 22 def run(block, context, &inline) # A Proc object takes precedence over an inline block. runtime = (block.nil? ? inline : block) response = Tryouts::Drill::Reality.new if runtime.nil? response.output = @output else begin response.output = context.instance_eval &runtime rescue => e puts e., e.backtrace if Tryouts.verbose > 2 response.etype = e.class response.error = e. response.trace = e.backtrace end end response end |