Sha256: de6d192a6329caddc462b08bf23f909b1a2d27f1e5f28e544ca84192caf2fc00

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

module Glimmer
  class CommandHandlerChainLink
    def initialize(command_handler)
      @command_handler = command_handler
    end
    def chain_to(next_chain_link)
      @next_chain_link = next_chain_link
    end
    def handle(parent, command_symbol, *args, &block)
      if (@command_handler.can_handle?(parent, command_symbol, *args, &block))
        Glimmer.logger.debug "#{@command_handler.class.to_s} will handle command: #{command_symbol} with arguments #{args}"
        return @command_handler.do_handle(parent, command_symbol, *args, &block)
      elsif @next_chain_link
        return @next_chain_link.handle(parent, command_symbol, *args, &block)
      else
        # TODO see if we need a better response here (e.g. dev mode error raising vs production mode silent failure)
        Glimmer.logger.error "Command: #{command_symbol} cannot be handled!"
        return nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glimmer-0.4.7 lib/glimmer/command_handler_chain_link.rb