Class: Configure::Injector
- Inherits:
-
Object
- Object
- Configure::Injector
- Defined in:
- lib/configure/injector.rb
Overview
Creates a configuration from the passed class and provides methods to inject values.
Defined Under Namespace
Classes: Arguments
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #configuration ⇒ Object
- #configuration_class ⇒ Object
- #defaults ⇒ Object
-
#initialize(schema) ⇒ Injector
constructor
A new instance of Injector.
- #put_arguments(key, arguments) ⇒ Object
- #put_block(key, arguments, &block) ⇒ Object
Constructor Details
#initialize(schema) ⇒ Injector
Returns a new instance of Injector.
7 8 9 10 |
# File 'lib/configure/injector.rb', line 7 def initialize(schema) @schema = schema @configuration = self.configuration_class.new end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/configure/injector.rb', line 5 def schema @schema end |
Instance Method Details
#configuration ⇒ Object
33 34 35 36 |
# File 'lib/configure/injector.rb', line 33 def configuration apply_defaults @configuration end |
#configuration_class ⇒ Object
12 13 14 |
# File 'lib/configure/injector.rb', line 12 def configuration_class @schema[:configuration_class] end |
#defaults ⇒ Object
16 17 18 |
# File 'lib/configure/injector.rb', line 16 def defaults @schema[:defaults] || { } end |
#put_arguments(key, arguments) ⇒ Object
28 29 30 31 |
# File 'lib/configure/injector.rb', line 28 def put_arguments(key, arguments) value = Configure::Value.new @schema, @configuration, key value.put_single_or_multiple arguments end |
#put_block(key, arguments, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/configure/injector.rb', line 20 def put_block(key, arguments, &block) nested_schema = (@schema[:nested] || { })[key] || @schema[:nested_default] || Configure::Schema.build { } nested_configuration = Configure.process_configuration nested_schema, &block Arguments.new(nested_schema, nested_configuration, arguments).put value = Configure::Value.new @schema, @configuration, key value.put_or_combine nested_configuration end |