Module: Dry::Container::Nested

Extended by:
ClassInterface
Defined in:
lib/dry/container/nested.rb,
lib/dry/container/nested/version.rb

Overview

Examples:

module Example
  extend Dry::Container::Mixin

  register :key, Object.new
  register :callable, proc { 1 }, call: false
  module Nested
    extend Dry::Container::Nested
    register :another, Object.new
  end
end

Defined Under Namespace

Modules: ClassInterface Classes: NoNameError

Constant Summary collapse

Undefined =
Object.new do
  class << self
    def inspect
      'Undefined'
    end

    alias_method :to_str, :inspect
    alias_method :to_s, :inspect
  end
end.freeze
VERSION =
'0.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassInterface

apply_namespace!, key_methods, key_parameter, method_definition, redefine_method

Class Method Details

.extended(other) ⇒ Object

Raises:



111
112
113
114
# File 'lib/dry/container/nested.rb', line 111

def self.extended(other)
  super
  raise NoNameError, other unless other.name
end

Instance Method Details

#each(&block) ⇒ Enumerator

Calls block once for each key/value pair in the container, passing the key and the registered item parameters.

If no block is given, an enumerator is returned instead.



201
202
203
204
205
206
207
208
# File 'lib/dry/container/nested.rb', line 201

def each(&block)
  container.config
           .resolver
           .each(_container)
           .each_with_object([]) do |(key, value), result|
    result << [deprefixed(key), value] if matcher.match?(key)
  end.each(&block)
end

#each_key(&block) ⇒ Dry::Container::Mixin

Calls block once for each key in container, passing the key as a parameter.

If no block is given, an enumerator is returned instead.



190
191
192
193
# File 'lib/dry/container/nested.rb', line 190

def each_key(&block)
  keys.each_key(&block)
  self
end

#keysArray<String>

An array of registered names for the container



178
179
180
181
182
# File 'lib/dry/container/nested.rb', line 178

def keys
  container.keys.each_with_object([]) do |key, keys|
    keys << deprefixed(key) if matcher.match?(key)
  end
end