Class: Yes::Core::Aggregate::Dsl::CommandDefiner::DslEvaluator
- Inherits:
-
Object
- Object
- Yes::Core::Aggregate::Dsl::CommandDefiner::DslEvaluator
- Defined in:
- lib/yes/core/aggregate/dsl/command_definer.rb
Overview
DSL evaluator class for command configuration blocks
Instance Attribute Summary collapse
- #command_data ⇒ CommandData, Class readonly
- #guard_evaluator_class ⇒ CommandData, Class readonly
- #state_updater_class ⇒ CommandData, Class readonly
Instance Method Summary collapse
-
#authorize { ... } ⇒ void
Overwrites the authorizer for the command.
-
#encrypt(*attribute_names) ⇒ void
Declares which payload attributes should be encrypted in the generated event.
-
#event(name) ⇒ void
Defines the event name for the command.
-
#guard(name, error_extra: {}) { ... } ⇒ void
Defines a guard for the command.
-
#initialize(command_data, guard_evaluator_class, state_updater_class) ⇒ DslEvaluator
constructor
A new instance of DslEvaluator.
-
#payload(attributes) ⇒ void
Defines the payload for the command Supports inline encryption declaration: payload email: { type: :email, encrypt: true }.
-
#update_state(custom: false) { ... } ⇒ void
Defines how the state should be updated.
Constructor Details
#initialize(command_data, guard_evaluator_class, state_updater_class) ⇒ DslEvaluator
Returns a new instance of DslEvaluator.
175 176 177 178 179 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 175 def initialize(command_data, guard_evaluator_class, state_updater_class) @command_data = command_data @guard_evaluator_class = guard_evaluator_class @state_updater_class = state_updater_class end |
Instance Attribute Details
#command_data ⇒ CommandData, Class (readonly)
170 171 172 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 170 def command_data @command_data end |
#guard_evaluator_class ⇒ CommandData, Class (readonly)
170 171 172 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 170 def guard_evaluator_class @guard_evaluator_class end |
#state_updater_class ⇒ CommandData, Class (readonly)
170 171 172 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 170 def state_updater_class @state_updater_class end |
Instance Method Details
#authorize { ... } ⇒ void
This method returns an undefined value.
Overwrites the authorizer for the command
255 256 257 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 255 def (&block) command_data. = block end |
#encrypt(*attribute_names) ⇒ void
This method returns an undefined value.
Declares which payload attributes should be encrypted in the generated event
227 228 229 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 227 def encrypt(*attribute_names) command_data.encrypted_attributes.concat(attribute_names) end |
#event(name) ⇒ void
This method returns an undefined value.
Defines the event name for the command
246 247 248 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 246 def event(name) command_data.event_name = name end |
#guard(name, error_extra: {}) { ... } ⇒ void
This method returns an undefined value.
Defines a guard for the command
188 189 190 191 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 188 def guard(name, error_extra: {}, &) command_data.add_guard(name) guard_evaluator_class.guard(name, error_extra:, &) end |
#payload(attributes) ⇒ void
This method returns an undefined value.
Defines the payload for the command Supports inline encryption declaration: payload email: { type: :email, encrypt: true }
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 198 def payload(attributes) normalized = attributes.transform_values do |value| case value when Hash # Extract encrypt flag if present, pass everything else through value.except(:encrypt) else # Handle simple syntax: :email or :string value end end # Collect encrypted attributes attributes.each do |key, value| command_data.encrypted_attributes << key if value.is_a?(Hash) && value[:encrypt] end command_data.payload_attributes = normalized end |
#update_state(custom: false) { ... } ⇒ void
This method returns an undefined value.
Defines how the state should be updated
237 238 239 240 |
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 237 def update_state(custom: false, &block) command_data.update_state_block = block state_updater_class.update_state(custom:, &block) end |