Class: ROM::AutoRegistrationStrategies::CustomNamespace Private

Inherits:
Base
  • Object
show all
Defined in:
lib/rom/compat/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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directoryPathname (readonly)

Returns The path to dir with components.

Returns:

  • (Pathname)

    The path to dir with components


19
# File 'lib/rom/compat/auto_registration_strategies/custom_namespace.rb', line 19

option :directory, type: PathnameType

#namespaceString (readonly)

Returns Name of a namespace.

Returns:

  • (String)

    Name of a namespace


23
# File 'lib/rom/compat/auto_registration_strategies/custom_namespace.rb', line 23

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)

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 'lib/rom/compat/auto_registration_strategies/custom_namespace.rb', line 28

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