infusible 3.12.0 → 4.0.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: 4f8f3b8f6436cd0680e83f6fd85cf24a937564c532e30cb1ed673ae021cacba5
4
- data.tar.gz: 3b196093e64782508fc4a0ecd62f097e51558461ecd3f990dd167b7ac8d27b57
3
+ metadata.gz: 8aafcac6a14000c504e84fefaf288d754358473a8c5d339ee149608dcc9dae74
4
+ data.tar.gz: 5fb2e41cb5b78221c4988024b8d41c472610fefe15176f344a70d6de441b4449
5
5
  SHA512:
6
- metadata.gz: 256c3ddb473dd6a3c0ab609c104e7a464ecd65b6a43f25f751f8346dd48192b7422b8f8f5b751ee2db06e30867a048991d021c5c70dafe8f26eafa603addef58
7
- data.tar.gz: beeb2782f186e40cc56b7d4ad6a347e94fa9710627d330e3fef26db1300604fd39a7dd247844f874da831a6bdb18f37e418cc86acfc9dd6a6a44b9cdf2bdf888
6
+ metadata.gz: ed25aa5de1c5ab6b967d3000ba2fa3b12a63973e68a04f48a3d55adcb6ffcf41140061bb208b091f5de249036f0ea826999f6f506fb6db2e6cc283e98b15a215
7
+ data.tar.gz: 38506f23c2abf7450dd61ca7888b606cec74cb290cc173c789aa886006cf925398bf6c56c2e99ebb1331018fa8ed8129ec98392620120db3c475e6f2dc89263d
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -14,10 +14,10 @@ When coupled with {dependency_injection_containers_link}, as provided by the {co
14
14
 
15
15
  [source,ruby]
16
16
  ----
17
- Import = Infusible[a: 1, b: 2, c: 3]
17
+ Dependencies = Infusible[a: 1, b: 2, c: 3]
18
18
 
19
19
  class Demo
20
- include Import[:a, :b, :c]
20
+ include Dependencies[:a, :b, :c]
21
21
 
22
22
  def to_s = "My injected dependencies are: #{a}, #{b}, and #{c}."
23
23
  end
@@ -80,10 +80,10 @@ There is basic and advanced usage. We'll start with the basics and work our to m
80
80
  This gem requires three steps for proper use:
81
81
 
82
82
  . A container.
83
- . An import constant.
83
+ . A dependencies constant.
84
84
  . An object and/or multiple objects for dependencies to be injected into.
85
85
 
86
- Let's walk through each staring by defining a container of dependencies.
86
+ Let's walk through each by defining a container of dependencies.
87
87
 
88
88
  ==== Containers
89
89
 
@@ -105,25 +105,25 @@ module Container
105
105
  end
106
106
  ----
107
107
 
108
- ==== Imports
108
+ ==== Setup
109
109
 
110
- Once your container is defined, you'll want to define the corresponding import for reuse within your application. Defining an import only requires two lines of code:
110
+ Once your container is defined, you'll want to set it up for reuse within your application. This only requires two lines of code:
111
111
 
112
112
  [source,ruby]
113
113
  ----
114
114
  require "infusible"
115
115
 
116
- Import = Infusible[Container]
116
+ Dependencies = Infusible[Container]
117
117
  ----
118
118
 
119
119
  ==== Dependencies
120
120
 
121
- With your container and import defined, you can inject your dependencies by including what you need:
121
+ With your container configured for injection, you can inject your dependencies by including what you need:
122
122
 
123
123
  [source,ruby]
124
124
  ----
125
125
  class Pinger
126
- include Import[:http, :logger]
126
+ include Dependencies[:http, :logger]
127
127
 
128
128
  def call url
129
129
  http.get(url).status.then { |status| logger.info %(The status of "#{url}" is #{status}.) }
@@ -150,7 +150,7 @@ You can use symbols, strings, or a combination of both when defining which depen
150
150
  [source,ruby]
151
151
  ----
152
152
  class Pinger
153
- include Import[:http, "logger"]
153
+ include Dependencies[:http, "logger"]
154
154
 
155
155
  def call = puts "Using: #{http.inspect} and #{logger.inspect}."
156
156
  end
@@ -163,7 +163,7 @@ To access namespaced dependencies within a container, you only need to provide t
163
163
  [source,ruby]
164
164
  ----
165
165
  class Pinger
166
- include Import["primary.http", "primary.logger"]
166
+ include Dependencies["primary.http", "primary.logger"]
167
167
 
168
168
  def call = puts "Using: #{http.inspect} and #{logger.inspect}."
169
169
  end
@@ -178,7 +178,7 @@ Should you want to rename your namespaced dependencies to something more appropr
178
178
  [source,ruby]
179
179
  ----
180
180
  class Pinger
181
- include Import[client: "primary.http"]
181
+ include Dependencies[client: "primary.http"]
182
182
 
183
183
  def call = puts "Using: #{client.inspect}."
184
184
  end
@@ -191,7 +191,7 @@ You can also mix names, namespaces, and aliases for injection as long as the ali
191
191
  [source,ruby]
192
192
  ----
193
193
  class Pinger
194
- include Import[:configuration, "primary.logger", client: :http]
194
+ include Dependencies[:configuration, "primary.logger", client: :http]
195
195
 
196
196
  def call = puts "Using: #{configuration.inspect}, #{logger.inspect}, and #{client.inspect}."
197
197
  end
@@ -204,7 +204,7 @@ Earlier, when demonstrating basic usage, all dependencies were injected by defau
204
204
  [source,ruby]
205
205
  ----
206
206
  class Pinger
207
- include Import[:http, :logger]
207
+ include Dependencies[:http, :logger]
208
208
  end
209
209
  ----
210
210
 
@@ -213,11 +213,11 @@ end
213
213
  [source,ruby]
214
214
  ----
215
215
  class Downloader
216
- include Import[:http]
216
+ include Dependencies[:http]
217
217
  end
218
218
  ----
219
219
 
220
- This allows you to reuse `Import` in as many situations as makes sense while improving performance.
220
+ This allows you to reuse `Dependencies` in as many situations as makes sense while improving performance.
221
221
 
222
222
  ==== Custom Initialization
223
223
 
@@ -226,7 +226,7 @@ Should you want to use injection in combination with your own initializer, you'l
226
226
  [source,ruby]
227
227
  ----
228
228
  class Pinger
229
- include Import[:logger]
229
+ include Dependencies[:logger]
230
230
 
231
231
  def initialize(http: HTTP, **)
232
232
  super(**)
@@ -258,7 +258,7 @@ class Parent
258
258
  end
259
259
 
260
260
  class Child < Parent
261
- include Import[:logger]
261
+ include Dependencies[:logger]
262
262
  end
263
263
  ----
264
264
 
@@ -267,11 +267,11 @@ In the above situation, the child's logger will be the logger that is injected w
267
267
  [source,ruby]
268
268
  ----
269
269
  class Parent
270
- include GeneralImport[:logger]
270
+ include GeneralDependencies[:logger]
271
271
  end
272
272
 
273
273
  class Child < Parent
274
- include Import[:logger]
274
+ include Dependencies[:logger]
275
275
  end
276
276
  ----
277
277
 
@@ -280,25 +280,25 @@ Once again, the child's logger will take precedence over the what is provided by
280
280
  [source,ruby]
281
281
  ----
282
282
  class Parent
283
- include Import[:logger]
283
+ include Dependencies[:logger]
284
284
  end
285
285
 
286
286
  class Child < Parent
287
- include Import[:http]
287
+ include Dependencies[:http]
288
288
  end
289
289
  ----
290
290
 
291
291
  With the above, the child class will have access to both the `logger` and `http` dependencies.
292
292
 
293
- ⚠️ Be careful when using parent dependencies within your child classes since they are _private by default_. Even though you can reach them, they might change, which can break your downstream dependencies and probably should be avoided or at least defined as `protected` by your parent objects in order to avoid breaking the parent/child relationship.
293
+ ⚠️ Be careful when using parent dependencies within your child classes since they are _private by default_. Even though you can reach them, they might change, which can break downstream dependencies and should be avoided. To prevent this, use `protected` injection via your parent objects in order to avoid breaking the parent/child relationship (this is explained further below).
294
294
 
295
295
  ==== Scopes
296
296
 
297
297
  By default -- and in all of the examples shown so far -- your dependencies are private by default when injected but you can make them public or protected. Here's a quick guide:
298
298
 
299
- * `include Import[:logger]`: Injects a _private_ logger dependency.
300
- * `include Import.protected(logger)`: Injects a _protected_ logger dependency. Useful with inheritance and a subclass that needs access to the dependency.
301
- * `include Import.public(:logger)`: Injects a _public_ logger dependency.
299
+ * `include Dependencies[:logger]`: Injects a _private_ logger dependency.
300
+ * `include Dependencies.protected(logger)`: Injects a _protected_ logger dependency. Useful with inheritance and a subclass that needs access to the dependency.
301
+ * `include Dependencies.public(:logger)`: Injects a _public_ logger dependency.
302
302
 
303
303
  There is no `+#private+` method since `#[]` does this for you and is _recommended practice_. Use of `+#public+` and `+#protected+` should be used sparingly or not at all if you can avoid it. Here's an example where public, protected, and private dependencies are injected:
304
304
 
@@ -312,12 +312,12 @@ module Container
312
312
  register :three, "Three"
313
313
  end
314
314
 
315
- Import = Infusible[Container]
315
+ Dependencies = Infusible[Container]
316
316
 
317
317
  class Demo
318
- include Import.public(:one)
319
- include Import.protected(:two)
320
- include Import[:three]
318
+ include Dependencies.public(:one)
319
+ include Dependencies.protected(:two)
320
+ include Dependencies[:three]
321
321
  end
322
322
 
323
323
  demo = Demo.new
@@ -342,10 +342,10 @@ module Container
342
342
  register :two, "Two"
343
343
  end
344
344
 
345
- Import = Infusible[Container]
345
+ Dependencies = Infusible[Container]
346
346
 
347
347
  class Demo
348
- include Import[:one, :two]
348
+ include Dependencies[:one, :two]
349
349
 
350
350
  def call = infused_keys.each { |key| puts __send__(key) }
351
351
  end
@@ -359,7 +359,7 @@ As you can see, with the _private_ `#infused_keys` attribute reader, we are able
359
359
 
360
360
  Since `#infused_keys` is a private attribute reader, this means the infused keys are private to each instance. This includes all ancestors when using inheritance as each parent class in the hierarchy will have it's own unique array of infused keys depending on what was injected for that object.
361
361
 
362
- All infused keys are frozen by default.
362
+ All infused keys are frozen by default as well.
363
363
 
364
364
  === Tests
365
365
 
@@ -375,11 +375,11 @@ module Container
375
375
  end
376
376
 
377
377
  # Our import which defines our container for potential injection.
378
- Import = Infusible[Container]
378
+ Dependencies = Infusible[Container]
379
379
 
380
380
  # Our action class which injects our kernel dependency from our container.
381
381
  class Action
382
- include Import[:kernel]
382
+ include Dependencies[:kernel]
383
383
 
384
384
  def call = kernel.puts "This is a test."
385
385
  end
@@ -487,7 +487,7 @@ When you use this gem all of the construction, initialization, and setting of pr
487
487
  [source,ruby]
488
488
  ----
489
489
  class Pinger
490
- include Import[:http, :logger]
490
+ include Dependencies[:http, :logger]
491
491
 
492
492
  def call url
493
493
  http.get(url).status.then { |status| logger.info %(The status of "#{url}" is #{status}.) }
@@ -503,9 +503,9 @@ When using this gem, along with a container like {containable_link}, make sure t
503
503
 
504
504
  * Use containers to group related dependencies that make logical sense for the namespace you are working in and avoid using containers as a junk drawer for throwing random objects in.
505
505
  * Use containers that don't have a lot of registered dependencies. If you register too many dependencies, that means your objects are too complex and need to be simplified further.
506
- * Use the `Import` constant to define _what_ is possible to import much like you'd use a `Container` to define your dependencies. Defining what is importable improves performance and should be defined in separate files for improved fuzzy file finding.
506
+ * Use the `Dependencies` constant to define _what_ is possible to inject much like you'd use a `Container` to define your dependencies. Defining what is importable improves performance and should be defined in separate files for improved fuzzy file finding.
507
507
  * Use `**` to forward keyword arguments when defining an initializer which needs to pass injected dependencies upwards.
508
- * Prefer `Import#[]` over the use of `Import#public` and/or `Import#protected` as much as a possible since injected dependencies should be private, by default, in order to not break encapsulation. That said, there are times where making them public and/or protected can save you from writing boilerplate code.
508
+ * Prefer `Dependencies#[]` over the use of `Dependencies#public` and/or `Dependencies#protected` as much as a possible since injected dependencies should be private, by default, in order to not break encapsulation. That said, there are times where making them public and/or protected can save you from writing boilerplate code.
509
509
 
510
510
  == Tests
511
511
 
data/infusible.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "infusible"
5
- spec.version = "3.12.0"
5
+ spec.version = "4.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/infusible"
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.signing_key = Gem.default_key_path
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
- spec.required_ruby_version = ">= 3.3", "<= 3.4"
26
- spec.add_dependency "marameters", "~> 3.12"
25
+ spec.required_ruby_version = "~> 3.4"
26
+ spec.add_dependency "marameters", "~> 4.0"
27
27
 
28
28
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
29
29
  spec.files = Dir["*.gemspec", "lib/**/*"]
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Infusible
4
- # Associates the container with the constructor for actualization.
4
+ # Associates the container with the builder for actualization.
5
5
  class Actuator
6
- def initialize container, constructor: Infusible::Builder
6
+ def initialize container, builder: Infusible::Builder
7
7
  @container = container
8
- @constructor = constructor
8
+ @builder = builder
9
9
  end
10
10
 
11
- def [](*configuration) = constructor.new container, *configuration
11
+ def [](*configuration) = builder.new container, *configuration
12
12
 
13
- def public(*configuration) = constructor.new container, *configuration, scope: __method__
13
+ def public(*configuration) = builder.new container, *configuration, scope: __method__
14
14
 
15
- def protected(*configuration) = constructor.new container, *configuration, scope: __method__
15
+ def protected(*configuration) = builder.new container, *configuration, scope: __method__
16
16
 
17
17
  private
18
18
 
19
- attr_reader :container, :constructor
19
+ attr_reader :container, :builder
20
20
  end
21
21
  end
@@ -8,7 +8,6 @@ module Infusible
8
8
  class Builder < Module
9
9
  def self.define_instance_variables target, keys, keywords
10
10
  unless target.instance_variable_defined? :@infused_keys
11
- target.instance_variable_set :@infused_names, keys
12
11
  target.instance_variable_set :@infused_keys, keys
13
12
  end
14
13
 
@@ -107,13 +106,6 @@ module Infusible
107
106
 
108
107
  instance_module.module_eval <<-READERS, __FILE__, __LINE__ + 1
109
108
  attr_reader :infused_keys
110
-
111
- def infused_names
112
- warn "`Inusible#infused_names` is deprecated, use `#infused_keys` instead.",
113
- category: :deprecated
114
- @infused_names
115
- end
116
-
117
109
  #{computed_scope} attr_reader #{methods.join ", "}
118
110
  READERS
119
111
  end
data/lib/infusible.rb CHANGED
@@ -11,9 +11,4 @@ module Infusible
11
11
  METHOD_SCOPES = %i[public protected private].freeze
12
12
 
13
13
  def self.[](container) = Actuator.new container
14
-
15
- def self.with container
16
- warn "`Infusible.#{__method__}` is deprecated, use `.[]` instead.", category: :deprecated
17
- Actuator.new container
18
- end
19
14
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infusible
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -35,7 +34,7 @@ cert_chain:
35
34
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
35
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
36
  -----END CERTIFICATE-----
38
- date: 2024-11-09 00:00:00.000000000 Z
37
+ date: 2024-12-27 00:00:00.000000000 Z
39
38
  dependencies:
40
39
  - !ruby/object:Gem::Dependency
41
40
  name: marameters
@@ -43,15 +42,14 @@ dependencies:
43
42
  requirements:
44
43
  - - "~>"
45
44
  - !ruby/object:Gem::Version
46
- version: '3.12'
45
+ version: '4.0'
47
46
  type: :runtime
48
47
  prerelease: false
49
48
  version_requirements: !ruby/object:Gem::Requirement
50
49
  requirements:
51
50
  - - "~>"
52
51
  - !ruby/object:Gem::Version
53
- version: '3.12'
54
- description:
52
+ version: '4.0'
55
53
  email:
56
54
  - brooke@alchemists.io
57
55
  executables: []
@@ -69,7 +67,6 @@ files:
69
67
  - lib/infusible/dependency_map.rb
70
68
  - lib/infusible/errors/duplicate_dependency.rb
71
69
  - lib/infusible/errors/invalid_dependency.rb
72
- - lib/infusible/stub.rb
73
70
  homepage: https://alchemists.io/projects/infusible
74
71
  licenses:
75
72
  - Hippocratic-2.1
@@ -81,16 +78,12 @@ metadata:
81
78
  label: Infusible
82
79
  rubygems_mfa_required: 'true'
83
80
  source_code_uri: https://github.com/bkuhlmann/infusible
84
- post_install_message:
85
81
  rdoc_options: []
86
82
  require_paths:
87
83
  - lib
88
84
  required_ruby_version: !ruby/object:Gem::Requirement
89
85
  requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: '3.3'
93
- - - "<="
86
+ - - "~>"
94
87
  - !ruby/object:Gem::Version
95
88
  version: '3.4'
96
89
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -99,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
92
  - !ruby/object:Gem::Version
100
93
  version: '0'
101
94
  requirements: []
102
- rubygems_version: 3.5.23
103
- signing_key:
95
+ rubygems_version: 3.6.2
104
96
  specification_version: 4
105
97
  summary: An automatic dependency injector.
106
98
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "infusible"
4
-
5
- module Infusible
6
- # Provides stubbing of the injected container when used in a test framework.
7
- module Stub
8
- refine Actuator do
9
- def stub_with(pairs, &)
10
- warn "`#{self.class}##{__method__}` is deprecated, use the Containable gem instead.",
11
- category: :deprecated
12
-
13
- return unless block_given?
14
-
15
- container.is_a?(Hash) ? stub_hash_with(pairs, &) : stub_container_with(pairs, &)
16
- end
17
-
18
- def stub pairs
19
- warn "`#{self.class}##{__method__}` is deprecated, use the Containable gem instead",
20
- category: :deprecated
21
-
22
- container.is_a?(Hash) ? stub_hash(pairs) : stub_container(pairs)
23
- end
24
-
25
- def unstub(*keys)
26
- warn "`#{self.class}##{__method__}` is deprecated, use the Containable gem instead",
27
- category: :deprecated
28
-
29
- container.is_a?(Hash) ? unstub_hash(*keys) : unstub_container(*keys)
30
- end
31
-
32
- private
33
-
34
- def stub_container_with pairs
35
- stub_container pairs
36
- yield
37
- unstub_container(*pairs.keys)
38
- end
39
-
40
- def stub_container pairs
41
- container.enable_stubs!
42
- pairs.each { |key, value| container.stub key, value }
43
- end
44
-
45
- def unstub_container(*keys) = keys.each { |key| container.unstub key }
46
-
47
- def stub_hash_with pairs
48
- stub_hash pairs
49
- yield
50
- unstub_hash(*pairs.keys)
51
- end
52
-
53
- def stub_hash pairs
54
- @backup = container.dup
55
- container.merge! pairs
56
- end
57
-
58
- def unstub_hash(*keys) = container.merge! @backup.slice(*keys)
59
- end
60
- end
61
- end