Class: Blurrily::CommandProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/blurrily/command_processor.rb

Constant Summary collapse

ProtocolError =
Class.new(StandardError)

Instance Method Summary collapse

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.message].join("\t")
end