Class: Nanoc::CLI::CleaningStream Private
- Inherits:
-
Object
- Object
- Nanoc::CLI::CleaningStream
- Extended by:
- Forwardable
- Defined in:
- lib/nanoc/cli/cleaning_stream.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An output stream that passes output through stream cleaners. This can be used to strip ANSI color sequences, for instance.
IO proxy methods collapse
- #<<(str) ⇒ Object private
- #flush ⇒ Object private
- #isatty ⇒ Object private
- #print(str) ⇒ Object private
- #puts(*str) ⇒ Object private
- #tty? ⇒ Boolean private
- #write(str) ⇒ Object private
Instance Method Summary collapse
-
#add_stream_cleaner(klass) ⇒ void
private
Adds a stream cleaner for the given class to this cleaning stream.
-
#initialize(stream) ⇒ CleaningStream
constructor
private
A new instance of CleaningStream.
-
#remove_stream_cleaner(klass) ⇒ void
private
Removes the stream cleaner for the given class from this cleaning stream.
Constructor Details
#initialize(stream) ⇒ CleaningStream
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CleaningStream.
26 27 28 29 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 26 def initialize(stream) @stream = stream @stream_cleaners = [] end |
Instance Method Details
#<<(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 69 70 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 66 def <<(str) _nanoc_swallow_broken_pipe_errors_while do @stream << _nanoc_clean(str) end end |
#add_stream_cleaner(klass) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Adds a stream cleaner for the given class to this cleaning stream. If the cleaning stream already has the given stream cleaner, nothing happens.
38 39 40 41 42 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 38 def add_stream_cleaner(klass) unless @stream_cleaners.map(&:class).include?(klass) @stream_cleaners << klass.new end end |
#flush ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 83 def flush _nanoc_swallow_broken_pipe_errors_while do @stream.flush end end |
#isatty ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 78 def isatty tty? end |
#print(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 90 def print(str) _nanoc_swallow_broken_pipe_errors_while do @stream.print(_nanoc_clean(str)) end end |
#puts(*str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 100 101 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 97 def puts(*str) _nanoc_swallow_broken_pipe_errors_while do @stream.puts(*str.map { |ss| _nanoc_clean(ss) }) end end |
#remove_stream_cleaner(klass) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Removes the stream cleaner for the given class from this cleaning stream. If the cleaning stream does not have the given stream cleaner, nothing happens.
52 53 54 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 52 def remove_stream_cleaner(klass) @stream_cleaners.delete_if { |c| c.instance_of?(klass) } end |
#tty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 73 def tty? @_tty_eh ||= @stream.tty? # rubocop:disable Naming/MemoizedInstanceVariableName end |
#write(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 62 63 |
# File 'lib/nanoc/cli/cleaning_stream.rb', line 59 def write(str) _nanoc_swallow_broken_pipe_errors_while do @stream.write(_nanoc_clean(str)) end end |