Sha256: 641c9907832ee05cf7d1586df63e517f3ab2ae2996551278f8b4233001dda82f

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

require 'aldous/logging_wrapper'
require 'aldous/service/result/base'
require 'aldous/service/result/failure'

module Aldous
  class Service
    class Wrapper
      attr :service

      def initialize(service)
        @service = service
      end

      def raisable_error
        service.raisable_error
      end

      def default_result_data
        service.default_result_data
      end

      def perform!
        result = service.perform

        unless result.kind_of?(::Aldous::Service::Result::Base)
          raise "Return value of #perform must be a type of #{::Aldous::Service::Result::Base}"
        end

        build_result_with_default_options(result)
      rescue => e
        raise raisable_error.new(e.message)
      end

      def perform
        perform!
      rescue => e
        Aldous::LoggingWrapper.log(e.cause || e)
        Aldous::Service::Result::Failure.new(default_result_data.merge(errors: [e]))
      end

      private

      def build_result_with_default_options(result)
        result.class.new(default_result_data.merge(result._data))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aldous-1.1.3 lib/aldous/service/wrapper.rb
aldous-1.1.2 lib/aldous/service/wrapper.rb
aldous-1.0.1 lib/aldous/service/wrapper.rb
aldous-1.0.0 lib/aldous/service/wrapper.rb