Class: GroongaClientCLI::GroongaClient

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga-client-cli/groonga-client.rb

Defined Under Namespace

Classes: Runner

Instance Method Summary collapse

Constructor Details

#initializeGroongaClient

Returns a new instance of GroongaClient.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/groonga-client-cli/groonga-client.rb', line 30

def initialize
  @protocol = :http
  @host     = "localhost"
  @port     = nil

  @read_timeout = Default::READ_TIMEOUT

  @runner_options = {
    :split_load_chunk_size => 10000,
  }
end

Instance Method Details

#run(argv) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/groonga-client-cli/groonga-client.rb', line 42

def run(argv)
  command_file_paths = parse_command_line(argv)

  @client = Groonga::Client.new(:protocol => @protocol,
                                :host     => @host,
                                :port     => @port,
                                :read_timeout => @read_timeout,
                                :backend  => :synchronous)
  runner = Runner.new(@client, @runner_options)

  if command_file_paths.empty?
    $stdin.each_line do |line|
      runner << line
    end
  else
    command_file_paths.each do |command_file_path|
      File.open(command_file_path) do |command_file|
        command_file.each_line do |line|
          runner << line
        end
      end
    end
  end

  true
end