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. :reek:MissingSafeMethod { exclude: [ validate! ] }

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DomainMessage

#initialize

Methods inherited from DomainObject

json_create, #to_json

Constructor Details

This class inherits a constructor from Aggregates::DomainMessage

Class Attribute Details

.aggregate_typeObject (readonly)

Returns the value of attribute aggregate_type.



13
14
15
# File 'lib/aggregates/command.rb', line 13

def aggregate_type
  @aggregate_type
end

Class Method Details

.interacts_with(aggregate_type) ⇒ Object



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

def interacts_with(aggregate_type)
  @aggregate_type = aggregate_type
end

Instance Method Details



26
27
28
# File 'lib/aggregates/command.rb', line 26

def load_related_aggregate(aggregate_repo)
  aggregate_repo.load_aggregate(self.class.aggregate_type, aggregate_id)
end

#validate!Object



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

def validate!
  super
rescue ActiveModel::ValidationError
  raise Aggregates::CommandValidationError, errors.as_json
end