Class: ConvenientService::Utils::Module::GetNamespace

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/module/get_namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(mod) ⇒ void

Parameters:



43
44
45
# File 'lib/convenient_service/utils/module/get_namespace.rb', line 43

def initialize(mod)
  @mod = mod
end

Instance Attribute Details

#modObject (readonly)

Returns the value of attribute mod.



37
38
39
# File 'lib/convenient_service/utils/module/get_namespace.rb', line 37

def mod
  @mod
end

Instance Method Details

#callModule, ...



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/convenient_service/utils/module/get_namespace.rb', line 51

def call
  return unless mod.name
  return unless mod.name.include?("::")

  namespace_name = mod.name.split("::")[0..-2].join("::")

  begin
    ::Object.const_get(namespace_name, false)
  rescue ::NameError
    ::ConvenientService.raise Exceptions::NestingUnderAnonymousNamespace.new(mod: mod, namespace: namespace_name)
  end
end