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.



39
40
41
# File 'lib/dbf/cli.rb', line 39

def initialize(io)
  @io = io
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

:nodoc:



52
53
54
# File 'lib/dbf/cli.rb', line 52

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

Instance Method Details

#<<(data) ⇒ Object



43
44
45
46
# File 'lib/dbf/cli.rb', line 43

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

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

:nodoc:

Returns:

  • (Boolean)


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

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

#write(*data) ⇒ Object



48
49
50
# File 'lib/dbf/cli.rb', line 48

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