Class: ROM::AutoRegistrationStrategies::CustomNamespace Private
- Defined in:
- core/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
Instance Attribute Summary collapse
-
#directory ⇒ Pathname
readonly
The path to dir with components.
-
#namespace ⇒ String
readonly
Name of a namespace.
Instance Method Summary collapse
-
#call ⇒ Object
private
Loads components.
Instance Attribute Details
#directory ⇒ Pathname (readonly)
Returns The path to dir with components.
18 |
# File 'core/lib/rom/setup/auto_registration_strategies/custom_namespace.rb', line 18 option :directory, type: PathnameType |
#namespace ⇒ String (readonly)
Returns Name of a namespace.
22 |
# File 'core/lib/rom/setup/auto_registration_strategies/custom_namespace.rb', line 22 option :namespace, type: Types::Strict::String |
Instance Method Details
#call ⇒ Object
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
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 |
# File 'core/lib/rom/setup/auto_registration_strategies/custom_namespace.rb', line 27 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, (attempted) end |