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



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

def initialize(stream)
  @stream = stream
  @stream_cleaners = []
end

Instance Method Details

#<<(s) ⇒ 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#<<


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

def <<(s)
  _nanoc_swallow_broken_pipe_errors_while do
    @stream.<<(_nanoc_clean(s))
  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:



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

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


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

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?


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

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?


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

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=


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

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


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

def flush
  _nanoc_swallow_broken_pipe_errors_while do
    @stream.flush
  end
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


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

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

#puts(*s) ⇒ 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


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

def puts(*s)
  _nanoc_swallow_broken_pipe_errors_while do
    @stream.puts(*s.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:



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

def remove_stream_cleaner(klass)
  @stream_cleaners.delete_if { |c| c.class == klass }
end

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


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

def reopen(*a)
  @stream.reopen(*a)
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


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

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


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

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


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

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=


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

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


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

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?


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

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


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

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=


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

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

#write(s) ⇒ 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


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

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