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



106
107
108
109
# File 'lib/dry/system/config/component_dirs.rb', line 106

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



275
276
277
278
279
280
281
# File 'lib/dry/system/config/component_dirs.rb', line 275

def method_missing(name, *args, &block)
  if defaults.respond_to?(name)
    defaults.public_send(name, *args, &block)
  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


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

def defaults
  @defaults
end

Instance Method Details

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

Overloads:

Raises:



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/dry/system/config/component_dirs.rb', line 164

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 79

#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 79

#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:



185
186
187
# File 'lib/dry/system/config/component_dirs.rb', line 185

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:



125
126
127
128
129
130
131
# File 'lib/dry/system/config/component_dirs.rb', line 125

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:



224
225
226
# File 'lib/dry/system/config/component_dirs.rb', line 224

def each(&block)
  to_a.each(&block)
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.



112
113
114
115
# File 'lib/dry/system/config/component_dirs.rb', line 112

def initialize_copy(source)
  @dirs = source.dirs.map { |path, dir| [path, dir.dup] }.to_h
  @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)


203
204
205
# File 'lib/dry/system/config/component_dirs.rb', line 203

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 69

#pathsArray<String>

Returns the paths of the component dirs

Returns:

  • (Array<String>)

    the component dir paths



194
195
196
# File 'lib/dry/system/config/component_dirs.rb', line 194

def paths
  dirs.keys
end

#to_aArray<ComponentDir>

Returns the added component dirs, with default settings applied

Returns:



213
214
215
216
# File 'lib/dry/system/config/component_dirs.rb', line 213

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