Class: Yes::Core::Aggregate::Dsl::CommandDefiner::DslEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/core/aggregate/dsl/command_definer.rb

Overview

DSL evaluator class for command configuration blocks

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_data, guard_evaluator_class, state_updater_class) ⇒ DslEvaluator

Returns a new instance of DslEvaluator.

Parameters:

  • command_data (CommandData)

    The command data to configure

  • guard_evaluator_class (Class)

    The guard evaluator class for this command

  • state_updater_class (Class)

    The state updater class for this command

Since:

  • 0.1.0



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_dataCommandData, Class (readonly)

Returns:

  • (CommandData)

    The command data being configured

  • (Class)

    The guard evaluator class for this command

  • (Class)

    The state updater class for this command

Since:

  • 0.1.0



170
171
172
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 170

def command_data
  @command_data
end

#guard_evaluator_classCommandData, Class (readonly)

Returns:

  • (CommandData)

    The command data being configured

  • (Class)

    The guard evaluator class for this command

  • (Class)

    The state updater class for this command

Since:

  • 0.1.0



170
171
172
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 170

def guard_evaluator_class
  @guard_evaluator_class
end

#state_updater_classCommandData, Class (readonly)

Returns:

  • (CommandData)

    The command data being configured

  • (Class)

    The guard evaluator class for this command

  • (Class)

    The state updater class for this command

Since:

  • 0.1.0



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

Yields:

  • The authorizer block

Yield Returns:

  • (void)

Since:

  • 0.1.0



255
256
257
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 255

def authorize(&block)
  command_data.authorizer_block = block
end

#encrypt(*attribute_names) ⇒ void

This method returns an undefined value.

Declares which payload attributes should be encrypted in the generated event

Examples:

command :update_contact_info do
  payload email: :email, phone: :phone
  encrypt :email, :phone
end

Parameters:

  • attribute_names (Array<Symbol>)

    The names of payload attributes to encrypt

Since:

  • 0.1.0



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

Parameters:

  • name (Symbol)

    The name of the event

Since:

  • 0.1.0



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

Parameters:

  • name (Symbol)

    The name of the guard

  • error_extra (Hash, Proc) (defaults to: {})

    The extra information to be added to the error message payload

Yields:

  • The guard evaluation block

Yield Returns:

  • (Boolean)

    True if the guard passes, false otherwise

Since:

  • 0.1.0



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 }

Parameters:

  • attributes (Hash)

    The attributes for the payload

Since:

  • 0.1.0



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

Parameters:

  • custom (Boolean) (defaults to: false)

    Whether the state should be updated using a custom block

Yields:

  • Block defining how to update the state

Yield Returns:

  • (void)

Since:

  • 0.1.0



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