Sha256: 1a78f6a2cb0f9ee114cdcfb38cc05d235b75e485804b67384ab12e31de5b35a0

Contents?: true

Size: 909 Bytes

Versions: 4

Compression:

Stored size: 909 Bytes

Contents

# COMMAND & HANDLER

```ruby
class RegisterAccountCommand < Commandoes::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

command = RegisterAccountCommand.new identity: 'test@test.test', password: 'Password123123!@#', password_confirmation: 'Password123123!@#'
handler = RegisterAccountHandler.new command
handler.call
```

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
commandoes-0.1.4 examples/command_and_handler.md
commandoes-0.1.3 examples/command_and_handler.md
commandoes-0.1.2 examples/command_and_handler.md
commandoes-0.1.1 examples/command_and_handler.md