infusible 2.2.1 → 3.1.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: 870b107724590e3bc2299263db39c125af05713798884f8134d535e5b33da4c0
4
- data.tar.gz: 80f0b9ece613b463da8fad3d6be1a0f9433e0af99dba4fe899a37fafffbce62a
3
+ metadata.gz: aead1f7ed51f9d27432c30d1eed5281acf00492d0d3a28122bbea6c816c76c5f
4
+ data.tar.gz: e24374e305cc022c120fcb914631691cc7a0f0a7acbad0d438da0ef5958786d5
5
5
  SHA512:
6
- metadata.gz: cef17b734b179f78de093ce80ba28911ab039f33d2c086c70c5a99d063e07a91e860a575989874f77dcd98add7fed5829c36d59b0f35787ca0dd69de8815dc4a
7
- data.tar.gz: 8ac52b78bc174842c896d09cd8dbffe070dcec75ac219874a7b52cd37cbca97c2c91297602b229916f102eb94d45110e6053999b5b011f3f5a0cd30ebe570a1b
6
+ metadata.gz: a78bd3911d1f83ab17f8cf1f4b814ef1b5790b3cdeb7ac5c3ae8823c87a7b662c8926ff158251cd9ab184cc540e7dde6410a424b9c19f07c35c24d3246a67f04
7
+ data.tar.gz: 5a5e117cf6173e932aeafb1126e40dae5297fcb86acd87d6daa55b4adebeae29b7b0d382bc17f32431ee5fab01977d4d758130376fa97d7ceb696ec021822eb1
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -326,6 +326,40 @@ demo.two # NoMethodError: protected method.
326
326
  demo.three # NoMethodError: private method.
327
327
  ----
328
328
 
329
+ ==== Infused Keys
330
+
331
+ You have access to the keys of all infused dependencies via the _private_ `infused_keys` method which can be powerful in metaprogramming situations. For example, consider the following, which calls all injected dependencies since they have the same Object API (i.e. `#call`):
332
+
333
+ Example:
334
+
335
+ [source,ruby]
336
+ ----
337
+ module Container
338
+ extend Dry::Container::Mixin
339
+
340
+ register(:one, proc { puts "One" }, call: false)
341
+ register(:two, proc { puts "Two" }, call: false)
342
+ end
343
+
344
+ Import = Infusible.with Container
345
+
346
+ class Demo
347
+ include Import[:one, :two]
348
+
349
+ def call = infused_keys.each { |key| __send__(key).call }
350
+ end
351
+
352
+ Demo.new.call
353
+ # One
354
+ # Two
355
+ ----
356
+
357
+ As you can see, with the _private_ `#infused_keys` attribute reader, we were able to iterate through each infused key and send the `#call` message to each injected dependency.
358
+
359
+ 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 super class in the hierarchy will have it's own unique array of infused keys depending on what was injected for that object.
360
+
361
+ All infused keys are frozen by default.
362
+
329
363
  === Tests
330
364
 
331
365
  As you architect your implementation, you'll want to test your injected dependencies. You'll also want to stub, mock, or spy on them as well. Testing support is built-in for you by only needing to require the stub refinement as provided by this gem. For demonstration purposes, I'm going to assume you are using RSpec but you can adapt for whatever testing framework you are using.
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 = "2.2.1"
5
+ spec.version = "3.1.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.2", "<= 3.3"]
26
- spec.add_dependency "marameters", "~> 2.0"
25
+ spec.required_ruby_version = "~> 3.3"
26
+ spec.add_dependency "marameters", "~> 3.0"
27
27
  spec.add_dependency "zeitwerk", "~> 2.6"
28
28
 
29
29
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
@@ -7,6 +7,10 @@ module Infusible
7
7
  # :reek:TooManyInstanceVariables
8
8
  class Constructor < Module
9
9
  def self.define_instance_variables target, names, keywords
10
+ unless target.instance_variable_defined? :@infused_keys
11
+ target.instance_variable_set :@infused_keys, names
12
+ end
13
+
10
14
  names.each do |name|
11
15
  next unless keywords.key?(name) || !target.instance_variable_defined?(:"@#{name}")
12
16
 
@@ -94,6 +98,7 @@ module Infusible
94
98
  computed_scope = METHOD_SCOPES.include?(scope) ? scope : :private
95
99
 
96
100
  instance_module.module_eval <<-READERS, __FILE__, __LINE__ + 1
101
+ attr_reader :infused_keys
97
102
  #{computed_scope} attr_reader #{methods.join ", "}
98
103
  READERS
99
104
  end
@@ -11,13 +11,12 @@ module Infusible
11
11
  @patterns = patterns
12
12
  @collection = {}
13
13
 
14
- configuration = configuration.dup
15
14
  aliases = configuration.last.is_a?(Hash) ? configuration.pop : {}
16
15
 
17
16
  configuration.each { |identifier| add to_name(identifier), identifier }
18
17
  aliases.each { |name, identifier| add name, identifier }
19
18
 
20
- @names = collection.keys
19
+ @names = collection.keys.freeze
21
20
  end
22
21
 
23
22
  def to_h = collection
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infusible
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-11-16 00:00:00.000000000 Z
38
+ date: 2024-01-13 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: marameters
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.0'
46
+ version: '3.0'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '2.0'
53
+ version: '3.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: zeitwerk
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -101,10 +101,7 @@ require_paths:
101
101
  - lib
102
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: '3.2'
107
- - - "<="
104
+ - - "~>"
108
105
  - !ruby/object:Gem::Version
109
106
  version: '3.3'
110
107
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -113,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
110
  - !ruby/object:Gem::Version
114
111
  version: '0'
115
112
  requirements: []
116
- rubygems_version: 3.4.22
113
+ rubygems_version: 3.5.4
117
114
  signing_key:
118
115
  specification_version: 4
119
116
  summary: An automated dependency manager and injector.
metadata.gz.sig CHANGED
Binary file