Class: Nanoc::CLI::CleaningStream Private

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

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:

  • stream (IO, StringIO)

    The stream to wrap



9
10
11
12
# File 'lib/nanoc/cli/cleaning_stream.rb', line 9

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#<<


49
50
51
52
53
# File 'lib/nanoc/cli/cleaning_stream.rb', line 49

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:



21
22
23
24
25
# File 'lib/nanoc/cli/cleaning_stream.rb', line 21

def add_stream_cleaner(klass)
  unless @stream_cleaners.map(&:class).include?(klass)
    @stream_cleaners << klass.new
  end
end

#closeObject

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#close


107
108
109
# File 'lib/nanoc/cli/cleaning_stream.rb', line 107

def close
  @stream.close
end

#closed?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:

  • (Boolean)

See Also:

  • IO#closed?


112
113
114
# File 'lib/nanoc/cli/cleaning_stream.rb', line 112

def closed?
  @stream.closed?
end

#exist?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:

  • (Boolean)

See Also:

  • File#exist?


117
118
119
# File 'lib/nanoc/cli/cleaning_stream.rb', line 117

def exist?
  @stream.exist?
end

#exists?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:

  • (Boolean)

See Also:

  • File.exists?


122
123
124
# File 'lib/nanoc/cli/cleaning_stream.rb', line 122

def exists?
  @stream.exists?
end

#external_encodingObject

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.sync=


147
148
149
# File 'lib/nanoc/cli/cleaning_stream.rb', line 147

def external_encoding
  @stream.external_encoding
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


66
67
68
69
70
# File 'lib/nanoc/cli/cleaning_stream.rb', line 66

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


61
62
63
# File 'lib/nanoc/cli/cleaning_stream.rb', line 61

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


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

def print(str)
  _nanoc_swallow_broken_pipe_errors_while do
    @stream.print(_nanoc_clean(str))
  end
end

#printf(*args) ⇒ 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#printf


85
86
87
# File 'lib/nanoc/cli/cleaning_stream.rb', line 85

def printf(*args)
  @stream.printf(*args)
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


90
91
92
93
94
# File 'lib/nanoc/cli/cleaning_stream.rb', line 90

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:



35
36
37
# File 'lib/nanoc/cli/cleaning_stream.rb', line 35

def remove_stream_cleaner(klass)
  @stream_cleaners.delete_if { |c| c.instance_of?(klass) }
end

#reopen(*args) ⇒ 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#reopen


102
103
104
# File 'lib/nanoc/cli/cleaning_stream.rb', line 102

def reopen(*args)
  @stream.reopen(*args)
end

#set_encoding(*args) ⇒ 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:

  • ARGF.set_encoding


152
153
154
# File 'lib/nanoc/cli/cleaning_stream.rb', line 152

def set_encoding(*args)
  @stream.set_encoding(*args)
end

#stringObject

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:

  • StringIO#string


97
98
99
# File 'lib/nanoc/cli/cleaning_stream.rb', line 97

def string
  @stream.string
end

#syncObject

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.sync


137
138
139
# File 'lib/nanoc/cli/cleaning_stream.rb', line 137

def sync
  @stream.sync
end

#sync=(arg) ⇒ 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.sync=


142
143
144
# File 'lib/nanoc/cli/cleaning_stream.rb', line 142

def sync=(arg)
  @stream.sync = arg
end

#tellObject

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#tell


73
74
75
# File 'lib/nanoc/cli/cleaning_stream.rb', line 73

def tell
  @stream.tell
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:

  • (Boolean)

See Also:

  • IO#tty?


56
57
58
# File 'lib/nanoc/cli/cleaning_stream.rb', line 56

def tty?
  @_tty_eh ||= @stream.tty? # rubocop:disable Naming/MemoizedInstanceVariableName
end

#winsizeObject

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.winsize


127
128
129
# File 'lib/nanoc/cli/cleaning_stream.rb', line 127

def winsize
  @stream.winsize
end

#winsize=(arg) ⇒ 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.winsize=


132
133
134
# File 'lib/nanoc/cli/cleaning_stream.rb', line 132

def winsize=(arg)
  @stream.winsize = arg
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


42
43
44
45
46
# File 'lib/nanoc/cli/cleaning_stream.rb', line 42

def write(str)
  _nanoc_swallow_broken_pipe_errors_while do
    @stream.write(_nanoc_clean(str))
  end
end