Sha256: 17f2c0525f25a533e0b7dbd633976870af7dec0f4325002cff9dd50940a839fa

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

require "dry/auto_inject/strategies"

module Dry
  module AutoInject
    class Injector < ::BasicObject
      # @api private
      attr_reader :container

      # @api private
      attr_reader :strategy

      # @api private
      attr_reader :builder

      define_method(:respond_to?, ::Kernel.instance_method(:respond_to?))

      # @api private
      def initialize(container, strategy, builder:)
        @container = container
        @strategy = strategy
        @builder = builder
      end

      def [](*dependency_names) = strategy.new(container, *dependency_names)

      def respond_to_missing?(name, _ = false) = builder.respond_to?(name)

      private

      def method_missing(name, ...) = builder.__send__(name)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-auto_inject-1.1.0 lib/dry/auto_inject/injector.rb