Class: ROM::AutoRegistrationStrategies::CustomNamespace Private

Inherits:
Base
  • Object
show all
Defined in:
lib/rom/setup/auto_registration_strategies/custom_namespace.rb

Overview

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

Custom namespace strategy loads components and assumes they are defined within the provided namespace

Constant Summary

Constants inherited from Base

Base::EXTENSION_REGEX, Base::PathnameType

Instance Attribute Summary collapse

Attributes inherited from Base

#file

Instance Method Summary collapse

Methods included from Initializer

extended

Instance Attribute Details

#directoryPathname (readonly)

Returns The path to dir with components.

Returns:

  • (Pathname)

    The path to dir with components



16
# File 'lib/rom/setup/auto_registration_strategies/custom_namespace.rb', line 16

option :directory, type: PathnameType

#namespaceString (readonly)

Returns Name of a namespace.

Returns:

  • (String)

    Name of a namespace



20
# File 'lib/rom/setup/auto_registration_strategies/custom_namespace.rb', line 20

option :namespace, type: Types::Strict::String

Instance Method Details

#callObject

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.

Loads components

Raises:

  • (NameError)


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
# File 'lib/rom/setup/auto_registration_strategies/custom_namespace.rb', line 25

def call
  parts = path_arr.map { |part| Inflector.camelize(part) }
  potential = parts.map.with_index do |_, i|
    parts[(i - parts.size)..parts.size]
  end
  attempted = []

  potential.map do |path|
    const_fragment = path.join("::")

    constant = "#{namespace}::#{const_fragment}"

    return constant if ns_const.const_defined?(const_fragment)

    attempted << constant
  end

  # If we have reached this point, its means constant is not defined and
  # NameError will be thrown if we attempt to camelize something like:
  # `"#{namespace}::#{Inflector.camelize(filename)}"`
  # so we can assume naming convention was not respected in required
  # file.

  raise NameError, name_error_message(attempted)
end