infusible 0.0.0 → 0.2.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: 543c2fdc713060365fa86371145a08208b9cd2ad206ec02cd5307806a8991019
4
- data.tar.gz: 80d73a65ef4331bf57101dee0c3b0b60dfc6712e619fa91e943a6e51b851d171
3
+ metadata.gz: c106dc7bb956b3b25aaaa18c62161936ac579a1c81123bcb088374c50c43ceed
4
+ data.tar.gz: 386593b46595b16473ccc8daa6f13d4be885bf677244b7939dcb13bb718e2657
5
5
  SHA512:
6
- metadata.gz: 70104e261ff6722e591c442684e197663c67e30a9cf164d4a3b58d2418a8271fbeb11ecb010ef8a65efcedf9e2f2b651288db2e10029e3a94857f942ac58f781
7
- data.tar.gz: 9788f80e1bf860075eff3e12aa3168cb3481118976c8726bc82f7942563cde9a8b35e0ec836ad5eaa81d1764582d70ad348b44641a284e7e9df81e10a9c6d9fb
6
+ metadata.gz: 9930c6ea24fb9e165e7e534d4e01c07e542f522b60d33a2b5ba79a3dd72ed5ac8bc38422ec7f5554040aca1453b8dcad87dceee5bbd8d229c156be3474c158b3
7
+ data.tar.gz: a1506ef91768a9a1e46099f9b4d91a7ccdfc56f904a5e12172c2bf9ea920cb216c181f159637e834898ba110c5a674612e7dc822d0a986623b207ccd62673cba
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -158,7 +158,7 @@ class Pinger
158
158
  end
159
159
  ----
160
160
 
161
- The namespace _and_ delimiter (i.e. `primary.`) will be removed so only `http` and `logger` are defined for use (as shown in the `#call` method).
161
+ The namespace (i.e. `primary.`) _and_ delimiter (i.e. `.`) will be removed so only `http` and `logger` are defined for use (as shown in the `#call` method). Only dots (i.e. `.`) are allowed as the delimiter between namespace and dependency.
162
162
 
163
163
  ==== Aliases
164
164
 
@@ -300,7 +300,7 @@ end
300
300
  # Our import which defines our container for potential injection.
301
301
  Import = Infusible.with Container
302
302
 
303
- # Our action class which uses Auto Injector to inject our kernel dependency from our container.
303
+ # Our action class which injects our kernel dependency from our container.
304
304
  class Action
305
305
  include Import[:kernel]
306
306
 
@@ -389,7 +389,25 @@ end
389
389
 
390
390
  ⚠️ I mention `around` block support last because the caveat is that you can't use an `around` block with any RSpec test double since link:https://github.com/rspec/rspec-mocks/issues/1283[RSpec can't guarantee proper cleanup]. This is why the RSpec `before` and `after` blocks were used to guarantee proper setup and teardown. That said, you can use _fakes_ or any object you own which _isn't_ a RSpec test double but provides the Object API you need for testing purposes.
391
391
 
392
- == Architecture
392
+ == Development
393
+
394
+ To contribute, run:
395
+
396
+ [source,bash]
397
+ ----
398
+ git clone https://github.com/bkuhlmann/infusible
399
+ cd infusible
400
+ bin/setup
401
+ ----
402
+
403
+ You can also use the IRB console for direct access to all objects:
404
+
405
+ [source,bash]
406
+ ----
407
+ bin/console
408
+ ----
409
+
410
+ === Architecture
393
411
 
394
412
  This gem automates a lot of the boilerplate code you'd normally have to do manually by defining your constructor, initializer, and instance variables for you. Normally, when injecting dependencies, you'd do something like this (using the `Pinger` example provided earlier):
395
413
 
@@ -426,7 +444,7 @@ end
426
444
 
427
445
  Your constructor, initializer, and instance variables are all there. Only you don't have to write all of this yourself anymore. 🎉
428
446
 
429
- == Style Guide
447
+ === Style Guide
430
448
 
431
449
  When using this gem, along with a container like {dry-container_link}, make sure to adhere to the following guidelines:
432
450
 
@@ -435,15 +453,6 @@ When using this gem, along with a container like {dry-container_link}, make sure
435
453
  * 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.
436
454
  * Use `**dependencies` as your named double splat argument when defining an initializer which needs to pass injected dependencies upwards. This improves readability and consistency by clearly identifying your injected dependencies.
437
455
 
438
- == Development
439
-
440
- You can also use the IRB console for direct access to all objects:
441
-
442
- [source,bash]
443
- ----
444
- bin/console
445
- ----
446
-
447
456
  == Tests
448
457
 
449
458
  To test, run:
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 = "0.0.0"
5
+ spec.version = "0.2.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/infusible"
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
25
  spec.required_ruby_version = "~> 3.1"
26
- spec.add_dependency "marameters", "~> 0.8"
26
+ spec.add_dependency "marameters", "~> 0.10"
27
27
  spec.add_dependency "zeitwerk", "~> 2.6"
28
28
 
29
29
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
@@ -5,6 +5,16 @@ require "marameters"
5
5
  module Infusible
6
6
  # Provides the automatic and complete resolution of all injected dependencies.
7
7
  class Constructor < Module
