Class: Rcqrs::ConventionCommandHandler
Instance Method Summary
collapse
#executeCommand, #initialize
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
account = repository.load(command.aggregate,command.aggregate_id)
methodname = get_method_name_from_command command
if(command.data.empty?)
account.send(methodname)
else
account.send(methodname, command.data)
end
repository.save(account)
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
|