Sha256: e342bf1d75963fb6b5f23dd68624d6a260a67923fbfc72264f2b7b2ec5c5791a

Contents?: true

Size: 955 Bytes

Versions: 11

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Service
    module Plugins
      module CanHaveStubbedResult
        class Middleware < Core::MethodChainMiddleware
          ##
          # @param args [Array]
          # @param kwargs [Hash]
          # @param block [Proc]
          # @return [Object] Can be any type.
          #
          def next(*args, **kwargs, &block)
            key_with_arguments = cache.keygen(*args, **kwargs, &block)
            key_without_arguments = cache.keygen

            return cache[key_with_arguments] if cache.exist?(key_with_arguments)
            return cache[key_without_arguments] if cache.exist?(key_without_arguments)

            chain.next(*args, **kwargs, &block)
          end

          private

          ##
          # @return [ConvenientService::Support::Cache]
          #
          def cache
            entity.stubbed_results
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
convenient_service-0.11.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.10.1 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.10.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.9.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.8.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.7.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.6.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.5.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.4.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.3.1 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb
convenient_service-0.3.0 lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb