This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commands
Andreas Reischuck edited this page Mar 23, 2014
·
5 revisions
Commands represent a request to change the application state.
They are created from the Rails controller and sent to the domain server. The Domain server validates them and creates an events, if they are valid.
In Ruby a command is located in app/commands
as a class that includes the ActiveEvent::Command
module.
You can use the attributes
method to declare the functions and serializations.
attributes :id, :attr1, :attr2, :attr3, ...
To enable the use of form helpers from Rails, you can include ActiveModel::Model
before the ActiveEvent::Command
. To automatically generate form_for
urls and names, you will have to override persisted?
and self.model_name
methods. Take a look at the scaffolding.
A complete example:
class RegisterUserCommand
include ActiveModel::Model
include ActiveEvent::Command
attributes :id, :email, :salt, :encrypted_password
attr_accessor :password, :password_confirmation
# add your hooks to encrypt the password
end