Class: Grntest::Executors::BaseExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/grntest/executors/base-executor.rb

Direct Known Subclasses

HTTPExecutor, StandardIOExecutor

Defined Under Namespace

Modules: ReturnCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = nil) ⇒ BaseExecutor

Returns a new instance of BaseExecutor.



36
37
38
39
40
41
42
43
44
# File 'lib/grntest/executors/base-executor.rb', line 36

def initialize(context=nil)
  @loading = false
  @pending_command = ""
  @pending_load_command = nil
  @current_command_name = nil
  @output_type = nil
  @long_timeout = default_long_timeout
  @context = context || ExecutionContext.new
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



35
36
37
# File 'lib/grntest/executors/base-executor.rb', line 35

def context
  @context
end

Instance Method Details

#execute(script_path) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/grntest/executors/base-executor.rb', line 46

def execute(script_path)
  unless script_path.exist?
    raise NotExist.new(script_path)
  end

  @context.execute do
    script_path.open("r:ascii-8bit") do |script_file|
      parser = create_parser
      script_file.each_line do |line|
        begin
          parser << line
        rescue Error, Groonga::Command::Parser::Error
          line_info = "#{script_path}:#{script_file.lineno}:#{line.chomp}"
          log_error("#{line_info}: #{$!.message}")
          if $!.is_a?(Groonga::Command::Parser::Error)
            @context.abort
          else
            log_error("#{line_info}: #{$!.message}")
            raise unless @context.top_level?
          end
        end
      end
    end
  end

  @context.result
end