Sha256: bb34a939c3cda562ade7e45f28e02e707e721e83d341d8ceeb6390511424358f

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Dry
  module System
    class Provider
      # Configures a Dry::System::Provider::Source subclass using a DSL that makes it
      # nicer to define source behaviour via a single block.
      #
      # @see Dry::System::Container.register_provider
      #
      # @api private
      class SourceDSL
        def self.evaluate(source_class, &block)
          new(source_class).instance_eval(&block)
        end

        attr_reader :source_class

        def initialize(source_class)
          @source_class = source_class
        end

        def setting(...)
          source_class.setting(...)
        end

        def prepare(&block)
          source_class.define_method(:prepare, &block)
        end

        def start(&block)
          source_class.define_method(:start, &block)
        end

        def stop(&block)
          source_class.define_method(:stop, &block)
        end

        private

        def method_missing(name, *args, &block)
          if source_class.respond_to?(name)
            source_class.public_send(name, *args, &block)
          else
            super
          end
        end

        def respond_to_missing?(name, include_all = false)
          source_class.respond_to?(name, include_all) || super
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-system-1.1.1 lib/dry/system/provider/source_dsl.rb
dry-system-1.1.0 lib/dry/system/provider/source_dsl.rb
dry-system-1.1.0.beta2 lib/dry/system/provider/source_dsl.rb
dry-system-1.1.0.beta1 lib/dry/system/provider/source_dsl.rb
dry-system-1.0.1 lib/dry/system/provider/source_dsl.rb
dry-system-1.0.0 lib/dry/system/provider/source_dsl.rb
dry-system-1.0.0.rc1 lib/dry/system/provider/source_dsl.rb