karafka-core 2.2.3 → 2.2.4
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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/karafka-core.gemspec +1 -1
- data/lib/karafka/core/configurable/leaf.rb +6 -1
- data/lib/karafka/core/configurable/node.rb +57 -8
- data/lib/karafka/core/configurable.rb +2 -2
- data/lib/karafka/core/version.rb +1 -1
- 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: 5725a5489ddec63bb880cba5cb2b2e69394f3aafeb573892c380c475812c2aa8
|
4
|
+
data.tar.gz: 4eafb4c97db61bae7373bed200f64329b440eae496d5712bd37374e0a20134dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9f1322799d2ecc16f930a1a2cf80c3e122b25101a32a8f3899e78df0ef1aba2dd4b97b7959c69c348d23cdaba2a65a287548a26022056f7b04714579df34f3
|
7
|
+
data.tar.gz: 13f54f8a7e697ce744ace8f5932d5ddeacb1a28fb181e8a1ac53e66e236b482bf3e3c3823161b33ed6e852f4301435d7b3d6ac5dc930450e27d93781f9c9dbf8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/karafka-core.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.metadata = {
|
33
33
|
'funding_uri' => 'https://karafka.io/#become-pro',
|
34
34
|
'homepage_uri' => 'https://karafka.io',
|
35
|
-
'changelog_uri' => 'https://
|
35
|
+
'changelog_uri' => 'https://karafka.io/docs/Changelog-Karafka-Core',
|
36
36
|
'bug_tracker_uri' => 'https://github.com/karafka/karafka-core/issues',
|
37
37
|
'source_code_uri' => 'https://github.com/karafka/karafka-core',
|
38
38
|
'documentation_uri' => 'https://karafka.io/docs',
|
@@ -4,11 +4,16 @@ module Karafka
|
|
4
4
|
module Core
|
5
5
|
module Configurable
|
6
6
|
# Single end config value representation
|
7
|
-
Leaf = Struct.new(:name, :default, :constructor, :compiled) do
|
7
|
+
Leaf = Struct.new(:name, :default, :constructor, :compiled, :lazy) do
|
8
8
|
# @return [Boolean] true if already compiled
|
9
9
|
def compiled?
|
10
10
|
compiled
|
11
11
|
end
|
12
|
+
|
13
|
+
# @return [Boolean] is this a lazy evaluated leaf
|
14
|
+
def lazy?
|
15
|
+
lazy == true
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
@@ -30,12 +30,13 @@ module Karafka
|
|
30
30
|
# @param name [Symbol] setting or nested node name
|
31
31
|
# @param default [Object] default value
|
32
32
|
# @param constructor [#call, nil] callable or nil
|
33
|
+
# @param lazy [Boolean] is this a lazy leaf
|
33
34
|
# @param block [Proc] block for nested settings
|
34
|
-
def setting(name, default: nil, constructor: nil, &block)
|
35
|
+
def setting(name, default: nil, constructor: nil, lazy: false, &block)
|
35
36
|
@children << if block
|
36
37
|
Node.new(name, block)
|
37
38
|
else
|
38
|
-
Leaf.new(name, default, constructor, false)
|
39
|
+
Leaf.new(name, default, constructor, false, lazy)
|
39
40
|
end
|
40
41
|
|
41
42
|
compile
|
@@ -95,27 +96,75 @@ module Karafka
|
|
95
96
|
@children.each do |value|
|
96
97
|
# Do not redefine something that was already set during compilation
|
97
98
|
# This will allow us to reconfigure things and skip override with defaults
|
98
|
-
skippable = respond_to?(value.name)
|
99
|
+
skippable = respond_to?(value.name) || (value.is_a?(Leaf) && value.compiled?)
|
100
|
+
lazy_leaf = value.is_a?(Leaf) && value.lazy?
|
99
101
|
|
100
|
-
|
102
|
+
# Do not create accessor for leafs that are lazy as they will get a custom method
|
103
|
+
# created instead
|
104
|
+
singleton_class.attr_accessor(value.name) unless lazy_leaf
|
101
105
|
|
102
106
|
next if skippable
|
103
107
|
|
104
108
|
initialized = if value.is_a?(Leaf)
|
105
|
-
next if value.compiled?
|
106
|
-
|
107
109
|
value.compiled = true
|
108
|
-
|
110
|
+
|
111
|
+
if value.constructor && value.lazy?
|
112
|
+
false
|
113
|
+
elsif value.constructor
|
114
|
+
call_constructor(value)
|
115
|
+
else
|
116
|
+
value.default
|
117
|
+
end
|
109
118
|
else
|
110
119
|
value.compile
|
111
120
|
value
|
112
121
|
end
|
113
122
|
|
114
|
-
|
123
|
+
if lazy_leaf && !initialized
|
124
|
+
build_dynamic_accessor(value)
|
125
|
+
else
|
126
|
+
public_send("#{value.name}=", initialized)
|
127
|
+
end
|
115
128
|
end
|
116
129
|
|
117
130
|
@compiled = true
|
118
131
|
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# Defines a lazy evaluated read and writer that will re-evaluate in case value constructor
|
136
|
+
# evaluates to `nil` or `false`. This allows us to define dynamic constructors that
|
137
|
+
# can react to external conditions to become expected value once this value is
|
138
|
+
# available
|
139
|
+
#
|
140
|
+
# @param value [Leaf]
|
141
|
+
def build_dynamic_accessor(value)
|
142
|
+
singleton_class.attr_writer(value.name)
|
143
|
+
|
144
|
+
define_singleton_method(value.name) do
|
145
|
+
existing = instance_variable_get("@#{value.name}")
|
146
|
+
|
147
|
+
return existing if existing
|
148
|
+
|
149
|
+
built = call_constructor(value)
|
150
|
+
|
151
|
+
instance_variable_set("@#{value.name}", built)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Runs the constructor with or without the default depending on its arity and returns the
|
156
|
+
# result
|
157
|
+
#
|
158
|
+
# @param value [Leaf]
|
159
|
+
def call_constructor(value)
|
160
|
+
constructor = value.constructor
|
161
|
+
|
162
|
+
if constructor.arity.zero?
|
163
|
+
constructor.call
|
164
|
+
else
|
165
|
+
constructor.call(value.default)
|
166
|
+
end
|
167
|
+
end
|
119
168
|
end
|
120
169
|
end
|
121
170
|
end
|
@@ -65,14 +65,14 @@ module Karafka
|
|
65
65
|
|
66
66
|
# Two versions are needed to pass arguments in the correct way
|
67
67
|
if RUBY_VERSION >= '2.7'
|
68
|
-
class_eval <<~CODE, __FILE__, __LINE__
|
68
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
69
69
|
# Pipes the settings setup to the config root node
|
70
70
|
def setting(...)
|
71
71
|
config.setting(...)
|
72
72
|
end
|
73
73
|
CODE
|
74
74
|
else
|
75
|
-
class_eval <<~CODE, __FILE__, __LINE__
|
75
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
76
76
|
# Pipes the settings setup to the config root node
|
77
77
|
# @param args [Object] anything provided to settings
|
78
78
|
# @param block [Proc] block for settings
|
data/lib/karafka/core/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karafka-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
|
36
36
|
msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2023-10-
|
38
|
+
date: 2023-10-25 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: concurrent-ruby
|
@@ -128,7 +128,7 @@ licenses:
|
|
128
128
|
metadata:
|
129
129
|
funding_uri: https://karafka.io/#become-pro
|
130
130
|
homepage_uri: https://karafka.io
|
131
|
-
changelog_uri: https://
|
131
|
+
changelog_uri: https://karafka.io/docs/Changelog-Karafka-Core
|
132
132
|
bug_tracker_uri: https://github.com/karafka/karafka-core/issues
|
133
133
|
source_code_uri: https://github.com/karafka/karafka-core
|
134
134
|
documentation_uri: https://karafka.io/docs
|
metadata.gz.sig
CHANGED
Binary file
|