Sha256: 473f6d81e14fb485ceca87c71cc54a64110829ece7d641f54fc79359f337f4d3
Contents?: true
Size: 1.41 KB
Versions: 2
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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-effects-0.3.0 | lib/dry/effects/providers/reader.rb |
dry-effects-0.2.0 | lib/dry/effects/providers/reader.rb |