Class: VCSRuby::Command
- Inherits:
-
Object
- Object
- VCSRuby::Command
- Defined in:
- lib/command.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #execute(parameter, streams = 0, no_error = false) ⇒ Object
-
#initialize(name, command) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(name, command) ⇒ Command
Returns a new instance of Command.
8 9 10 11 12 |
# File 'lib/command.rb', line 8 def initialize name, command @name = name @command = which(command) @available = !!@command end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/command.rb', line 7 def name @name end |
Instance Method Details
#available? ⇒ Boolean
14 15 16 |
# File 'lib/command.rb', line 14 def available? @available end |
#execute(parameter, streams = 0, no_error = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/command.rb', line 18 def execute parameter, streams = 0, no_error = false raise "Command '#{name}' not available" unless available? puts "#{@command} #{parameter}" if Configuration.instance.verbose? result = nil if Tools::windows? streams = '2> nul' if streams === 0 result = `cmd /S /C ""#{@command}" #{parameter} #{streams}"` else streams = "2> /dev/null" if streams === 0 result =`"#{@command}" #{parameter} #{streams}` end raise "#{@command} failed with return value '#{$?}'" unless $?.to_i == 0 || no_error return result end |