Class: Droonga::Serf::Command

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/droonga/serf/command.rb

Defined Under Namespace

Classes: Failure, ForbiddenCommandInEventHandler

Constant Summary collapse

DANGEROUS_COMMANDS_IN_EVENT_HANDLER =
[
  "event",
  "query",
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serf, command, *options) ⇒ Command

Returns a new instance of Command.



54
55
56
57
58
59
60
# File 'lib/droonga/serf/command.rb', line 54

def initialize(serf, command, *options)
  assert_safe_command(command)
  @serf = serf
  @command = command
  @options = options
  @verbose = false
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



52
53
54
# File 'lib/droonga/serf/command.rb', line 52

def verbose
  @verbose
end

Instance Method Details

#runObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/droonga/serf/command.rb', line 62

def run
  command_line = [@serf, @command] + @options
  p command_line if @verbose
  stdout, stderror, status = Open3.capture3(*command_line,
                                            :pgroup => true)
  unless status.success?
    raise Failure.new(command_line, status.to_i, stdout, stderror)
  end
  logger.error("run: #{stderror}") unless stderror.empty?
  if @verbose
    begin
      pp JSON.parse(stdout)
    rescue JSON::ParserError
      p stdout
    end
  end
  stdout
end