class Dry::Container
Public Class Methods
extended(other)
click to toggle source
Calls superclass method
# File lib/dry/container/nested.rb, line 111 def self.extended(other) super raise NoNameError, other unless other.name end
Public Instance Methods
container()
click to toggle source
# File lib/dry/container/nested.rb, line 82 def container if containing_module.container? containing_module else containing_module.container end end
container?()
click to toggle source
# File lib/dry/container/nested.rb, line 78 def container? singleton_class.included_modules.include? Dry::Container::Mixin end
containing_module()
click to toggle source
@return [Module]
# File lib/dry/container/nested.rb, line 42 def containing_module Inflecto.constantize Inflecto.camelize containing_path end
containing_path(name = self.name)
click to toggle source
@param [String] name @return [String]
# File lib/dry/container/nested.rb, line 37 def containing_path(name = self.name) path(name)[0..-2].join('/') end
deprefixed(key)
click to toggle source
# File lib/dry/container/nested.rb, line 94 def deprefixed(key) key.gsub(matcher, '') end
each(&block)
click to toggle source
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.
@return [Enumerator]
# 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)
click to toggle source
Calls block once for each key in container, passing the key as a parameter.
If no block is given, an enumerator is returned instead.
@return [Dry::Container::Mixin] self
# File lib/dry/container/nested.rb, line 190 def each_key(&block) keys.each_key(&block) self end
key(key = Undefined)
click to toggle source
@return [String] @example
module Example key #=> 'example' key #=> 'example' module Nested key #=> 'example.nested' end end
# File lib/dry/container/nested.rb, line 55 def key(key = Undefined) @__key__ = key unless key == Undefined @__key__ ||= path(name).last end
keys()
click to toggle source
An array of registered names for the container
@return [Array<String>]
# 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
matcher()
click to toggle source
# File lib/dry/container/nested.rb, line 90 def matcher /\A#{prefix}\./ end
namespace_dsl()
click to toggle source
# File lib/dry/container/nested.rb, line 70 def namespace_dsl container[prefixed] end
path(name = self.name)
click to toggle source
# File lib/dry/container/nested.rb, line 74 def path(name = self.name) Inflecto.underscore(name).split('/') end
prefix()
click to toggle source
# File lib/dry/container/nested.rb, line 66 def prefix container? ? nil : "#{containing_module.prefix}#{key}" end
prefixed(key = nil)
click to toggle source
@param key [String?] @return [String]
# File lib/dry/container/nested.rb, line 62 def prefixed(key = nil) [prefix, key].compact.join('.') end