module Dry::Effects::Provider::ClassInterface
Attributes
effects[R]
Public Class Methods
extended(base)
click to toggle source
# File lib/dry/effects/provider/class_interface.rb, line 10 def self.extended(base) base.instance_exec do defines :type @mutex = ::Mutex.new @effects = ::Hash.new do |es, type| @mutex.synchronize do es.fetch(type) do es[type] = Class.new(Provider).tap do |provider| provider.type type end end end end end end
Public Instance Methods
[](type)
click to toggle source
# File lib/dry/effects/provider/class_interface.rb, line 31 def [](type) if self < Provider Provider.effects.fetch(type) do Provider.effects[type] = ::Class.new(self).tap do |subclass| subclass.type type end end else @effects[type] end end
handle_method(*, as: Undefined, **)
click to toggle source
# File lib/dry/effects/provider/class_interface.rb, line 56 def handle_method(*, as: Undefined, **) Undefined.default(as) { :"with_#{type}" } end
mixin(*as, **kw)
click to toggle source
# File lib/dry/effects/provider/class_interface.rb, line 43 def mixin(*as, **kw) handle_method = handle_method(*as, **kw) provider = new(*as, **kw).freeze frame = Frame.new(provider) ::Module.new do define_method(handle_method) do |*args, &block| frame.(*args, &block) end end end