Class: Groonga::Context::CommandExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/context/command-executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ CommandExecutor

Returns a new instance of CommandExecutor.



24
25
26
# File 'lib/groonga/context/command-executor.rb', line 24

def initialize(context)
  @context = context
end

Instance Method Details

#execute(name, parameters = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/groonga/context/command-executor.rb', line 28

def execute(name, parameters={})
  parameters = normalize_parameters(name, parameters)
  command_class = Command.find(name)
  command = command_class.new(name, parameters)
  request_id = @context.send(command.to_command_format)
  loop do
    response_id, raw_response = @context.receive
    if request_id == response_id
      response_class = Client::Response.find(command.name)
      header = [0, 0, 0]
      case command.output_type
      when :json
        body = JSON.parse(raw_response)
      else
        body = raw_response
      end
      response = response_class.new(command, header, body)
      response.raw = raw_response
      return response
    end
    # raise if request_id < response_id
  end
end