Class: Aggregates::Command

Inherits:
DomainMessage show all
Defined in:
lib/aggregates/command.rb

Overview

Commands are a type of message that define the shape and contract data that is accepted for an attempt at performing a state change on a given aggregate. Essentially, they provide the api for interacting with your domain. Commands should have descriptive names capturing the change they are intended to make to the domain. For instance, ChangeUserEmail or AddComment.

Defined Under Namespace

Classes: Contract

Instance Method Summary collapse

Methods inherited from DomainMessage

json_create, #to_json

Instance Method Details

#validateObject



16
17
18
# File 'lib/aggregates/command.rb', line 16

def validate
  Contract.new.call(attributes).errors.to_h
end

#validate!Object



20
21
22
23
# File 'lib/aggregates/command.rb', line 20

def validate!
  errors = validate
  raise CommandValidationError, errors unless errors.length.zero?
end