Sha256: 71937a749b2a71ee5514667e4968cd09f5bffd2a91f4b6257d2b8ac238d91d7e

Contents?: true

Size: 959 Bytes

Versions: 3

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Effects
    module Providers
      class Implicit < Provider[:implicit]
        include ::Dry::Equalizer(:name, :static, :dictionary, inspect: false)

        param :dependency

        param :static, default: -> { EMPTY_HASH }

        attr_reader :dictionary

        def implicit(arg)
          dictionary.fetch(arg.class)
        end

        # Yield the block with the handler installed
        #
        # @api private
        def call(dynamic = EMPTY_HASH)
          if dynamic.empty?
            @dictionary = static
          else
            @dictionary = static.merge(dynamic)
          end

          yield
        end

        # @param [Effect] effect
        # @return [Boolean]
        # @api public
        def provide?(effect)
          super &&
            dependency.equal?(effect.dependency) &&
            dictionary.key?(effect.payload[0].class)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-effects-0.4.1 lib/dry/effects/providers/implicit.rb
dry-effects-0.4.0 lib/dry/effects/providers/implicit.rb
dry-effects-0.3.1 lib/dry/effects/providers/implicit.rb