Class: RubyShell::Command
- Inherits:
-
Object
- Object
- RubyShell::Command
- Defined in:
- lib/rubyshell/command.rb
Instance Method Summary collapse
- #exec_command ⇒ Object
-
#initialize(command_name, *args, &block) ⇒ Command
constructor
A new instance of Command.
- #parsed_args ⇒ Object
- #to_shell ⇒ Object
Constructor Details
#initialize(command_name, *args, &block) ⇒ Command
Returns a new instance of Command.
5 6 7 8 9 |
# File 'lib/rubyshell/command.rb', line 5 def initialize(command_name, *args, &block) @command_name = command_name @args = args @block = block end |
Instance Method Details
#exec_command ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rubyshell/command.rb', line 15 def exec_command result = `#{to_shell}`.chomp raise "Command Failed" unless $?.success? result end |
#parsed_args ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubyshell/command.rb', line 23 def parsed_args @args.map do |arg| case arg when Hash map_hash_arg(arg) else arg.to_s end end.flatten end |
#to_shell ⇒ Object
11 12 13 |
# File 'lib/rubyshell/command.rb', line 11 def to_shell [@command_name.to_s.gsub("!", ""), *parsed_args].join(" ") end |