class CLIntegracon::LazyStringProxy

A LazyStringProxy returns a LazyString for each call, which delegates the call as soon as the result is needed to the underlying formatter.

Attributes

formatter[R]

@return [Formatter]

the formatter used to build the string

Public Class Methods

new(formatter) click to toggle source

Initialize a LazyStringProxy, which returns for each call to an underlying formatter a new LazyString, whose to_s method will evaluate to the result of the original call delegated to the formatter.

@param [Formatter] formatter

the formatter
# File lib/CLIntegracon/formatter.rb, line 50
def initialize(formatter)
  @formatter = formatter
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source

Remember the call delegated to formatter in a closure on an anonymous object, defined as method :to_s.

@return [#to_s]

# File lib/CLIntegracon/formatter.rb, line 59
def method_missing(method, *args, &block)
  return LazyString.new do
    @formatter.send(method, *args, &block)
  end
end
respond_to?(method) click to toggle source

Respond to all methods, which are beginning with `describe_` to which the formatter also responds.

@return [Bool]

Calls superclass method
# File lib/CLIntegracon/formatter.rb, line 70
def respond_to?(method)
  if /^describe_/.match(method.to_s) && @formatter.respond_to?(method)
    true
  else
    super
  end
end