Sha256: 142619c2d00d8bc468f1b6d0572e41cd481c396d22ba74d15d67dceaa994467d

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

require 'dry/auto_inject/builder'

module Dry
  # Configure an auto-injection module
  #
  # @example
  #    module MyApp
  #      # set up your container
  #      container = Dry::Container.new
  #
  #      container.register(:data_store, -> { DataStore.new })
  #      container.register(:user_repository, -> { container[:data_store][:users] })
  #      container.register(:persist_user, -> { PersistUser.new })
  #
  #      # set up your auto-injection function
  #      AutoInject = Dry::AutoInject(container)
  #
  #      # define your injection function
  #      def self.Inject(*keys)
  #        AutoInject[*keys]
  #      end
  #    end
  #
  #    # then simply include it in your class providing which dependencies should be
  #    # injected automatically from the configured container
  #    class PersistUser
  #      include MyApp::Inject(:user_repository)
  #
  #      def call(user)
  #        user_repository << user
  #      end
  #    end
  #
  #    persist_user = container[:persist_user]
  #
  #    persist_user.call(name: 'Jane')
  #
  # @return [Proc] calling the returned proc builds an auto-injection module
  #
  # @api public
  def self.AutoInject(container, options = {})
    AutoInject::Builder.new(container, options)
  end

  module AutoInject
    # @api private
    def self.super_method(klass, method)
      method = klass.instance_method(method)
      method unless method.owner.equal?(klass)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-auto_inject-0.4.5 lib/dry/auto_inject.rb
dry-auto_inject-0.4.4 lib/dry/auto_inject.rb
dry-auto_inject-0.4.3 lib/dry/auto_inject.rb
dry-auto_inject-0.4.2 lib/dry/auto_inject.rb
dry-auto_inject-0.4.1 lib/dry/auto_inject.rb
dry-auto_inject-0.4.0 lib/dry/auto_inject.rb
dry-auto_inject-0.3.0 lib/dry/auto_inject.rb