Class: Cocaine::CommandLine
- Inherits:
-
Object
- Object
- Cocaine::CommandLine
- Defined in:
- lib/cocaine/command_line.rb
Class Attribute Summary (collapse)
-
+ (Object) path
Returns the value of attribute path.
Instance Method Summary (collapse)
- - (Object) command
-
- (CommandLine) initialize(binary, params = "", options = {})
constructor
A new instance of CommandLine.
- - (Object) run
Constructor Details
- (CommandLine) initialize(binary, params = "", options = {})
A new instance of CommandLine
7 8 9 10 11 12 13 14 |
# File 'lib/cocaine/command_line.rb', line 7 def initialize(binary, params = "", = {}) @binary = binary.dup @params = params.dup @options = .dup @swallow_stderr = @options.delete(:swallow_stderr) @expected_outcodes = @options.delete(:expected_outcodes) @expected_outcodes ||= [0] end |
Class Attribute Details
+ (Object) path
Returns the value of attribute path
4 5 6 |
# File 'lib/cocaine/command_line.rb', line 4 def path @path end |
Instance Method Details
- (Object) command
16 17 18 19 20 21 22 |
# File 'lib/cocaine/command_line.rb', line 16 def command cmd = [] cmd << @binary cmd << interpolate(@params, @options) cmd << bit_bucket if @swallow_stderr cmd.join(" ").strip end |
- (Object) run
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cocaine/command_line.rb', line 24 def run output = '' begin with_modified_path do output = self.class.send(:`', command) end rescue Errno::ENOENT raise Cocaine::CommandNotFoundError end if $?.exitstatus == 127 raise Cocaine::CommandNotFoundError end unless @expected_outcodes.include?($?.exitstatus) raise Cocaine::ExitStatusError, "Command '#{command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}" end output end |