Class: Nous::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/nous/command.rb

Defined Under Namespace

Classes: CommandError, Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/nous/command.rb', line 26

def self.call(...)
  command = new(...)
  command.call
rescue => e
  return command.failure(CommandError.new("unexpected: #{e.message}")) if command

  Result.new(success: false, error: e)
end

Instance Method Details

#failure(error, metadata: {}) ⇒ Object



39
40
41
# File 'lib/nous/command.rb', line 39

def failure(error, metadata: {})
  Result.new(success: false, error:, metadata:)
end

#success(payload:, metadata: {}) ⇒ Object



35
36
37
# File 'lib/nous/command.rb', line 35

def success(payload:, metadata: {})
  Result.new(success: true, payload:, metadata:)
end