Module: Brandish::Processor::Command

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Ruby hook.



15
16
17
18
# File 'lib/brandish/processor/command.rb', line 15

def self.included(base)
  base.include Processor::NameFilter
  base.include Processor::PairFilter
end

Instance Method Details

#perform::Object

This method is abstract.

Performs the command adjustment. This must be subclassed and overwritten.

Returns:

  • (::Object)


42
43
44
# File 'lib/brandish/processor/command.rb', line 42

def perform
  fail NotImplementedError, "Please implement #{self.class}#perform"
end

#process_command(node) ⇒ ::Object

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.

Parameters:

Returns:

  • (::Object)


26
27
28
29
30
31
32
33
34
35
# File 'lib/brandish/processor/command.rb', line 26

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