Class: Resol::Service

Inherits:
Object
  • Object
show all
Includes:
Builder, Callbacks, SmartCore::Initializer
Defined in:
lib/resol/service.rb

Defined Under Namespace

Classes: Failure, InvalidCommandImplementation, Result

Class Method Summary collapse

Methods included from Callbacks

included

Methods included from Builder

included

Class Method Details

.call(*args, **kwargs, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/resol/service.rb', line 41

def call(*args, **kwargs, &block)
  command = build(*args, **kwargs)
  result = catch(command) do
    __run_callbacks__(command)
    command.call(&block)
    nil
  end
  return Resol::Success(result.data) unless result.nil?

  error_message = "No success! or fail! called in the #call method in #{command.class}"
  raise InvalidCommandImplementation, error_message
rescue self::Failure => e
  Resol::Failure(e)
end

.call!Object



56
57
58
# File 'lib/resol/service.rb', line 56

def call!(...)
  call(...).value_or { |error| raise error }
end

.inherited(klass) ⇒ Object



36
37
38
39
# File 'lib/resol/service.rb', line 36

def inherited(klass)
  klass.const_set(:Failure, Class.new(klass::Failure))
  super
end