Sha256: f0ffa8b52aa10a4e096f7b076cab6806ca9e413d4d4073a599e2947db9e2be6b

Contents?: true

Size: 762 Bytes

Versions: 9

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Service
    module Plugins
      module RaisesOnDoubleResult
        class Middleware < Core::MethodChainMiddleware
          def next(...)
            refute_has_result! || mark_as_has_result!

            chain.next(...)
          end

          private

          ##
          # NOTE: `refute` is `!assert`.
          # https://docs.seattlerb.org/minitest
          #
          def refute_has_result!
            return unless entity.internals.cache.exist?(:has_result)

            raise Errors::DoubleResult.new(service: entity)
          end

          def mark_as_has_result!
            entity.internals.cache.write(:has_result, true)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
convenient_service-0.7.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.6.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.5.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.4.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.3.1 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.3.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.2.1 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.2.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb
convenient_service-0.1.0 lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb