class Pastel::Delegator
Wrapes the {DecoratorChain} to allow for easy resolution of string coloring.
@api private
Attributes
Public Class Methods
Source
# File lib/pastel/delegator.rb, line 38 def initialize(resolver, chain) @resolver = resolver @chain = chain end
Create Delegator
Used internally by {Pastel}
@param [ColorResolver] resolver
@param [DecoratorChain] chain
@api private
Source
# File lib/pastel/delegator.rb, line 25 def self.wrap(resolver, chain = DecoratorChain.empty) new(resolver, chain) end
Wrap resolver and chain
@api public
Public Instance Methods
Source
# File lib/pastel/delegator.rb, line 57 def ==(other) other.is_a?(self.class) && chain == other.chain end
Compare delegated objects for equivalence of attributes
@return [Boolean]
@api public
Source
# File lib/pastel/delegator.rb, line 48 def eql?(other) instance_of?(other.class) && chain.eql?(other.chain) end
Compare delegated objects for equality of attributes
@return [Boolean]
@api public
Source
# File lib/pastel/delegator.rb, line 76 def hash [self.class, chain].hash end
Hash for this instance and its attributes
@return [Numeric]
@api public
Source
# File lib/pastel/delegator.rb, line 66 def inspect "#<Pastel styles=#{chain.map(&:to_s)}>" end
Object string representation
@return [String]
@api
Also aliased as: to_s
Protected Instance Methods
Source
# File lib/pastel/delegator.rb, line 112 def evaluate_block(&block) delegator = self.class.wrap(resolver) delegator.instance_eval(&block) end
Evaluate color block
@api private
Source
# 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
Handles color method calls
@api private
Source
# 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
Check if color is valid
@api private
Calls superclass method