Sha256: 812eb062b7634e14930a1fa54c5afa8104a069a4d556d349bed0f29252f71156
Contents?: true
Size: 1.47 KB
Versions: 4
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true require "dry/system/constants" module Dry module System # @api private class ProviderSourceRegistry # @api private class Registration attr_reader :source attr_reader :provider_options def initialize(source:, provider_options:) @source = source @provider_options = provider_options end end attr_reader :sources def initialize @sources = {} end def load_sources(path) Dir[File.join(path, "**/#{RB_GLOB}")].sort.each do |file| require file end end def register(name:, group:, source:, provider_options:) sources[key(name, group)] = Registration.new( source: source, provider_options: provider_options ) end def register_from_block(name:, group:, provider_options:, &block) register( name: name, group: group, source: Provider::Source.for(name: name, group: group, &block), provider_options: provider_options ) end def resolve(name:, group:) sources[key(name, group)].tap { |source| unless source raise ProviderSourceNotFoundError.new( name: name, group: group, keys: sources.keys ) end } end private def key(name, group) {group: group, name: name} end end end end
Version data entries
4 entries across 4 versions & 1 rubygems