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


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

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


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

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?


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

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=


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

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

#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


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

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


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

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.

rubocop:disable Naming/AccessorMethodName

See Also:

  • ARGF.set_encoding


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

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


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

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


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

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=


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

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?
  @cached_is_tty ||= @stream.tty?
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


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

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=


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

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