Sha256: 54bbbf449e814901ecb813a5f0bc91c845edda3c97d352896077d83f8af9681d

Contents?: true

Size: 1006 Bytes

Versions: 4

Compression:

Stored size: 1006 Bytes

Contents


class Tryouts; class Drill; module Sergeant
  
  # = API
  # 
  # The sergeant responsible for running Ruby code (API) drills.
  #
  class API
    
    # +return_value+ specify a return value. This will be 
    # used if no block is specified for the drill.
    def initialize(return_value=nil)
      @return_value = return_value
    end
  
    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 = @return_value
      else
        begin
          unless runtime.nil?
            ret = context.instance_eval &runtime
            response.output, response.rcode = ret, 0
          end
        rescue => ex
          response.rcode = 1
          response.output = ret
          response.emsg = ex.message
          response.backtrace = ex.backtrace
        end
      end
      response
    end
    
  end
end; end; end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
delano-tryouts-0.5.0 lib/tryouts/drill/sergeant/api.rb
delano-tryouts-0.5.1 lib/tryouts/drill/sergeant/api.rb
tryouts-0.5.0 lib/tryouts/drill/sergeant/api.rb
tryouts-0.5.1 lib/tryouts/drill/sergeant/api.rb