8
+ def self.define_instance_variables target, names, keywords
9
+ names.each do |name|
10
+ next unless keywords.key?(name) || !target.instance_variable_defined?(:"@#{name}")
11
+
12
+ target.instance_variable_set :"@#{name}", keywords[name]
13
+ end
14
+ end
15
+
16
+ private_class_method :define_instance_variables
17
+
8
18
  def initialize container, *configuration
9
19
  super()
10
20
 
@@ -45,17 +55,19 @@ module Infusible
45
55
  break instance unless instance.only_bare_splats?
46
56
  end
47
57
 
58
+ variablizer = self.class.method :define_instance_variables
59
+
48
60
  if super_parameters.positionals? || super_parameters.only_single_splats?
49
- define_initialize_with_positionals super_parameters
61
+ define_initialize_with_positionals super_parameters, variablizer
50
62
  else
51
- define_initialize_with_keywords super_parameters
63
+ define_initialize_with_keywords super_parameters, variablizer
52
64
  end
53
65
  end
54
66
 
55
- def define_initialize_with_positionals super_parameters
56
- instance_module.class_exec dependencies.names, method(:define_variables) do |names, definer|
67
+ def define_initialize_with_positionals super_parameters, variablizer
68
+ instance_module.class_exec dependencies.names, variablizer do |names, definer|
57
69
  define_method :initialize do |*positionals, **keywords, &block|
58
- definer.call self, keywords
70
+ definer.call self, names, keywords
59
71
 
60
72
  if super_parameters.only_single_splats?
61
73
  super(*positionals, **keywords, &block)
@@ -66,24 +78,15 @@ module Infusible
66
78
  end
67
79
  end
68
80
 
69
- def define_initialize_with_keywords super_parameters
70
- instance_module.class_exec dependencies.names, method(:define_variables) do |names, definer|
81
+ def define_initialize_with_keywords super_parameters, variablizer
82
+ instance_module.class_exec dependencies.names, variablizer do |names, definer|
71
83
  define_method :initialize do |**keywords, &block|
72
- definer.call self, keywords
84
+ definer.call self, names, keywords
73
85
  super(**super_parameters.keyword_slice(keywords, keys: names), &block)
74
86
  end
75
87
  end
76
88
  end
77
89
 
78
- # :reek:FeatureEnvy
79
- def define_variables target, keywords
80
- dependencies.names.each do |name|
81
- next unless keywords.key?(name) || !target.instance_variable_defined?(:"@#{name}")
82
-
83
- target.instance_variable_set :"@#{name}", keywords[name]
84
- end
85
- end
86
-
87
90
  def define_readers
88
91
  methods = dependencies.names.map { |name| ":#{name}" }
89
92
 
@@ -3,12 +3,12 @@
3
3
  module Infusible
4
4
  # Sanitizes and resolves dependencies for use.
5
5
  class DependencyMap
6
- NAME_PATTERN = /([a-z_][a-zA-Z_0-9]*)$/
6
+ PATTERNS = {name: /([a-z_][a-zA-Z_0-9]*)$/, valid: /^[\w.]+$/}.freeze
7
7
 
8
8
  attr_reader :names
9
9
 
10
- def initialize *configuration, name_pattern: NAME_PATTERN
11
- @name_pattern = name_pattern
10
+ def initialize *configuration, patterns: PATTERNS
11
+ @patterns = patterns
12
12
  @collection = {}
13
13
 
14
14
  configuration = configuration.dup
@@ -24,10 +24,14 @@ module Infusible
24
24
 
25
25
  private
26
26
 
27
- attr_reader :name_pattern, :collection
27
+ attr_reader :patterns, :collection
28
28
 
29
29
  def to_name identifier
30
- identifier.to_s[name_pattern] || fail(Errors::InvalidDependency.new(identifier:))
30
+ name = identifier[patterns.fetch(:name)]
31
+
32
+ return name if name && name.match?(patterns.fetch(:valid))
33
+
34
+ fail(Errors::InvalidDependency.new(identifier:))
31
35
  end
32
36
 
33
37
  def add name, identifier
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: 0.0.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
29
29
  RFE=
30
30
  -----END CERTIFICATE-----
31
- date: 2022-09-05 00:00:00.000000000 Z
31
+ date: 2022-10-22 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: marameters
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.8'
39
+ version: '0.10'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.8'
46
+ version: '0.10'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: zeitwerk
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.3.21
106
+ rubygems_version: 3.3.24
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Automates the injection of dependencies into your class.
metadata.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- +ۏ[Gpз}�߮!�:;��� FE��c8�&ٍ;DH
2
- `��??����J 16 7��D��d ������^ΰR�jtk���O P����1b!��Z��8�Q����]Ɏ~��c�4�e��2��v���fiGw���)��2^Joߋy�<�+B6fw�ԮL�Q���</�k�ε%mM�sŐ2 �f�`ЌO=@S��4�<�
3
- Rd#O�uz�O��)���=W1������>��uRk�C��k�,�KFuu���
1
+ WX� ˔�S��|8�2�e�5y�Q~��B�������ܗz�������bkY��/��I��~Bܶ�
2
+ !;6��x���_�-���w�`�J|=k(ڷ��V�� ��Ì��̧'������ ���Ye���_2N��0��:`3�~oУn֩��-罘���'�?4��~�A[���6'�� 5s�������k��0�%�F �v������ĽsT���j�_D�'NgM��͠�e8��)�!�<