Sha256: 91cf641f5e48ba453df30feccce6e312a303c9268ff008942f90ab6da7e65139

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

require 'concurrent/map'
require 'dry/system/constants'
require 'dry/system/components/bootable'

module Dry
  module System
    class Provider
      attr_reader :identifier

      attr_reader :options

      attr_reader :components

      def initialize(identifier, options)
        @identifier = identifier
        @options = options
        @components = Concurrent::Map.new
      end

      def boot_path
        options.fetch(:boot_path)
      end

      def boot_files
        Dir[boot_path.join("**/#{RB_GLOB}")]
      end

      def register_component(name, fn)
        components[name] = Components::Bootable.new(name, &fn)
      end

      def boot_file(name)
        boot_files.detect { |path| Pathname(path).basename(RB_EXT).to_s == name.to_s }
      end

      def component(name, options = {})
        identifier = options[:key] || name
        components.fetch(identifier).new(name, options)
      end

      def load_components
        boot_files.each { |f| require f }
        freeze
        self
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-system-0.12.0 lib/dry/system/provider.rb
dry-system-0.11.0 lib/dry/system/provider.rb
dry-system-0.10.1 lib/dry/system/provider.rb
dry-system-0.10.0 lib/dry/system/provider.rb
dry-system-0.9.2 lib/dry/system/provider.rb
dry-system-0.9.1 lib/dry/system/provider.rb
dry-system-0.9.0 lib/dry/system/provider.rb