corindon 0.7.2 → 0.8.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: 9899f5321cf96c41569182938051a815f5baed7d04bda1f88a649c21b50df0b3
4
- data.tar.gz: c6a9495fc8c46760fb5a09780bc8bbc12ae95deb4e0d7331042f7640f0d380d7
3
+ metadata.gz: 1dd263e6d3149f438f50e22fe7575fec7fcfc6d5f8755c77cd83877e5e89c0de
4
+ data.tar.gz: a33cc4b33c681d3027238dac77f1400e7a611b7502f0504aa5e8b6db2d28ac0a
5
5
  SHA512:
6
- metadata.gz: 66590e780392422933ccceb3596bb9e97d4ef6eb9e4d5685847cfe128b5f5d0a196723aa626f5bab711b011dad84a5987fc2b1946dd850b0e255226308bdd18a
7
- data.tar.gz: bd262475a0fa7d10b565ef357d066db7b94c310eff89188438683ff26322de2fb5bcf87398b676ded30ef0fac18c81d251cb0c0f217ed20208bd02ba96a0629e
6
+ metadata.gz: 13d607a74528b870f3d064a94b6913a4a76ea69ce5d4463ce6f0c41dd65c97c115d9aaeb07c05dc6f874910619dc8354c2670084cf71747e2330b34be46be145
7
+ data.tar.gz: 1c63ab07e90abbec9c23b04c7c6a097e39dbf23b2faf4f9cecaabb27006f0ee52aec72ee03c477157480931d9cfab95979357890bcc273de62f08bffbb02eaec
data/corindon.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency 'bundler'
22
22
  s.add_development_dependency 'minitest', '~> 5.14'
23
+ s.add_development_dependency 'minitest-reporters', '~> 1.4'
23
24
  s.add_development_dependency 'rake', '~> 13.0'
24
25
  s.add_development_dependency 'rubocop', '1.3.1'
25
26
  end
@@ -8,7 +8,8 @@ module Corindon
8
8
  attr_reader :injector
9
9
 
10
10
  # @param [Array<Definition>] definitions
11
- def initialize(definitions: [], parameters: {}, service_built_listeners: [])
11
+ # @param [ParameterBag] parameters
12
+ def initialize(definitions: [], parameters: ParameterBag.new, service_built_listeners: [])
12
13
  @services = {}
13
14
  @definitions = {}
14
15
  @parameters = parameters
@@ -25,7 +26,7 @@ module Corindon
25
26
  def dup
26
27
  Container.new(
27
28
  definitions: definitions.values,
28
- parameters: parameters.dup,
29
+ parameters: ParameterBag.new(parameters.bag.dup),
29
30
  service_built_listeners: service_built_listeners
30
31
  )
31
32
  end
@@ -105,22 +106,22 @@ module Corindon
105
106
  end
106
107
  end
107
108
 
108
- # @param [Class, #to_s] key
109
+ # @param [Class, String, Token::ParameterToken] key
109
110
  # @param [Object] value
110
- def set_parameter(name, value)
111
- parameters[to_id(name)] = value
111
+ def set_parameter(key, value)
112
+ parameters.set(key, value)
112
113
  end
113
114
 
114
- # @param [Class, #to_s] key
115
+ # @param [Class, String, Token::ParameterToken] key
115
116
  # @return [Boolean]
116
117
  def parameter?(key)
117
- parameters.key?(to_id(key))
118
+ parameters.has?(key)
118
119
  end
119
120
 
120
- # @param [Class, #to_s] key
121
+ # @param [Class, String, Token::ParameterToken] key
121
122
  # @return [Object]
122
123
  def parameter(key)
123
- parameters.fetch(to_id(key))
124
+ parameters.get(key)
124
125
  end
125
126
 
126
127
  # @param [Proc{Object, Container}] listener
@@ -132,6 +133,7 @@ module Corindon
132
133
 
133
134
  # @return [Hash{String=>Definition}]
134
135
  attr_reader :definitions
136
+ # @return [ParameterBag]
135
137
  attr_reader :parameters
136
138
  attr_reader :services
137
139
  attr_reader :tags
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Corindon
4
+ module DependencyInjection
5
+ class ParameterBag
6
+ # @return [Hash{String => Object}]
7
+ attr_reader :bag
8
+
9
+ # @param [Hash{String => Object}] bag
10
+ def initialize(bag = {})
11
+ @bag = bag
12
+ end
13
+
14
+ # @param [Class, String, Token::ParameterToken] key
15
+ # @return [Boolean]
16
+ def has?(key)
17
+ @bag.key?(to_key(key))
18
+ end
19
+
20
+ # @param [Class, String, Token::ParameterToken] key
21
+ # @return [Object]
22
+ def get(key)
23
+ @bag.fetch(to_key(key))
24
+ end
25
+
26
+ # @param [Class, String, Token::ParameterToken] key
27
+ # @param [Object] value
28
+ def set(key, value)
29
+ @bag[to_key(key)] = value
30
+ end
31
+
32
+ private
33
+
34
+ def to_key(keylike)
35
+ if keylike.is_a?(Class)
36
+ keylike.name
37
+ elsif keylike.is_a?(Token::ParameterToken)
38
+ keylike.key
39
+ elsif keylike.is_a?(String)
40
+ keylike
41
+ else
42
+ raise StandardError.new("#{keylike} is not a valid key (objects of class #{keylike.class.name} are not handled.")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Corindon
4
- VERSION = '0.7.2'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corindon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Piotaix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +121,7 @@ files:
107
121
  - lib/corindon/dependency_injection/dsl.rb
108
122
  - lib/corindon/dependency_injection/injectable.rb
109
123
  - lib/corindon/dependency_injection/injector.rb
124
+ - lib/corindon/dependency_injection/parameter_bag.rb
110
125
  - lib/corindon/dependency_injection/ruby_compat.rb
111
126
  - lib/corindon/dependency_injection/testing/mock_utils.rb
112
127
  - lib/corindon/dependency_injection/token/injection_token.rb