infusible 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +2 -2
- data/infusible.gemspec +1 -1
- data/lib/infusible/constructor.rb +20 -17
- data/lib/infusible/dependency_map.rb +9 -5
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 178bec613d52f3563639135ef4a2faa4b61544e0087929c601807fc0db11f57d
|
4
|
+
data.tar.gz: 3ff1ecb8efb324e9758010f0798dca0777173caa6ee0da71eba26c3c80895303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
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
@@ -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,
|
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,
|
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
|
-
|
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,
|
11
|
-
@
|
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 :
|
27
|
+
attr_reader :patterns, :collection
|
28
28
|
|
29
29
|
def to_name identifier
|
30
|
-
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.
|
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-
|
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.
|
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
|