Class: Scripto::RunCommands::CommandLine
- Inherits:
-
Object
- Object
- Scripto::RunCommands::CommandLine
- Defined in:
- lib/scripto/run_commands.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#command ⇒ Object
Returns the value of attribute command.
Instance Method Summary collapse
- #capture ⇒ Object
-
#initialize(command, args) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #raise!(status) ⇒ Object
- #run ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(command, args) ⇒ CommandLine
Returns a new instance of CommandLine.
45 46 47 48 49 50 51 52 |
# File 'lib/scripto/run_commands.rb', line 45 def initialize(command, args) self.command = command self.args = if args args.map(&:to_s) else [ ] end end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
43 44 45 |
# File 'lib/scripto/run_commands.rb', line 43 def args @args end |
#command ⇒ Object
Returns the value of attribute command.
43 44 45 |
# File 'lib/scripto/run_commands.rb', line 43 def command @command end |
Instance Method Details
#capture ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/scripto/run_commands.rb', line 59 def capture begin captured = `#{to_s}` rescue Errno::ENOENT raise Error, "#{self} failed : ENOENT (No such file or directory)" end raise!($CHILD_STATUS) if $CHILD_STATUS != 0 captured end |
#raise!(status) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/scripto/run_commands.rb', line 69 def raise!(status) if status.termsig == Signal.list["INT"] raise "#{self} interrupted" end raise Error, "#{self} failed : #{status.to_i / 256}" end |
#run ⇒ Object
54 55 56 57 |
# File 'lib/scripto/run_commands.rb', line 54 def run system(command, *args) raise!($CHILD_STATUS) if $CHILD_STATUS != 0 end |
#to_s ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/scripto/run_commands.rb', line 76 def to_s if args.length > 0 escaped = args.map { |i| Shellwords.escape(i) } "#{command} #{escaped.join(" ")}" else command end end |