corindon 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdda7809de8ba754d34b1ee6c90af75e23b9700450aa889651859a23ef54aa4d
|
4
|
+
data.tar.gz: f1df008ae51c1fbe48a1a9554dc6be740d2012525106e0c2aadc41e3737ac651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8f2c9c05289f1767bdab134dc959a159540bdd6653622b26d7515bad28010c0b052ac978ed555b37772b70be9ac9b2b108e8124060ff271c2517b4672d5b72a
|
7
|
+
data.tar.gz: 3ae05c3677e98b24da5c7bf3f13a879d0f1e1350ec49953108cc9c9b16423928c93555dc07b38da55898005e1e43eaffc821dafcef823aaa4d0432267283a016
|
@@ -5,16 +5,15 @@ module Corindon
|
|
5
5
|
class Container
|
6
6
|
using Ext::Something
|
7
7
|
|
8
|
-
attr_reader :definitions
|
9
8
|
attr_reader :id_generator
|
10
9
|
attr_reader :injector
|
11
|
-
attr_reader :services
|
12
10
|
|
13
11
|
# @param [Id::IdGenerator] id_generator
|
14
12
|
def initialize(id_generator: Id::UuidGenerator.new)
|
15
13
|
@id_generator = id_generator
|
16
14
|
@services = {}
|
17
15
|
@definitions = {}
|
16
|
+
@parameters = {}
|
18
17
|
@tags = Hash.new { |hash, key| hash[key] = [] }
|
19
18
|
|
20
19
|
@injector = Injector.new(container: self)
|
@@ -38,8 +37,8 @@ module Corindon
|
|
38
37
|
end
|
39
38
|
|
40
39
|
id = id || definition.id || to_id(klass)
|
41
|
-
|
42
|
-
definition.tags.each { |tag|
|
40
|
+
definitions[id] = definition
|
41
|
+
definition.tags.each { |tag| tags[tag] << id }
|
43
42
|
|
44
43
|
id
|
45
44
|
end
|
@@ -47,9 +46,9 @@ module Corindon
|
|
47
46
|
# @param [String] tag
|
48
47
|
# @return [Array<String>]
|
49
48
|
def tagged(tag)
|
50
|
-
if
|
49
|
+
if tags.key?(tag)
|
51
50
|
|
52
|
-
|
51
|
+
tags.fetch(tag)
|
53
52
|
else
|
54
53
|
[]
|
55
54
|
end
|
@@ -58,7 +57,7 @@ module Corindon
|
|
58
57
|
# @param [Class, #to_s] key
|
59
58
|
# @return [Boolean]
|
60
59
|
def has?(key)
|
61
|
-
|
60
|
+
definitions.key?(to_id(key))
|
62
61
|
end
|
63
62
|
|
64
63
|
# @param [Class, #to_s] key
|
@@ -75,11 +74,34 @@ module Corindon
|
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
77
|
+
# @param [Class, #to_s] key
|
78
|
+
# @param [Object] value
|
79
|
+
def set_parameter(name, value)
|
80
|
+
parameters[to_id(name)] = value
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param [Class, #to_s] key
|
84
|
+
# @return [Boolean]
|
85
|
+
def parameter?(key)
|
86
|
+
parameters.key?(to_id(key))
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param [Class, #to_s] key
|
90
|
+
# @return [Object]
|
91
|
+
def parameter(key)
|
92
|
+
parameters.fetch(to_id(key))
|
93
|
+
end
|
94
|
+
|
78
95
|
private
|
79
96
|
|
97
|
+
attr_reader :definitions
|
98
|
+
attr_reader :parameters
|
99
|
+
attr_reader :services
|
100
|
+
attr_reader :tags
|
101
|
+
|
80
102
|
def build_service(id)
|
81
|
-
|
82
|
-
|
103
|
+
definitions.fetch(id).build(injector).tap do |service|
|
104
|
+
services[id] = service
|
83
105
|
end
|
84
106
|
end
|
85
107
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Corindon
|
4
|
+
module DependencyInjection
|
5
|
+
module Token
|
6
|
+
class ParameterToken < InjectionToken
|
7
|
+
attr_reader :key
|
8
|
+
|
9
|
+
def initialize(key:)
|
10
|
+
super()
|
11
|
+
|
12
|
+
@key = key
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [Injector] injector
|
16
|
+
def resolve(injector:)
|
17
|
+
injector.container.parameter(key)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/corindon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corindon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Piotaix
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/corindon/dependency_injection/injectable.rb
|
101
101
|
- lib/corindon/dependency_injection/injector.rb
|
102
102
|
- lib/corindon/dependency_injection/token/injection_token.rb
|
103
|
+
- lib/corindon/dependency_injection/token/parameter_token.rb
|
103
104
|
- lib/corindon/dependency_injection/token/service_call_token.rb
|
104
105
|
- lib/corindon/dependency_injection/token/tagged_token.rb
|
105
106
|
- lib/corindon/dependency_injection/token/value_token.rb
|