Class: RubyShell::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyshell/command.rb

Instance Method Summary collapse

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_commandObject



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_argsObject



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_shellObject



11
12
13
# File 'lib/rubyshell/command.rb', line 11

def to_shell
  [@command_name.to_s.gsub("!", ""), *parsed_args].join(" ")
end