class Kamaze::Project::Tools::Console::Output

Provide a console output

Console output can be initialized from a “IO“ (“STDOUT“ and/or “STDERR“) a “File“, using “File.open()“, or a “StringIO“.

As a result, console provides a convenient way to suppress or replace standard outputs (keeping them untouched).

Console output uses “cli-ui“ to provide colored formatting.

@see github.com/Shopify/cli-ui @see ruby-doc.org/core-2.1.3/IO.html

Attributes

output[R]

@!method print(s)

Writes the given objects to ios as with IO#print.

Writes the given object(s) to ``ios``.

The stream must be opened for writing.
If the output field separator (``$,``) is not nil,
it will be inserted between each object.
If the output record separator (``$\``) is not nil,
it will be appended to the output.
If no arguments are given, prints ``$_``.
Objects that aren't strings will be converted by calling
their ``to_s`` method.
With no argument, prints the contents of the variable ``$_``.
Returns nil.
@param [String] s
@return [nil]

Public Class Methods

new(to = $stdout) click to toggle source

@param [IO] to

# File lib/kamaze/project/tools/console/output.rb, line 34
def initialize(to = $stdout)
  @output = to
end

Public Instance Methods

flush() click to toggle source

Flushes any buffered data to the underlying operating system

note that this is Ruby internal buffering only; the OS may buffer the data as well

@return [self]

# File lib/kamaze/project/tools/console/output.rb, line 51
def flush
  self.tap do
    output.flush if output.respond_to?(:flush)
  end
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/kamaze/project/tools/console/output.rb, line 57
def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    args = bufferize(*args) if formattable_on?(method.to_sym)

    return output.public_send(method, *args, &block)
  end

  super
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/kamaze/project/tools/console/output.rb, line 67
def respond_to_missing?(method, include_private = false)
  return true if output.respond_to?(method, include_private)

  super(method, include_private)
end
tty?() click to toggle source

Denote is a tty

@return [Boolean]

# File lib/kamaze/project/tools/console/output.rb, line 41
def tty?
  output.respond_to?(:'tty?') ? output.tty? : false
end

Protected Instance Methods

bufferize(*strings) click to toggle source

Bufferize given arguments

@param [Array<String>] strings

@return [Array<Buffer>|Array<String>]

# File lib/kamaze/project/tools/console/output.rb, line 125
def bufferize(*strings)
  strings.to_a.map { |s| Buffer.new(self, s) }
end
formattable_on?(method) click to toggle source

Denote given method is formattable

@param [Symbol] method

# File lib/kamaze/project/tools/console/output.rb, line 116
def formattable_on?(method)
  formattables.include?(method.to_sym)
end
formattables() click to toggle source

Formattable methods

@return [Array<Symbol>]

# File lib/kamaze/project/tools/console/output.rb, line 109
def formattables
  [:puts, :print, :write]
end