Class: Toys::StandardMiddleware::ApplyConfig
- Inherits:
-
Object
- Object
- Toys::StandardMiddleware::ApplyConfig
- Defined in:
- lib/toys/standard_middleware/apply_config.rb
Overview
A middleware that applies the given block to all tool configurations.
Instance Method Summary collapse
-
#initialize(parent_source: nil, source_name: nil, &block) ⇒ ApplyConfig
constructor
Create an ApplyConfig middleware.
Constructor Details
#initialize(parent_source: nil, source_name: nil, &block) ⇒ ApplyConfig
Create an ApplyConfig middleware.
This middleware works in one of two modes:
- Tied to a provided
parent_source. This is generally used when the middleware is invoked during tool loading, e.g. via the DSL::Tool#subtool_apply DSL directive. The block will be associated with a new "proc" source under the given parent, and will apply only to tools from the same source tree (i.e. the same priority.) - Not tied to a source, i.e. the no
parent_sourceprovided. This is generally used when the middleware is installed globally in the loader. The block will be applied to every tool, regardless of the tool's source, and will be associated with a separate "proc" source for every tool source tree (i.e. every priority).
Your block cannot create or modify subtools of the tool being modified. (This is because the same middleware could be expected to apply to that subtool as well, and the semantics of the resulting recursion would be messy and ambiguous.) Thus, within the block:
- You cannot use the
tooldirective. - You cannot create a
Toys::Toolsubclass. - You cannot use a
subtool_applydirective. - You cannot pass the
as:parameter to anyloador related directive. - You cannot use any
loador related directive that references a directory. (You can, however, load a file directly, as long as it does not use theas:parameter, and the file's contents do not violate any of these rules.)
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/toys/standard_middleware/apply_config.rb', line 49 def initialize(parent_source: nil, source_name: nil, &block) @block = block if parent_source @source = parent_source.proc_child(block, source_name: source_name) @mutex = @sources_by_root = @source_name = nil else @source_name = source_name @sources_by_root = {} @mutex = ::Mutex.new @source = nil end end |