Module: Foobara::Domain::DomainModuleExtension

Includes:
Concern, Manifestable
Defined in:
foobara-0.0.110/projects/domain/src/domain_module_extension.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Class Method Details

._copy_constants(old_mod, new_class) ⇒ Object

TODO: rename this



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'foobara-0.0.110/projects/domain/src/domain_module_extension.rb', line 20

def _copy_constants(old_mod, new_class)
  old_mod.constants.each do |const_name|
    value = old_mod.const_get(const_name)
    if new_class.const_defined?(const_name)
      # TODO: figure out how to test this path. Seems to occur when models are nested and loaded
      # remotely in a certain order
      # :nocov:
      to_replace = new_class.const_get(const_name)
      if to_replace != value
        new_class.send(:remove_const, const_name)
        new_class.const_set(const_name, value)
      end
      # :nocov:
    else
      new_class.const_set(const_name, value)
    end
  end

  lower_case_constants = old_mod.instance_variable_get(:@foobara_lowercase_constants)

  if lower_case_constants && !lower_case_constants.empty?
    lower_case_constants&.each do |lower_case_constant|
      new_class.singleton_class.define_method lower_case_constant do
        old_mod.send(lower_case_constant)
      end
    end

    new_lowercase_constants = new_class.instance_variable_get(:@foobara_lowercase_constants) || []
    new_lowercase_constants += lower_case_constants

    new_class.instance_variable_set(:@foobara_lowercase_constants, new_lowercase_constants)
  end
end

.allObject



15
16
17
# File 'foobara-0.0.110/projects/domain/src/domain_module_extension.rb', line 15

def all
  @all ||= []
end