Class: SPNet::CommandInPort
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spnet/ports/command_in_port.rb
Overview
Provides a means to list and execute commands in a Block object.
Constant Summary collapse
- ARG_SPECS =
Define arg specs to use in processing hashed arguments during #initialize.
{ :command_map => arg_spec_hash(:reqd => true, :type => Proc, :validator => ->(a){a.arity == 1}), }
Instance Attribute Summary
Attributes inherited from InPort
Instance Method Summary collapse
-
#exec_command(command, data) ⇒ Object
Execute a command with the given data (nil by default).
-
#initialize(hashed_args) ⇒ CommandInPort
constructor
A new instance of CommandInPort.
-
#list_commands ⇒ Object
List the commands that are available.
Methods inherited from InPort
#clear_link, #linked?, #set_link
Constructor Details
#initialize(hashed_args) ⇒ CommandInPort
A new instance of CommandInPort.
18 19 20 21 |
# File 'lib/spnet/ports/command_in_port.rb', line 18 def initialize hashed_args hash_make hashed_args, CommandInPort::ARG_SPECS super(:matching_class => CommandOutPort) end |
Instance Method Details
#exec_command(command, data) ⇒ Object
Execute a command with the given data (nil by default).
29 30 31 32 |
# File 'lib/spnet/ports/command_in_port.rb', line 29 def exec_command command, data raise "Command #{command} not found in command list" unless @command_map.has_key?(command) @command_map[command].call data end |
#list_commands ⇒ Object
List the commands that are available.
24 25 26 |
# File 'lib/spnet/ports/command_in_port.rb', line 24 def list_commands @command_map.keys end |