Class: RSpec::Risky::Probe::OutputProbe::RecordingIO
- Inherits:
-
Object
- Object
- RSpec::Risky::Probe::OutputProbe::RecordingIO
show all
- Defined in:
- lib/rspec/risky/probe/recording_io.rb
Instance Method Summary
collapse
Constructor Details
#initialize(stream_name, io, report, passthrough:) ⇒ RecordingIO
Returns a new instance of RecordingIO.
8
9
10
11
12
13
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 8
def initialize(stream_name, io, report, passthrough:)
@stream_name = stream_name
@io = io
@report = report
@passthrough = passthrough
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
76
77
78
79
80
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 76
def method_missing(method_name, *args, &block)
return super unless @io.respond_to?(method_name)
@io.public_send(method_name, *args, &block)
end
|
Instance Method Details
#<<(data) ⇒ Object
27
28
29
30
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 27
def <<(data)
write(data)
self
end
|
#clone ⇒ Object
68
69
70
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 68
def clone
@io.clone
end
|
#dup ⇒ Object
72
73
74
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 72
def dup
@io.dup
end
|
#flush ⇒ Object
51
52
53
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 51
def flush
@io.flush if @io.respond_to?(:flush)
end
|
#print(*objects) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 38
def print(*objects)
data = objects.empty? ? $_.to_s : objects.map(&:to_s).join($,)
data = "#{data}#{$OUTPUT_RECORD_SEPARATOR}" if $OUTPUT_RECORD_SEPARATOR
record(data, caller_locations(1))
@io.print(*objects) if @passthrough
end
|
#printf(format_string, *arguments) ⇒ Object
45
46
47
48
49
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 45
def printf(format_string, *arguments)
data = format(format_string, *arguments)
record(data, caller_locations(1))
@io.printf(format_string, *arguments) if @passthrough
end
|
#puts(*objects) ⇒ Object
32
33
34
35
36
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 32
def puts(*objects)
data = objects.empty? ? "\n" : objects.map { |object| "#{format_puts_object(object)}\n" }.join
record(data, caller_locations(1))
@io.puts(*objects) if @passthrough
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
82
83
84
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 82
def respond_to_missing?(method_name, include_private = false)
@io.respond_to?(method_name, include_private) || super
end
|
#sync ⇒ Object
55
56
57
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 55
def sync
@io.sync if @io.respond_to?(:sync)
end
|
#sync=(value) ⇒ Object
59
60
61
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 59
def sync=(value)
@io.sync = value if @io.respond_to?(:sync=)
end
|
#tty? ⇒ Boolean
Also known as:
isatty
63
64
65
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 63
def tty?
@io.tty? if @io.respond_to?(:tty?)
end
|
#write(data) ⇒ Object
15
16
17
18
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 15
def write(data)
record(data, caller_locations(1))
@io.write(data) if @passthrough
end
|
#write_nonblock(data, *args) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/rspec/risky/probe/recording_io.rb', line 20
def write_nonblock(data, *args)
record(data, caller_locations(1))
return data.bytesize unless @passthrough
@io.write_nonblock(data, *args)
end
|