Class: Chitin::Pipe
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Runnable
#<, #>, #>>, #[], #^, #bg!, #bg?, #fg?
Constructor Details
#initialize(*parts) ⇒ Pipe
Returns a new instance of Pipe.
8
9
10
11
12
13
14
|
# File 'lib/chitin/commands/pipe.rb', line 8
def initialize(*parts)
@parts = parts
super()
link_all
end
|
Instance Attribute Details
Returns the value of attribute parts.
5
6
7
|
# File 'lib/chitin/commands/pipe.rb', line 5
def parts
@parts
end
|
Returns the value of attribute pids.
6
7
8
|
# File 'lib/chitin/commands/pipe.rb', line 6
def pids
@pids
end
|
Instance Method Details
94
95
96
|
# File 'lib/chitin/commands/pipe.rb', line 94
def err
@parts.last[:err]
end
|
#err=(other) ⇒ Object
97
|
# File 'lib/chitin/commands/pipe.rb', line 97
def err=(other); @parts.last[:set_err, other]; end
|
84
85
86
|
# File 'lib/chitin/commands/pipe.rb', line 84
def in
@parts.first[:in]
end
|
#in=(other) ⇒ Object
87
|
# File 'lib/chitin/commands/pipe.rb', line 87
def in=(other); @parts.first[:set_in, other]; end
|
#link(left, right) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/chitin/commands/pipe.rb', line 27
def link(left, right)
r, w = IO.pipe
left > w
r > right
w.close
r.close end
|
17
18
19
20
21
22
23
24
25
|
# File 'lib/chitin/commands/pipe.rb', line 17
def link_all
parts[1..-1].inject parts.first do |left, right|
link left, right
right
end
end
|
89
90
91
|
# File 'lib/chitin/commands/pipe.rb', line 89
def out
@parts.last[:out]
end
|
#out=(other) ⇒ Object
92
|
# File 'lib/chitin/commands/pipe.rb', line 92
def out=(other); @parts.last[:set_out, other]; end
|
Run them all but let the last run return its value
54
55
56
57
58
59
60
|
# File 'lib/chitin/commands/pipe.rb', line 54
def raw_run
parts[0..-2].each {|part| part[:run] }
result = parts.last[:raw_run]
reset
result
end
|
68
69
70
71
72
73
|
# File 'lib/chitin/commands/pipe.rb', line 68
def reset
parts.map {|part| part[:reset] }
link_all
self
end
|
#returning ⇒ Object
103
104
105
|
# File 'lib/chitin/commands/pipe.rb', line 103
def returning
parts.last[:returning]
end
|
Like raw_run, but meant to be used in chaining.
46
47
48
49
50
51
|
# File 'lib/chitin/commands/pipe.rb', line 46
def run
parts.each {|part| part[:run] }
reset
self
end
|
99
100
101
|
# File 'lib/chitin/commands/pipe.rb', line 99
def to_s
"#{self.in} > #{parts.map {|p| p[:to_s] }.join ' | '} > #{self.out}"
end
|
62
63
64
65
66
|
# File 'lib/chitin/commands/pipe.rb', line 62
def wait
parts.each {|part| part[:wait] }
self
end
|
75
76
77
78
79
80
81
82
|
# File 'lib/chitin/commands/pipe.rb', line 75
def |(other)
raise "#{other.class} needs to include Runnable" unless Runnable === other
link parts.last, other
parts << other
self
end
|