Class: Blurrily::CommandProcessor
- Inherits:
-
Object
- Object
- Blurrily::CommandProcessor
- Defined in:
- lib/blurrily/command_processor.rb
Constant Summary collapse
- ProtocolError =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(map_group) ⇒ CommandProcessor
constructor
A new instance of CommandProcessor.
- #process_command(line) ⇒ Object
Constructor Details
#initialize(map_group) ⇒ CommandProcessor
Returns a new instance of CommandProcessor.
8 9 10 |
# File 'lib/blurrily/command_processor.rb', line 8 def initialize(map_group) @map_group = map_group end |
Instance Method Details
#process_command(line) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/blurrily/command_processor.rb', line 12 def process_command(line) command, map_name, *args = line.split(/\t/) raise ProtocolError, 'Unknown command' unless COMMANDS.include? command raise ProtocolError, 'Invalid database name' unless map_name =~ /^[a-z_]+$/ result = send("on_#{command}", map_name, *args) ['OK', *result].compact.join("\t") rescue ArgumentError, ProtocolError => e ['ERROR', e.].join("\t") end |