Class: Rcqrs::ConventionCommandHandler

Inherits:
BaseCommandHandler show all
Defined in:
lib/rcqrs/convention_command_handler.rb

Instance Method Summary collapse

Methods inherited from BaseCommandHandler

#executeCommand, #initialize

Constructor Details

This class inherits a constructor from Rcqrs::BaseCommandHandler

Instance Method Details

#command_name(command) ⇒ Object



27
28
29
# File 'lib/rcqrs/convention_command_handler.rb', line 27

def command_name command
  command.class.name.split("::").last
end

#execute(command) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/rcqrs/convention_command_handler.rb', line 5

def execute command
   = repository.load(command.aggregate,command.aggregate_id)
  methodname = get_method_name_from_command command
  if(command.data.empty?)
    .send(methodname)      
  else
    .send(methodname, command.data)
  end
  repository.save()
end

#get_method_name_from_command(command) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/rcqrs/convention_command_handler.rb', line 16

def get_method_name_from_command command
  words = command_name(command).split(%r{[A-Z]})
  first_letters = command_name(command).scan(%r{[A-Z]})
  result = String.new
  words.shift
  0.upto(words.size-2) do |i|
    result << first_letters[i].downcase + words[i] + "_"  
  end
  result[0..-2]
end