Class: DBF::CLI::TerminalFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/dbf/cli.rb

Overview

Wraps an IO so text written to an interactive terminal is stripped of control bytes. Redirected or piped output is never wrapped, so exported data is passed through unaltered.

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ TerminalFilter

Returns a new instance of TerminalFilter.



41
42
43
# File 'lib/dbf/cli.rb', line 41

def initialize(io)
  @io = io
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

:nodoc:



54
55
56
# File 'lib/dbf/cli.rb', line 54

def method_missing(name, ...) # :nodoc:
  @io.respond_to?(name) ? @io.send(name, ...) : super
end

Instance Method Details

#<<(data) ⇒ Object



45
46
47
48
# File 'lib/dbf/cli.rb', line 45

def <<(data)
  @io << CLI.sanitize(data, CONTROL_BYTES_KEEPING_NEWLINES)
  self
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


58
59
60
# File 'lib/dbf/cli.rb', line 58

def respond_to_missing?(name, include_private = false) # :nodoc:
  @io.respond_to?(name, include_private) || super
end

#write(*data) ⇒ Object



50
51
52
# File 'lib/dbf/cli.rb', line 50

def write(*data)
  @io.write(*data.map { |datum| CLI.sanitize(datum, CONTROL_BYTES_KEEPING_NEWLINES) })
end