Class: Lucid::Formatter::Interceptor::Pipe
- Inherits:
-
Object
- Object
- Lucid::Formatter::Interceptor::Pipe
show all
- Defined in:
- lib/lucid/formatter/interceptor.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pipe) ⇒ Pipe
Returns a new instance of Pipe.
7
8
9
10
11
|
# File 'lib/lucid/formatter/interceptor.rb', line 7
def initialize(pipe)
@pipe = pipe
@buffer = []
@wrapped = true
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
23
24
25
|
# File 'lib/lucid/formatter/interceptor.rb', line 23
def method_missing(method, *args, &blk)
@pipe.send(method, *args, &blk)
end
|
Instance Attribute Details
Returns the value of attribute buffer.
6
7
8
|
# File 'lib/lucid/formatter/interceptor.rb', line 6
def buffer
@buffer
end
|
Returns the value of attribute pipe.
6
7
8
|
# File 'lib/lucid/formatter/interceptor.rb', line 6
def pipe
@pipe
end
|
Class Method Details
.unwrap!(pipe) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/lucid/formatter/interceptor.rb', line 37
def self.unwrap!(pipe)
validate_pipe pipe
wrapped = nil
case pipe
when :stdout
wrapped = $stdout
$stdout = wrapped.unwrap! if $stdout.respond_to?(:unwrap!)
when :stderr
wrapped = $stderr
$stderr = wrapped.unwrap! if $stderr.respond_to?(:unwrap!)
end
wrapped
end
|
.validate_pipe(pipe) ⇒ Object
31
32
33
34
35
|
# File 'lib/lucid/formatter/interceptor.rb', line 31
def self.validate_pipe(pipe)
unless [:stdout, :stderr].include? pipe
raise ArgumentError, '#wrap only accepts :stderr or :stdout'
end
end
|
.wrap(pipe) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/lucid/formatter/interceptor.rb', line 51
def self.wrap(pipe)
validate_pipe pipe
case pipe
when :stderr
$stderr = self.new($stderr)
return $stderr
when :stdout
$stdout = self.new($stdout)
return $stdout
end
end
|
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
27
28
29
|
# File 'lib/lucid/formatter/interceptor.rb', line 27
def respond_to?(method, include_private=false)
super || @pipe.respond_to?(method, include_private)
end
|
18
19
20
21
|
# File 'lib/lucid/formatter/interceptor.rb', line 18
def unwrap!
@wrapped = false
@pipe
end
|
#write(str) ⇒ Object
13
14
15
16
|
# File 'lib/lucid/formatter/interceptor.rb', line 13
def write(str)
@buffer << str if @wrapped
return @pipe.write(str)
end
|