Class: Nanoc::CLI::CleaningStream Private

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

API:

  • private

IO proxy methods collapse

Instance Method Summary collapse

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.

Parameters:

  • The stream to wrap

API:

  • private



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.

See Also:

  • IO#<<

API:

  • private



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.

Parameters:

  • The class of the stream cleaner to add

API:

  • private



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

#flushObject

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.

See Also:

  • IO#flush

API:

  • private



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

#isattyObject

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.

See Also:

  • IO#isatty

API:

  • private



78
79
80
# File 'lib/nanoc/cli/cleaning_stream.rb', line 78

def isatty
  tty?
end

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.

See Also:

  • IO#print

API:

  • private



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.

See Also:

  • IO#puts

API:

  • private



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.

Parameters:

  • The class of the stream cleaner to add

API:

  • private



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.

Returns:

See Also:

  • IO#tty?

API:

  • private



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.

See Also:

  • IO#write

API:

  • private



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