Sha256: becd48cb503a36828d951187d78a534164d4b0d0e5222c0e89a6491fe07cde63

Contents?: true

Size: 1022 Bytes

Versions: 4

Compression:

Stored size: 1022 Bytes

Contents



class Tryouts; class Drill; module Sergeant
  
  # = API
  # 
  # The sergeant responsible for running Ruby code (API) drills.
  #
  class API
    
    attr_reader :opts
    
    # +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.
    def initialize(opts={})
      @opts = opts
    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 = @opts[:output]
      else
        begin
          response.output = context.instance_eval &runtime
        rescue => e
          puts e.message, e.backtrace if Tryouts.debug? && Tryouts.verbose > 2
          response.etype = e.class
          response.error = e.message
          response.trace = e.backtrace
        end
      end
      response
    end
    
  end
end; end; end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
delano-tryouts-0.6.0 lib/tryouts/drill/sergeant/api.rb
delano-tryouts-0.6.1 lib/tryouts/drill/sergeant/api.rb
tryouts-0.6.0 lib/tryouts/drill/sergeant/api.rb
tryouts-0.6.1 lib/tryouts/drill/sergeant/api.rb