Sha256: 6b616e8726441e349b4f5a1e4b85806261d0501ebcfb01c0bb7467b2f6fd6b84

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require "dry/effects/initializer"
require "dry/effects/provider/class_interface"

module Dry
  module Effects
    # Base class for effect providers
    #
    # @api private
    class Provider
      extend Initializer
      extend ClassInterface

      # yield the block with the handler installed
      #
      # @api private
      def call
        yield
      end

      # Effect-specific representation of the provider
      #
      # @return [String]
      # @api public
      def represent
        type.to_s
      end

      # Effect type
      #
      # @return [Symbol]
      # @api public
      def type
        self.class.type
      end

      # Whether the effect can be handled?
      #
      # @param [Effect] effect
      # @return [Boolean]
      # @api public
      def provide?(effect)
        type.equal?(effect.type)
      end

      # @return [String]
      # @api public
      def inspect
        "#<#{self.class.name} #{represent}>"
      end

      private

      def value_with_options_from_args(args)
        case args.size
        when 2
          args
        when 1
          if args[0].is_a?(::Hash)
            [Undefined, args[0]]
          else
            [args[0], EMPTY_HASH]
          end
        when 0
          [Undefined, EMPTY_HASH]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-effects-0.3.0 lib/dry/effects/provider.rb
dry-effects-0.2.0 lib/dry/effects/provider.rb