Module: Coque::Redirectable

Included in:
Cmd, Pipeline
Defined in:
lib/coque/redirectable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stderrObject

Returns the value of attribute stderr.



5
6
7
# File 'lib/coque/redirectable.rb', line 5

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



5
6
7
# File 'lib/coque/redirectable.rb', line 5

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



5
6
7
# File 'lib/coque/redirectable.rb', line 5

def stdout
  @stdout
end

Instance Method Details

#<(io) ⇒ Object



23
24
25
# File 'lib/coque/redirectable.rb', line 23

def <(io)
  self.in(io)
end

#>(io) ⇒ Object



13
14
15
# File 'lib/coque/redirectable.rb', line 13

def >(io)
  out(io)
end

#>=(io) ⇒ Object



33
34
35
# File 'lib/coque/redirectable.rb', line 33

def >=(io)
  err(io)
end

#err(io) ⇒ Object



27
28
29
30
31
# File 'lib/coque/redirectable.rb', line 27

def err(io)
  clone.tap do |c|
    c.stderr = io
  end
end

#getio(io, mode = "r") ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coque/redirectable.rb', line 37

def getio(io, mode = "r")
  case io
  when STDERR
    io.dup
  when STDOUT
    io.dup
  when String
    File.open(io, mode)
  when Pathname
    File.open(io, mode)
  when IO
    io
  when Tempfile
    io
  else
    raise ArgumentError.new("Can't redirect stream to #{io}, must be String, Pathname, or IO")
  end
end

#in(io) ⇒ Object



17
18
19
20
21
# File 'lib/coque/redirectable.rb', line 17

def in(io)
  clone.tap do |c|
    c.stdin = io
  end
end

#out(io) ⇒ Object



7
8
9
10
11
# File 'lib/coque/redirectable.rb', line 7

def out(io)
  clone.tap do |c|
    c.stdout = io
  end
end