Module: Dry::Initializer::Dispatchers
Overview
The module is responsible for __normalizing__ arguments of ‘.param` and `.option`.
What the module does is convert the source list of arguments into the standard set of options:
-
‘:option` – whether an argument is an option (or param)
-
‘:source` – the name of source option
-
‘:target` – the target name of the reader
-
‘:reader` – if the reader’s privacy (:public, :protected, :private, nil)
-
‘:ivar` – the target nane of the variable
-
‘:type` – the callable coercer of the source value
-
‘:optional` – if the argument is optional
-
‘:default` – the proc returning the default value of the source value
-
‘:null` – the value to be set to unassigned optional argument
It is this set is used to build [Dry::Initializer::Definition].
# Settings
The module uses global setting ‘null` to define what value should be set to variables that kept unassigned. By default it uses `Dry::Initializer::UNDEFINED`
# Syntax Extensions
The module supports syntax extensions. You can add any number of custom dispatchers __on top__ of the stack of default dispatchers. Every dispatcher should be a callable object that takes the source set of options and converts it to another set of options.
Defined Under Namespace
Modules: BuildNestedType, CheckType, PrepareDefault, PrepareIvar, PrepareOptional, PrepareReader, PrepareSource, PrepareTarget, UnwrapType, WrapType
Instance Attribute Summary collapse
- #null ⇒ Object
- #null Defines a value to be set to unassigned attributes(Definesavaluetobesettounassignedattributes) ⇒ Object
Instance Method Summary collapse
-
#<<(dispatcher) ⇒ self
Registers a new dispatcher.
-
#call(**options) ⇒ Hash<Symbol, Objct>
Normalizes the source set of options.
Instance Attribute Details
#null ⇒ Object
68 69 70 |
# File 'lib/dry/initializer/dispatchers.rb', line 68 def null @null end |
#null Defines a value to be set to unassigned attributes(Definesavaluetobesettounassignedattributes) ⇒ Object
68 |
# File 'lib/dry/initializer/dispatchers.rb', line 68 attr_accessor :null |
Instance Method Details
#<<(dispatcher) ⇒ self
Registers a new dispatcher
76 77 78 79 |
# File 'lib/dry/initializer/dispatchers.rb', line 76 def <<(dispatcher) @pipeline = [dispatcher] + pipeline self end |
#call(**options) ⇒ Hash<Symbol, Objct>
Normalizes the source set of options
87 88 89 90 |
# File 'lib/dry/initializer/dispatchers.rb', line 87 def call(**) = { null: null, ** } pipeline.reduce() { |opts, dispatcher| dispatcher.call(**opts) } end |