class Pastel::Delegator
Wrapes the {DecoratorChain} to allow for easy resolution of string coloring.
@api private
Attributes
chain[R]
resolver[R]
Public Class Methods
new(resolver, chain)
click to toggle source
Create Delegator
Used internally by {Pastel}
@param [ColorResolver] resolver
@param [DecoratorChain] chain
@api private
# File lib/pastel/delegator.rb, line 38 def initialize(resolver, chain) @resolver = resolver @chain = chain end
wrap(resolver, chain = DecoratorChain.empty)
click to toggle source
Wrap resolver and chain
@api public
# File lib/pastel/delegator.rb, line 25 def self.wrap(resolver, chain = DecoratorChain.empty) new(resolver, chain) end
Public Instance Methods
==(other)
click to toggle source
Compare delegated objects for equivalence of attributes
@return [Boolean]
@api public
# File lib/pastel/delegator.rb, line 57 def ==(other) other.is_a?(self.class) && chain == other.chain end
eql?(other)
click to toggle source
Compare delegated objects for equality of attributes
@return [Boolean]
@api public
# File lib/pastel/delegator.rb, line 48 def eql?(other) instance_of?(other.class) && chain.eql?(other.chain) end
hash()
click to toggle source
Hash for this instance and its attributes
@return [Numeric]
@api public
# File lib/pastel/delegator.rb, line 76 def hash [self.class, chain].hash end
inspect()
click to toggle source
Object string representation
@return [String]
@api
# File lib/pastel/delegator.rb, line 66 def inspect "#<Pastel styles=#{chain.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 112 def evaluate_block(&block) delegator = self.class.wrap(resolver) delegator.instance_eval(&block) end
method_missing(method_name, *args, &block)
click to toggle source
Handles color method calls
@api private
# File lib/pastel/delegator.rb, line 89 def method_missing(method_name, *args, &block) new_chain = chain.add(method_name) delegator = self.class.wrap(resolver, new_chain) if args.empty? && method_name.to_sym != :detach delegator else strings = args.dup strings << evaluate_block(&block) if block_given? resolver.resolve(new_chain, strings.join) end end
respond_to_missing?(name, include_all = false)
click to toggle source
Check if color is valid
@api private
Calls superclass method
# File lib/pastel/delegator.rb, line 104 def respond_to_missing?(name, include_all = false) resolver.color.respond_to?(name, include_all) || resolver.color.valid?(name) || super end