Sha256: ab45b38f729d59f79c722fb117a20a8a61fb97c708d113dd06129472516b3532

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

require_relative 'simple_injector/version'
require_relative 'simple_injector/contract'
require_relative 'simple_injector/injectable'
require_relative 'simple_injector/inject'

# Entrypoint module
module SimpleInjector
  def self.included(target)
    target.extend(ClassMethods)
  end

  # methods to add on included class
  module ClassMethods
    @contractor_class = nil

    def attr_injector(name)
      injectable = Inject.find(@contractor_class, name)

      define_method name do
        instance_variable_set(:"@#{name}", injectable.callback.call) unless instance_variable_defined?(:"@#{name}")

        instance_variable_get(:"@#{name}")
      end
    end

    def contract(klass)
      @contractor_class = klass.to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_injector-0.0.2 lib/simple_injector.rb