Class: ROM::Loader
Overview
AutoRegistration is used to load component files automatically from the provided directory path
Constant Summary collapse
- NamespaceType =
Types::Strict::Bool | Types.Instance(Module)
- PathnameType =
Types.Constructor(Pathname, &Kernel.method(:Pathname))
- InflectorType =
Types.Interface(:camelize)
- ComponentDirs =
Types::Strict::Hash.constructor { |hash| hash.transform_values(&:to_s) }
- DEFAULT_MAPPING =
{ relations: "relations", mappers: "mappers", commands: "commands" }.freeze
Instance Attribute Summary collapse
-
#auto_load ⇒ Boolean
readonly
Whether files should be auto-loadable.
-
#component_dirs ⇒ Hash
readonly
Component => dir-name map.
- #components ⇒ ROM::Components readonly private
-
#directory ⇒ Pathname
readonly
The root path.
-
#inflector ⇒ Dry::Inflector
readonly
private
String inflector.
-
#namespace ⇒ Boolean, String
readonly
The name of the top level namespace or true/false which enables/disables default top level namespace inferred from the dir name.
Instance Method Summary collapse
- #auto_load_component_file(type, key) ⇒ Object private
-
#call ⇒ Object
private
Load components.
Instance Attribute Details
#auto_load ⇒ Boolean (readonly)
Returns Whether files should be auto-loadable.
40 |
# File 'lib/rom/loader.rb', line 40 option :auto_load, type: Types::Strict::Bool, default: -> { false } |
#component_dirs ⇒ Hash (readonly)
Returns component => dir-name map.
50 |
# File 'lib/rom/loader.rb', line 50 option :component_dirs, type: ComponentDirs, default: -> { DEFAULT_MAPPING } |
#components ⇒ ROM::Components (readonly)
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.
60 |
# File 'lib/rom/loader.rb', line 60 option :components |
#directory ⇒ Pathname (readonly)
Returns The root path.
35 |
# File 'lib/rom/loader.rb', line 35 param :root_directory, type: PathnameType.optional |
#inflector ⇒ Dry::Inflector (readonly)
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.
Returns String inflector.
55 |
# File 'lib/rom/loader.rb', line 55 option :inflector, type: InflectorType, default: -> { Inflector } |
#namespace ⇒ Boolean, String (readonly)
Returns The name of the top level namespace or true/false which enables/disables default top level namespace inferred from the dir name.
46 |
# File 'lib/rom/loader.rb', line 46 option :namespace, type: NamespaceType, default: -> { true } |
Instance Method Details
#auto_load_component_file(type, key) ⇒ 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.
76 77 78 79 80 81 82 83 84 |
# File 'lib/rom/loader.rb', line 76 def auto_load_component_file(type, key) return unless component_dirs.include?(type) const_parts = key.split(".").map { |name| inflector.camelize(name) } const_parts.unshift(namespace_const_name) if namespace_const_name const_name = const_parts.join("::") inflector.constantize(const_name) end |
#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.
Load components
65 66 67 68 69 70 71 72 73 |
# File 'lib/rom/loader.rb', line 65 def call return if @loaded || root_directory.nil? setup backend.eager_load unless auto_load @loaded = true end |