Sha256: 245a80bbca309a6588a119f35df59574b65dd84a31a236cc653253844d49e963
Contents?: true
Size: 659 Bytes
Versions: 1
Compression:
Stored size: 659 Bytes
Contents
# frozen_string_literal: true module SimpleInjector class InjectableNotFound < StandardError; end # Singleton class to save instances and retrieve class Inject @injectables = {} class << self attr_accessor :injectables def register(contract_name, name, callback) (@injectables[contract_name] ||= []) << Injectable.new(name, callback) end def find(contract_name, name) injectable = (@injectables[contract_name] ||= []).find { |i| i.name == name } raise InjectableNotFound, "An instance with name '#{name}' was not registered" unless injectable injectable end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_injector-0.0.2 | lib/simple_injector/inject.rb |