Module: Rddd::Services::ServiceBus

Defined in:
lib/rddd/services/service_bus.rb

Instance Method Summary collapse

Instance Method Details

#execute_service(service_name, attributes = {}) ⇒ Object

Execute the given service.

Parameters:

  • service (Symbol)

    to be executed.

  • attributes (Hash) (defaults to: {})

    to be passed to the service call.

  • optional (Block)

    error callback block.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rddd/services/service_bus.rb', line 44

def execute_service(service_name, attributes = {})
  namespace, service_name = service_name.to_s.split('__') if service_name.to_s.include?('__')

  service = namespace ? \
    build_remote_service(namespace.to_sym, service_name.to_sym, attributes) : \
    build_service(service_name, attributes)

  unless service.valid?
    yield(service.errors) if block_given?
    return
  end

  service.execute
end