Class: Loom::Shell::CmdRedirect

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/shell/cmd_wrapper.rb

Defined Under Namespace

Modules: Mode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word, fd: nil, mode: Mode::OUTPUT) ⇒ CmdRedirect

Returns a new instance of CmdRedirect.



123
124
125
126
127
# File 'lib/loom/shell/cmd_wrapper.rb', line 123

def initialize(word, fd: nil, mode: Mode::OUTPUT)
  @fd = fd
  @word = word
  @mode = mode
end

Class Method Details

.append_stdout(word) ⇒ Object



109
110
111
# File 'lib/loom/shell/cmd_wrapper.rb', line 109

def append_stdout(word)
  CmdRedirect.new(word, mode: Mode::APPEND)
end

Instance Method Details

#to_sObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/loom/shell/cmd_wrapper.rb', line 129

def to_s
  case @mode
  when Mode::INPUT
    "%s<%s" % [@fd, @word]
  when Mode::OUTPUT
    "%s>%s" % [@fd, @word]
  when Mode::APPEND
    "%s>>%s" % [@fd, @word]
  when Mode::OUTPUT_12
    "&>%s" % [@word]
  when Mode::APPEND_12
    "&>>%s" % [@word]
  else
    raise "invalid shell redirection mode: #{@mode}"
  end
end