Class: GroongaQueryLog::Command::Extract

Inherits:
GroongaQueryLog::CommandLine show all
Defined in:
lib/groonga-query-log/command/extract.rb

Defined Under Namespace

Classes: DumpFormatter, InspectFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExtract

Returns a new instance of Extract.



31
32
33
34
35
# File 'lib/groonga-query-log/command/extract.rb', line 31

def initialize
  @options = nil
  @option_parser = nil
  setup_options
end

Instance Attribute Details

#option_parserObject (readonly)

Returns the value of attribute option_parser.



29
30
31
# File 'lib/groonga-query-log/command/extract.rb', line 29

def option_parser
  @option_parser
end

#optionsObject

Returns the value of attribute options.



28
29
30
# File 'lib/groonga-query-log/command/extract.rb', line 28

def options
  @options
end

Instance Method Details

#run(arguments) ⇒ Object

Executes extractor for Groonga’s query logs. “groonga-query-log-extract” command runs this method.

If only paths of query log files are specified, this method prints command(s) of them to console.

Examples:

extractor = GroongaQueryLog::Command::Extract.new
extractor.run("--output", "commands.output",
              "--command", "select",
              "query.log")

Parameters:

  • arguments (Array<String>)

    arguments for groonga-query-log-extract. Please execute “groonga-query-log-extract –help” or see #setup_options.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/groonga-query-log/command/extract.rb', line 52

def run(arguments)
  begin
    log_paths = @option_parser.parse!(arguments)
  rescue OptionParser::ParseError
    $stderr.puts($!.message)
    return false
  end

  begin
    if @options.output
      File.open(@options.output, "w") do |output|
        extract(log_paths, output)
      end
    else
      extract(log_paths, $stdout)
    end
  rescue Interrupt, Errno::EPIPE
  rescue Error
    $stderr.puts($!.message)
    return false
  end

  true
end