Module: Dry::Effects::Provider::ClassInterface Private

Includes:
Core::ClassAttributes
Included in:
Dry::Effects::Provider
Defined in:
lib/dry/effects/provider/class_interface.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#effectsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/dry/effects/provider/class_interface.rb', line 26

def effects
  @effects
end

Class Method Details

.extended(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dry/effects/provider/class_interface.rb', line 7

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

Instance Method Details

#[](type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dry/effects/provider/class_interface.rb', line 28

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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/dry/effects/provider/class_interface.rb', line 53

def handle_method(*, as: Undefined, **)
  Undefined.default(as) { :"with_#{type}" }
end

#mixin(*as, **kw) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dry/effects/provider/class_interface.rb', line 40

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