Class: Containable::Builder
- Inherits:
-
Module
- Object
- Module
- Containable::Builder
- Defined in:
- lib/containable/builder.rb
Overview
Provides safe registration and resolution of dependencies.
Instance Method Summary collapse
- #extended(descendant) ⇒ Object
-
#initialize(dependencies = Concurrent::Hash.new, register: Register, resolver: Resolver) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(dependencies = Concurrent::Hash.new, register: Register, resolver: Resolver) ⇒ Builder
Returns a new instance of Builder.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/containable/builder.rb', line 8 def initialize dependencies = Concurrent::Hash.new, register: Register, resolver: Resolver super() @dependencies = dependencies @register = register.new dependencies @resolver = resolver.new dependencies private_methods.grep(/\A(define)_/).sort.each { |method| __send__ method } alias_method :[]=, :register alias_method :[], :resolve freeze end |
Instance Method Details
#extended(descendant) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/containable/builder.rb', line 23 def extended descendant fail TypeError, "Only a module can be a container." if descendant.is_a? Class super descendant.class_eval "private_class_method :dependencies", __FILE__, __LINE__ end |