Class: Cucumber::Formatter::Interceptor::Pipe
- Inherits:
-
Object
- Object
- Cucumber::Formatter::Interceptor::Pipe
show all
- Defined in:
- lib/cucumber/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.
9
10
11
12
13
14
|
# File 'lib/cucumber/formatter/interceptor.rb', line 9
def initialize(pipe)
@pipe = pipe
@buffer = StringIO.new
@wrapped = true
@lock = Mutex.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
34
35
36
|
# File 'lib/cucumber/formatter/interceptor.rb', line 34
def method_missing(method, *args, &blk)
@pipe.respond_to?(method) ? @pipe.send(method, *args, &blk) : super
end
|
Instance Attribute Details
#pipe ⇒ Object
Returns the value of attribute pipe.
7
8
9
|
# File 'lib/cucumber/formatter/interceptor.rb', line 7
def pipe
@pipe
end
|
Class Method Details
.unwrap!(pipe) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/cucumber/formatter/interceptor.rb', line 46
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
42
43
44
|
# File 'lib/cucumber/formatter/interceptor.rb', line 42
def self.validate_pipe(pipe)
raise ArgumentError, '#wrap only accepts :stderr or :stdout' unless %i[stdout stderr].include? pipe
end
|
.wrap(pipe) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/cucumber/formatter/interceptor.rb', line 60
def self.wrap(pipe)
validate_pipe pipe
case pipe
when :stderr
$stderr = new($stderr)
$stderr
when :stdout
$stdout = new($stdout)
$stdout
end
end
|
Instance Method Details
#buffer_string ⇒ Object
23
24
25
26
27
|
# File 'lib/cucumber/formatter/interceptor.rb', line 23
def buffer_string
@lock.synchronize do
return @buffer.string.dup
end
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
38
39
40
|
# File 'lib/cucumber/formatter/interceptor.rb', line 38
def respond_to_missing?(method, include_private = false)
super || @pipe.respond_to?(method, include_private)
end
|
#unwrap! ⇒ Object
29
30
31
32
|
# File 'lib/cucumber/formatter/interceptor.rb', line 29
def unwrap!
@wrapped = false
@pipe
end
|
#write(str) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/cucumber/formatter/interceptor.rb', line 16
def write(str)
@lock.synchronize do
@buffer << str if @wrapped
return @pipe.write(str)
end
end
|