Sha256: 7940851b8b5fb23b0b06b733c74a866104d9b050812fb301ee5e7dbc7404a420
Contents?: true
Size: 770 Bytes
Versions: 4
Compression:
Stored size: 770 Bytes
Contents
module Flows module Plugin module DependencyInjector # Resolves dependency on initialization and can inject it into class instance. # # @api private Dependency = Struct.new(:name, :definition, :provided_value, :value, :klass, keyword_init: true) do def initialize(*) super self.value = provided_value == NO_VALUE ? definition.default : provided_value type = definition.type raise UnexpectedDependencyTypeError.new(klass, name, value, type) if type != NO_TYPE && !(type === value) # rubocop:disable Style/CaseEquality end def inject_to(instance) value = self.value instance.define_singleton_method(name) { value } end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems