Module: Plumb::TypeRegistry

Included in:
Types
Defined in:
lib/plumb/type_registry.rb

Instance Method Summary collapse

Instance Method Details

#const_added(const_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/plumb/type_registry.rb', line 5

def const_added(const_name)
  obj = const_get(const_name)
  case obj
  when Module
    obj.extend TypeRegistry
  when Composable
    anc = [name, const_name].join('::')
    obj.freeze.name.set(anc)
  end
end

#included(host) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/plumb/type_registry.rb', line 16

def included(host)
  host.extend TypeRegistry
  constants(false).each do |const_name|
    const = const_get(const_name)

    anc = [host.name, const_name].join('::')
    case const
    when Module
      next if const.is_a?(Class)

      child_mod = Module.new
      child_mod.define_singleton_method(:name) do
        anc
      end
      child_mod.send(:include, const)
      host.const_set(const_name, child_mod)
    when Composable
      type = const.dup
      type.freeze.name.set(anc)
      host.const_set(const_name, type)
    end
  end
end