Class: Dry::System::Config::ComponentDirs

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/config/component_dirs.rb

Overview

The configured component dirs for a container

Instance Attribute Summary collapse

Settings collapse

Instance Method Summary collapse

Constructor Details

#initializeComponentDirs

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.

Creates a new component dirs



102
103
104
105
# File 'lib/dry/system/config/component_dirs.rb', line 102

def initialize
  @dirs = {}
  @defaults = ComponentDir.new(nil)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object (private)



271
272
273
274
275
276
277
# File 'lib/dry/system/config/component_dirs.rb', line 271

def method_missing(name, ...)
  if defaults.respond_to?(name)
    defaults.public_send(name, ...)
  else
    super
  end
end

Instance Attribute Details

#defaultsObject (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.

A ComponentDir for configuring the default values to apply to all added component dirs

See Also:

  • #method_missing


97
98
99
# File 'lib/dry/system/config/component_dirs.rb', line 97

def defaults
  @defaults
end

Instance Method Details

#add(path) {|dir| ... } ⇒ ComponentDir #add(dir) ⇒ ComponentDir

Overloads:

  • #add(path) {|dir| ... } ⇒ ComponentDir

    Adds and configures a component dir for the given path

    Examples:

    component_dirs.add "lib" do |dir|
      dir.default_namespace = "my_app"
    end
    

    Parameters:

    • path (String)

      the path for the component dir, relative to the configured container root

    Yield Parameters:

    Returns:

    See Also:

  • #add(dir) ⇒ ComponentDir

    Adds a configured component dir

    Examples:

    dir = Dry::System::ComponentDir.new("lib")
    component_dirs.add dir
    

    Parameters:

    Returns:

    See Also:

Raises:



160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/dry/system/config/component_dirs.rb', line 160

def add(path_or_dir)
  path, dir_to_add = path_and_dir(path_or_dir)

  raise ComponentDirAlreadyAddedError, path if dirs.key?(path)

  dirs[path] = dir_to_add.tap do |dir|
    # Defaults must be applied after yielding, since the dir is being newly added,
    # and must have its configuration fully in place before we can know which
    # defaults to apply
    yield dir if path_or_dir == path && block_given?
    apply_defaults_to_dir(dir)
  end
end

#add_to_load_pathObject

Returns the configured default ‘add_to_load_path`

See Also:



# File 'lib/dry/system/config/component_dirs.rb', line 77


#add_to_load_path=(value) ⇒ Object

Sets a default ‘add_to_load_path` value for all added component dirs



# File 'lib/dry/system/config/component_dirs.rb', line 77


#auto_registerObject

Returns the configured default ‘instance`

See Also:



# File 'lib/dry/system/config/component_dirs.rb', line 15


#auto_register=(value) ⇒ Object

Sets a default ‘auto_register` for all added component dirs



# File 'lib/dry/system/config/component_dirs.rb', line 15


#delete(path) ⇒ ComponentDir

Deletes and returns a previously added component dir

Parameters:

  • path (String)

    the path for the component dir

Returns:



181
182
183
# File 'lib/dry/system/config/component_dirs.rb', line 181

def delete(path)
  dirs.delete(path)
end

#dir(path) {|dir| ... } ⇒ ComponentDir Also known as: []

Returns and optionally yields a previously added component dir

Parameters:

  • path (String)

    the path for the component dir

Yield Parameters:

Returns:



121
122
123
124
125
126
127
# File 'lib/dry/system/config/component_dirs.rb', line 121

def dir(path)
  dirs[path].tap do |dir|
    # Defaults can be (re-)applied first, since the dir has already been added
    apply_defaults_to_dir(dir) if dir
    yield dir if block_given?
  end
end

#each {|dir| ... } ⇒ Object

Calls the given block once for each added component dir, passing the dir as an argument.

Yield Parameters:



220
221
222
# File 'lib/dry/system/config/component_dirs.rb', line 220

def each(&)
  to_a.each(&)
end

#initialize_copy(source) ⇒ 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.



108
109
110
111
# File 'lib/dry/system/config/component_dirs.rb', line 108

def initialize_copy(source)
  @dirs = source.dirs.transform_values(&:dup)
  @defaults = source.defaults.dup
end

#instance=(value) ⇒ Object

Sets a default ‘instance` for all added component dirs



# File 'lib/dry/system/config/component_dirs.rb', line 28


#lengthInteger Also known as: size

Returns the count of component dirs

Returns:

  • (Integer)


199
200
201
# File 'lib/dry/system/config/component_dirs.rb', line 199

def length
  dirs.length
end

#loaderObject

Returns the configured default ‘loader`

See Also:



# File 'lib/dry/system/config/component_dirs.rb', line 41


#loader=(value) ⇒ Object

Sets a default ‘loader` value for all added component dirs



# File 'lib/dry/system/config/component_dirs.rb', line 41


#memoizeObject

Returns the configured default ‘memoize`

See Also:



# File 'lib/dry/system/config/component_dirs.rb', line 54


#memoize=(value) ⇒ Object

Sets a default ‘memoize` value for all added component dirs



# File 'lib/dry/system/config/component_dirs.rb', line 54


#namespacesNamespaces

Returns the default configured namespaces for all added component dirs

Allows namespaces to added on the returned object via Namespaces#add.

Returns:

See Also:



# File 'lib/dry/system/config/component_dirs.rb', line 67


#pathsArray<String>

Returns the paths of the component dirs

Returns:

  • (Array<String>)

    the component dir paths



190
191
192
# File 'lib/dry/system/config/component_dirs.rb', line 190

def paths
  dirs.keys
end

#to_aArray<ComponentDir>

Returns the added component dirs, with default settings applied

Returns:



209
210
211
212
# File 'lib/dry/system/config/component_dirs.rb', line 209

def to_a
  dirs.each { |_, dir| apply_defaults_to_dir(dir) }
  dirs.values
end