Sha256: 287ee5ae4d2d1433cbd194e37833b2131ee7f76a9f40026ca99837c0ce7a47f9
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: true require "dry/core/constants" require "dry/effects/version" require "dry/effects/container" require "dry/effects/errors" require "dry/effects/instructions/raise" module Dry module Effects include Core::Constants class Error < StandardError; end @effects = Container.new @providers = Container.new class << self attr_reader :effects, :providers # Handle an effect. # If no handler is present in the stack it will either # raise an exception and yield a block if given. # It is not recommended to build effects manually, hence # this method shouldn't be used often. # # @example getting current user with yield # # require 'dry/effects/effects/reader' # extend Dry::Effects::Constructors # Dry::Effects.yield(Read(:current_user)) # # @param [Effect] effect # @return [Object] Result value is determined by effect type # @api public def yield(effect) result = ::Fiber.yield(effect) if result.is_a?(Instruction) result.() else result end rescue ::FiberError => e if block_given? yield(effect, e) else raise Errors::UnhandledEffectError, effect end end # Build a handler. # Normally, handlers are built via mixins. # This method is useful for demonstration purposes. # # @example providing current user # # Dry::Effects[:reader, :current_user].(User.new) do # code_using_current_user.() # end # # @param [Array<Object>] args Handler parameters # @return [Handler] # @api public def [](*args) Handler.new(*args) end end end end require "dry/effects/all" require "dry/effects/extensions"
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dry-effects-0.2.0 | lib/dry/effects.rb |