Class: RemoteRuby::StreamPrefixer
- Inherits:
-
Object
- Object
- RemoteRuby::StreamPrefixer
- Defined in:
- lib/remote_ruby/stream_prefixer.rb
Overview
Decorates the source stream prepending a prefix to each line read from the source
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(stream, prefix) ⇒ StreamPrefixer
constructor
A new instance of StreamPrefixer.
- #write(data) ⇒ Object
Constructor Details
#initialize(stream, prefix) ⇒ StreamPrefixer
Returns a new instance of StreamPrefixer.
9 10 11 12 13 |
# File 'lib/remote_ruby/stream_prefixer.rb', line 9 def initialize(stream, prefix) @stream = stream @prefix = prefix @prefix_needed = true end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/remote_ruby/stream_prefixer.rb', line 7 def prefix @prefix end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
7 8 9 |
# File 'lib/remote_ruby/stream_prefixer.rb', line 7 def stream @stream end |
Instance Method Details
#write(data) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/remote_ruby/stream_prefixer.rb', line 15 def write(data) res = 0 data.each_line do |line| res += stream.write(prefix) if @prefix_needed @prefix_needed = line.end_with?("\n") res += stream.write(line) end res end |