Module: Etcher
- Defined in:
- lib/etcher.rb,
lib/etcher/types.rb,
lib/etcher/finder.rb,
lib/etcher/builder.rb,
lib/etcher/contract.rb,
lib/etcher/registry.rb,
lib/etcher/resolver.rb,
lib/etcher/loaders/json.rb,
lib/etcher/loaders/yaml.rb,
lib/etcher/transformers/time.rb,
lib/etcher/loaders/environment.rb,
lib/etcher/transformers/string.rb
Overview
Finds internal constant if moniker matches, otherwise answers a failure.
Defined Under Namespace
Modules: Loaders, Transformers, Types Classes: Builder, Resolver
Constant Summary collapse
- LOGGER =
Cogger.new id: :etcher
- Finder =
lambda do |namespace, moniker| Etcher.const_get(namespace) .constants .find { |constant| constant.downcase == moniker } .then do |constant| return Dry::Monads::Success Etcher.const_get("#{namespace}::#{constant}") if constant Dry::Monads::Failure "Unable to select #{moniker.inspect} within #{namespace.downcase}." end rescue NameError Dry::Monads::Failure "Invalid namespace: #{namespace.inspect}." end
- Contract =
A simple passthrough contract.
lambda do |result| def result.to_monad = Dry::Monads::Success self unless result.respond_to? :to_monad result end
- Registry =
Provides a registry of customization for loading and resolving a configuration.
Data.define :contract, :model, :loaders, :transformers do def self.find namespace, moniker, logger: LOGGER case Finder.call namespace, moniker in Success(constant) then constant in Failure() then logger.abort else logger.abort "Unable to find constant in registry." end end def initialize contract: Contract, model: Hash, loaders: [], transformers: [] super end def add_loader(loader, *, **) if loader.is_a? Symbol self.class.find(:Loaders, loader).then { |constant| loaders.append constant.new(*, **) } else loaders.append loader end self end def add_transformer(transformer, *, **) if transformer.is_a? Symbol self.class.find(:Transformers, transformer).then do |constant| transformers.append constant.new(*, **) end else transformers.append transformer end self end end
Class Method Summary collapse
- .call(registry = Registry.new) ⇒ Object
- .loader(registry = Zeitwerk::Registry) ⇒ Object
- .new ⇒ Object
Class Method Details
.call(registry = Registry.new) ⇒ Object
23 |
# File 'lib/etcher.rb', line 23 def self.call(registry = Registry.new, **) = Resolver.new(registry).call(**) |
.loader(registry = Zeitwerk::Registry) ⇒ Object
17 18 19 |
# File 'lib/etcher.rb', line 17 def self.loader registry = Zeitwerk::Registry @loader ||= registry.loaders.find { |loader| loader.tag == File.basename(__FILE__, ".rb") } end |
.new ⇒ Object
21 |
# File 'lib/etcher.rb', line 21 def self.new(...) = Builder.new(...) |