Class: Cucumber::Formatter::Interceptor::Pipe

Inherits:
Object
  • Object
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



8
9
10
11
12
# File 'lib/cucumber/formatter/interceptor.rb', line 8

def initialize(pipe)
  @pipe = pipe
  @buffer = StringIO.new
  @wrapped = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object



45
46
47
# File 'lib/cucumber/formatter/interceptor.rb', line 45

def method_missing(method, *args, &blk)
  @pipe.send(method, *args, &blk)
end

Instance Attribute Details

#pipeObject (readonly)

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



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cucumber/formatter/interceptor.rb', line 59

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



53
54
55
56
57
# File 'lib/cucumber/formatter/interceptor.rb', line 53

def self.validate_pipe(pipe)
  unless [:stdout, :stderr].include? pipe
    raise ArgumentError, '#wrap only accepts :stderr or :stdout'
  end
end

.wrap(pipe) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cucumber/formatter/interceptor.rb', line 73

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

#bufferObject

Deprecated.

use #buffer_string



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cucumber/formatter/interceptor.rb', line 22

def buffer
  require 'cucumber/deprecate.rb'
  Cucumber.deprecate(
    'Use Cucumber::Formatter::Interceptor::Pipe#buffer_string instead',
    'Cucumber::Formatter::Interceptor::Pipe#buffer',
    '3.99'
  )
  lock.synchronize do
    return @buffer.string.lines
  end
end

#buffer_stringObject



34
35
36
37
38
# File 'lib/cucumber/formatter/interceptor.rb', line 34

def buffer_string
  lock.synchronize do
    return @buffer.string.dup
  end
end

#respond_to?(method, include_private = false) ⇒ Boolean



49
50
51
# File 'lib/cucumber/formatter/interceptor.rb', line 49

def respond_to?(method, include_private = false)
  super || @pipe.respond_to?(method, include_private)
end

#unwrap!Object



40
41
42
43
# File 'lib/cucumber/formatter/interceptor.rb', line 40

def unwrap!
  @wrapped = false
  @pipe
end

#write(str) ⇒ Object



14
15
16
17
18
19
# File 'lib/cucumber/formatter/interceptor.rb', line 14

def write(str)
  lock.synchronize do
    @buffer << str if @wrapped
    return @pipe.write(str)
  end
end