Sha256: 301b9c53f9b10037cc914fae67c4e8a666ffed992d6fdb0c82fa02bfb2f09dc2

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Effects
    module Providers
      class Cmp < Provider[:cmp]
        include ::Dry::Equalizer(:id, :value, inspect: false)

        attr_reader :value

        param :id

        def get = value

        # Yield the block with the handler installed
        #
        # @return [Array(Any, Any)]
        # @api private
        def call(value = Undefined)
          if Undefined.equal?(value)
            @value = false
            first = yield
            @value = true
            [first, yield]
          else
            @value = value
            yield
          end
        end

        # @param [Effect] effect
        # @return [Boolean]
        # @api public
        def provide?(effect) = super && id.equal?(effect.id)

        # @return [String]
        # @api public
        def represent = "cmp[#{id}=#{@value}]"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-effects-0.5.0 lib/dry/effects/providers/cmp.rb