Sha256: 56c299b6c742f58714b3ef45034b6ffa3d624ba4ec01ada67c866360cf4323d1
Contents?: true
Size: 1.41 KB
Versions: 4
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true require 'dry/effects/provider' module Dry module Effects module Providers class Reader < Provider[:reader] def self.handle_method(scope, as: Undefined, **) Undefined.default(as) { :"with_#{scope}" } end Any = ::Object.new.tap { |any| def any.===(_) true end }.freeze include ::Dry::Equalizer(:scope, :state, inspect: false) attr_reader :state param :scope option :type, as: :state_type, default: -> { Any } def initialize(*, **) super @state = Undefined end def read state end # Yield the block with the handler installed # # @api private def call(state) case state when state_type @state = state yield else raise Errors::InvalidValueError.new(state, scope) end end # @return [String] # @api public def represent if Undefined.equal?(state) "#{type}[#{scope} not set]" else "#{type}[#{scope} set]" end end # @return [Boolean] # @api public def provide?(effect) effect.type.equal?(:state) && effect.name.equal?(:read) && scope.equal?(effect.scope) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems