infusible 0.0.0 → 0.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: 543c2fdc713060365fa86371145a08208b9cd2ad206ec02cd5307806a8991019
4
- data.tar.gz: 80d73a65ef4331bf57101dee0c3b0b60dfc6712e619fa91e943a6e51b851d171
3
+ metadata.gz: 178bec613d52f3563639135ef4a2faa4b61544e0087929c601807fc0db11f57d
4
+ data.tar.gz: 3ff1ecb8efb324e9758010f0798dca0777173caa6ee0da71eba26c3c80895303
5
5
  SHA512:
6
- metadata.gz: 70104e261ff6722e591c442684e197663c67e30a9cf164d4a3b58d2418a8271fbeb11ecb010ef8a65efcedf9e2f2b651288db2e10029e3a94857f942ac58f781
7
- data.tar.gz: 9788f80e1bf860075eff3e12aa3168cb3481118976c8726bc82f7942563cde9a8b35e0ec836ad5eaa81d1764582d70ad348b44641a284e7e9df81e10a9c6d9fb
6
+ metadata.gz: 4455f13436bee9d4b0658cdec1ae488f1103d633cbcbfd44a22c5397bf02889e83cad553551e0f284c487d35a8e9f4c82537ebab098b0b7eba0a7deb0936cf06
7
+ data.tar.gz: bf576ffa04bce9e9dfcc19b10199ffcea349f94dc1fcfb383d5d147c9073cb37c983bc9c50bcdde2482589a1413dcbbe09b37db6d344bd2741482a18c215c1b7
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
 
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.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/infusible"
@@ -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.1.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-09-12 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: marameters
@@ -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.22
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Automates the injection of dependencies into your class.
metadata.gz.sig CHANGED
Binary file