Module: Domainic::Command::InstanceMethods

Defined in:
lib/domainic/command/instance_methods.rb

Overview

Instance methods that are included in any class that includes Domainic::Command. These methods provide the core execution logic and error handling for commands.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#call(**context) ⇒ Result

Executes the command with the given context, handling any errors

Since:

  • 0.1.0



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

def call(**context)
  call!(**context)
rescue ExecutionError => e
  e.result
end

#call!(**input) ⇒ Result

Executes the command with the given context, raising any errors

Raises:

Since:

  • 0.1.0



33
34
35
36
37
38
39
# File 'lib/domainic/command/instance_methods.rb', line 33

def call!(**input)
  __execute_command!(input)
rescue StandardError => e
  raise e if e.is_a?(ExecutionError)

  raise ExecutionError.new("#{self.class} failed", Result.failure(e, context.to_h))
end

#executevoid

This method is abstract.

Subclass and override #execute to implement command behavior

This method returns an undefined value.

Executes the command's business logic

Raises:

  • (NotImplementedError)

    If the subclass does not implement #execute

Since:

  • 0.1.0



48
49
50
# File 'lib/domainic/command/instance_methods.rb', line 48

def execute
  raise NotImplementedError, "#{self.class} does not implement #execute"
end