class ROM::AutoRegistrationStrategies::CustomNamespace
Custom namespace strategy loads components and assumes they are defined within the provided namespace
@api private
Public Instance Methods
call()
click to toggle source
Loads components
@api private
# File 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, name_error_message(attempted) end
Private Instance Methods
file_path()
click to toggle source
@api private
# File lib/rom/setup/auto_registration_strategies/custom_namespace.rb, line 78 def file_path File.dirname(file).split('/') - directory.to_s.split('/') end
filename()
click to toggle source
@api private
# File lib/rom/setup/auto_registration_strategies/custom_namespace.rb, line 63 def filename Pathname(file).basename('.rb') end
name_error_message(attempted)
click to toggle source
@api private
# File lib/rom/setup/auto_registration_strategies/custom_namespace.rb, line 56 def name_error_message(attempted) 'required file does not define expected constant name; either ' \ 'register your constant explicitly of try following the path' \ "naming convention like:\n\n\t- #{attempted.join("\n\t- ")}\n" end
ns_const()
click to toggle source
@api private
# File lib/rom/setup/auto_registration_strategies/custom_namespace.rb, line 68 def ns_const @namespace_constant ||= Inflector.constantize(namespace) end
path_arr()
click to toggle source
@api private
# File lib/rom/setup/auto_registration_strategies/custom_namespace.rb, line 73 def path_arr file_path << filename end