Class: Droonga::Serf::Command
- Inherits:
-
Object
- Object
- Droonga::Serf::Command
- 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
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(serf, command, *options) ⇒ Command
constructor
A new instance of Command.
-
#run ⇒ Object
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, *) assert_safe_command(command) @serf = serf @command = command @options = @verbose = false end |
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
52 53 54 |
# File 'lib/droonga/serf/command.rb', line 52 def verbose @verbose end |
Instance Method Details
#run ⇒ Object
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 |