Module: Dialekt::Util::CoreExtensions::ModuleMixins

Defined in:
lib/dialekt/util/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#dialekt_base_nameObject



11
12
13
14
15
# File 'lib/dialekt/util/core_extensions.rb', line 11

def dialekt_base_name
  @__dialekt_base_name ||= begin # rubocop:disable Naming/MemoizedInstanceVariableName
    name.gsub(%r{\A.+::}, "")
  end
end

#dialekt_enclosing_moduleObject



17
18
19
20
21
# File 'lib/dialekt/util/core_extensions.rb', line 17

def dialekt_enclosing_module
  if %r{\A(?<parent_name>[^:#]+(?:::[^:#]+)*)::[^:]+\z} =~ name && Kernel.const_defined?(parent_name)
    Kernel.const_get(parent_name)
  end
end

#dialekt_inflector(inflector = EMPTY) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dialekt/util/core_extensions.rb', line 67

def dialekt_inflector(inflector = EMPTY)
  if inflector == EMPTY
    dialekt_lookup_inflector
  else
    if const_defined?(INFLECTOR_CONST)
      raise ArgumentError, "#{self.class} #{self} already has an inflector defined"
    end

    const_set(INFLECTOR_CONST, inflector)
  end
end

#dialekt_lookup_inflectorObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dialekt/util/core_extensions.rb', line 51

def dialekt_lookup_inflector
  if const_defined?(INFLECTOR_CONST, true)
    const_get(INFLECTOR_CONST)
  else
    enclosing_module = self.dialekt_enclosing_module

    inflector = if enclosing_module.nil?
      Dry::Inflector.new
    else
      enclosing_module.dialekt_inflector
    end

    const_set(INFLECTOR_CONST, inflector)
  end
end

#dialekt_lookup_type_checkerObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dialekt/util/core_extensions.rb', line 23

def dialekt_lookup_type_checker
  if const_defined?(TYPE_CHECKER_CONST, true)
    const_get(TYPE_CHECKER_CONST)
  else
    enclosing_module = self.dialekt_enclosing_module

    type_checker = if enclosing_module.nil?
      RubyTypeChecker.instance
    else
      enclosing_module.dialekt_type_checker
    end

    const_set(TYPE_CHECKER_CONST, type_checker)
  end
end

#dialekt_type_checker(checker = EMPTY) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dialekt/util/core_extensions.rb', line 39

def dialekt_type_checker(checker = EMPTY)
  if checker == EMPTY
    dialekt_lookup_type_checker
  else
    if const_defined?(TYPE_CHECKER_CONST)
      raise ArgumentError, "#{self.class} #{self} already has a type checker defined"
    end

    const_set(TYPE_CHECKER_CONST, checker)
  end
end