Sha256: e201f2a71969bfc71ed25e5f7deee592a3b61ed1aba02a7c5aac97d9a037724e
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
```ruby class RegisterAccountCommand < Commandos::IAmACommand values do string :identity string :password string :password_confirmation end validates_presence_of \ :identity, :password, :password_confirmation validate \ :password_confirmation! private def password_confirmation! unless password_confirmation == password errors.add :password_confirmation, "doesn't match password" end end end class RegisterAccountHandler def initialize(command) @command = command end def call return command unless command.valid? account_to_register = Account.new command.attributes account_to_register.save! end end class AccountCommandRegistry < IAmACommandRegistry def initialize register RegisterAccountCommand, handler: RegisterAccountHandler end end class AccountService def initialize @dispatcher = Commandos::Dispatcher.new registry: AccountCommandRegistry.new end def register_account(safe_params) dispatcher.dispatch RegisterAccountCommand.new safe_params end private attr_reader :dispatcher end ```
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
commandos-0.1.5 | examples/command_registry_and_dispatcher.md |
commandos-0.1.4 | examples/command_registry_and_dispatcher.md |