Sha256: bbfd226d0429a01b88cf65fc939ccca50099f35c1b9b51fec90b245b06247347

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Brandish
  module Processor
    # A command processor.  This is designed to act over a base to modify
    # one specific command.  The command name itself is specified on the
    # class, and the class provides logic to only modify command nodes with
    # the same name.
    module Command
      # Ruby hook.
      #
      # @api private
      # @return [void]
      def self.included(base)
        base.include Processor::NameFilter
        base.include Processor::PairFilter
      end

      # Processes the command.  If the node's name doesn't match the name for
      # this class, it passes it on up to {Base#process_command}; otherwise,
      # it passes it over to {#perform}.
      #
      # @param node [Parser::Node::Command]
      # @return [::Object]
      def process_command(node)
        return super unless allowed_names.include?(node.name)
        @node = node
        @name = node.name
        @pairs = node.pairs
        @body = nil
        
        assert_valid_pairs
        perform
      end

      # Performs the command adjustment.  This must be subclassed and
      # overwritten.
      #
      # @abstract
      # @return [::Object]
      def perform
        fail NotImplementedError, "Please implement #{self.class}#perform"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
brandish-0.1.3 lib/brandish/processor/command.rb
brandish-0.1.2 lib/brandish/processor/command.rb
brandish-0.1.1 lib/brandish/processor/command.rb