class Pastel::Delegator
Wrapes the {DecoratorChain} to allow for easy resolution of string coloring.
@api private
Attributes
base[R]
resolver[R]
Public Class Methods
for(resolver, base)
click to toggle source
@api public
# File lib/pastel/delegator.rb, line 39 def self.for(resolver, base) new(resolver, base) end
new(resolver, base)
click to toggle source
Create Delegator
Used internally by {Pastel}
@param [ColorResolver] resolver
@param [DecoratorChain] base
@api private
# File lib/pastel/delegator.rb, line 33 def initialize(resolver, base) @resolver = resolver @base = base end
Public Instance Methods
inspect()
click to toggle source
Object string representation
@return [String]
@api
# File lib/pastel/delegator.rb, line 50 def inspect "#<Pastel @styles=#{base.map(&:to_s)}>" end
Also aliased as: to_s
Protected Instance Methods
evaluate_block(&block)
click to toggle source
Evaluate color block
@api private
# File lib/pastel/delegator.rb, line 87 def evaluate_block(&block) delegator = self.class.new(resolver, DecoratorChain.empty) delegator.instance_eval(&block) end
method_missing(method_name, *args, &block)
click to toggle source
# File lib/pastel/delegator.rb, line 68 def method_missing(method_name, *args, &block) new_base = base.add(method_name) delegator = wrap(new_base) if args.empty? && !(method_name.to_sym == :detach) delegator else string = args.join string << evaluate_block(&block) if block_given? resolver.resolve(new_base, string) end end
respond_to_missing?(name, include_all = false)
click to toggle source
Calls superclass method
# File lib/pastel/delegator.rb, line 80 def respond_to_missing?(name, include_all = false) resolver.color.respond_to?(name, include_all) || valid?(name) || super end
wrap(base)
click to toggle source
Wrap colors
@api private
# File lib/pastel/delegator.rb, line 64 def wrap(base) self.class.new(resolver, base) end