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: e142a541f92e6b2af8869b8fadc2ecc82da2823b4c5ed9a9a24b7959cceecd7c
4
- data.tar.gz: 8d9623f9a1c9b8162b551efd142fb71259e0bb689eb7e3f9ef0b2788682521c6
3
+ metadata.gz: fdda7809de8ba754d34b1ee6c90af75e23b9700450aa889651859a23ef54aa4d
4
+ data.tar.gz: f1df008ae51c1fbe48a1a9554dc6be740d2012525106e0c2aadc41e3737ac651
5
5
  SHA512:
6
- metadata.gz: e45eca1ef91da4d221138313a9c15bca970585adb5f22a47efe9503aaa2b9630691182819199387b8f690d48859a7e28e20725abf3c135e5f3e30c9a42951a4f
7
- data.tar.gz: 88772fb162c2b8c95678f9965aee48dbc15cc548224e39b928de8e5422683005e07ff64148f43e790ed6dc96a05bf69a3c25a3f2a1dba9e01606f8be81f42107
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
- @definitions[id] = definition
42
- definition.tags.each { |tag| @tags[tag] << id }
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 @tags.key?(tag)
49
+ if tags.key?(tag)
51
50
 
52
- @tags.fetch(tag)
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
- @definitions.key?(to_id(key))
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
- @definitions.fetch(id).build(injector).tap do |service|
82
- @services[id] = service
103
+ definitions.fetch(id).build(injector).tap do |service|
104
+ services[id] = service
83
105
  end
84
106
  end
85
107
 
@@ -42,6 +42,12 @@ module Corindon
42
42
  @id = nil
43
43
  end
44
44
 
45
+ # @param [Class, #to_s] key
46
+ # @return [Token::ParameterToken]
47
+ def param(key)
48
+ Token::ParameterToken.new(key: key)
49
+ end
50
+
45
51
  # @param [String] tag
46
52
  def tag(tag)
47
53
  @tags << tag
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Corindon
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.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