dry-initializer 3.1.0 → 3.2.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
- data/CHANGELOG.md +21 -0
- data/LICENSE +1 -1
- data/README.md +4 -12
- data/dry-initializer.gemspec +2 -2
- data/lib/dry/initializer/builders/attribute.rb +8 -14
- data/lib/dry/initializer/builders/initializer.rb +1 -1
- data/lib/dry/initializer/builders/reader.rb +2 -2
- data/lib/dry/initializer/config.rb +6 -6
- data/lib/dry/initializer/definition.rb +5 -5
- data/lib/dry/initializer/dispatchers/build_nested_type.rb +1 -2
- data/lib/dry/initializer/dispatchers/check_type.rb +1 -1
- data/lib/dry/initializer/dispatchers/prepare_default.rb +3 -3
- data/lib/dry/initializer/dispatchers/prepare_ivar.rb +1 -1
- data/lib/dry/initializer/dispatchers/prepare_optional.rb +1 -1
- data/lib/dry/initializer/dispatchers/prepare_reader.rb +1 -1
- data/lib/dry/initializer/dispatchers/prepare_target.rb +1 -1
- data/lib/dry/initializer/dispatchers/unwrap_type.rb +1 -1
- data/lib/dry/initializer/dispatchers.rb +2 -2
- data/lib/dry/initializer/dsl.rb +3 -3
- data/lib/dry/initializer/mixin/root.rb +2 -2
- data/lib/dry/initializer/mixin.rb +1 -1
- data/lib/dry/initializer/version.rb +1 -1
- data/lib/dry/initializer.rb +0 -1
- metadata +8 -9
- data/lib/dry/initializer/errors.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be50d677121c471c7921e3ad842921e172fa29bef381290012a0f2a4a11980d9
|
4
|
+
data.tar.gz: 02cb06be56f166c3eacec5f29ecef2589611123467c23eccd912e44632b50f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c2f86f9a06c429cd53c4452e200ac85e889ca536140fa83fbeb488e11317d1c0f4585903542d865be713cd44f86a38b1647de096994ae801afa8fed912d117
|
7
|
+
data.tar.gz: 8af84416c708e34373d30810f8e04ca4249f0ee6f2ccff6d49dd4a4477112354370c71ce5263dc5c1ff276b107617156377ae186a9ffc53a453753f154695b7b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 3.2.0 2025-01-01
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- Set minimal supported Ruby version to 3.1 (@flash-gordon)
|
9
|
+
- Exclude block forwarding from `Root#initialize`. This helps
|
10
|
+
with tracking down calls that shouldn't pass a block in Ruby 3.4 (see #109) (@flash-gordon)
|
11
|
+
|
12
|
+
|
13
|
+
[Compare v3.1.1...v3.2.0](https://github.com/dry-rb/dry-initializer/compare/v3.1.1...v3.2.0)
|
14
|
+
|
15
|
+
## 3.1.1 2022-01-19
|
16
|
+
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Improved error messages were rolled back, they created an implicit dependency on dry-types (@flash-gordon)
|
21
|
+
|
22
|
+
[Compare v3.1.0...v3.1.1](https://github.com/dry-rb/dry-initializer/compare/v3.1.0...v3.1.1)
|
23
|
+
|
3
24
|
## 3.1.0 2022-01-16
|
4
25
|
|
5
26
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,21 @@
|
|
1
1
|
<!--- this file is synced from dry-rb/template-gem project -->
|
2
2
|
[gem]: https://rubygems.org/gems/dry-initializer
|
3
3
|
[actions]: https://github.com/dry-rb/dry-initializer/actions
|
4
|
-
[codacy]: https://www.codacy.com/gh/dry-rb/dry-initializer
|
5
|
-
[chat]: https://dry-rb.zulipchat.com
|
6
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-initializer
|
7
4
|
|
8
|
-
# dry-initializer [][gem]
|
11
|
-
[][actions]
|
12
|
-
[][codacy]
|
13
|
-
[][codacy]
|
14
|
-
[][inchpages]
|
5
|
+
# dry-initializer [][gem] [][actions]
|
15
6
|
|
16
7
|
## Links
|
17
8
|
|
18
9
|
* [User documentation](https://dry-rb.org/gems/dry-initializer)
|
19
10
|
* [API documentation](http://rubydoc.info/gems/dry-initializer)
|
11
|
+
* [Forum](https://discourse.dry-rb.org)
|
20
12
|
|
21
13
|
## Supported Ruby versions
|
22
14
|
|
23
15
|
This library officially supports the following Ruby versions:
|
24
16
|
|
25
|
-
* MRI `>=
|
26
|
-
* jruby `>= 9.
|
17
|
+
* MRI `>= 3.1.0`
|
18
|
+
* jruby `>= 9.4` (not tested on CI)
|
27
19
|
|
28
20
|
## License
|
29
21
|
|
data/dry-initializer.gemspec
CHANGED
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
-
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-initializer/blob/
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-initializer/blob/main/CHANGELOG.md"
|
26
26
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-initializer"
|
27
27
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-initializer/issues"
|
28
28
|
|
29
|
-
spec.required_ruby_version = ">=
|
29
|
+
spec.required_ruby_version = ">= 3.1.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
32
|
|
@@ -53,7 +53,7 @@ module Dry
|
|
53
53
|
|
54
54
|
def required_reader
|
55
55
|
"#{@val} = #{@opts}.fetch(:'#{@source}')" \
|
56
|
-
|
56
|
+
" { raise KeyError, \"\#{self.class}: #{@definition} is required\" }"
|
57
57
|
end
|
58
58
|
|
59
59
|
def definition_line
|
@@ -72,23 +72,17 @@ module Dry
|
|
72
72
|
return unless @type
|
73
73
|
|
74
74
|
arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#{@val} = #{@item}.type.call(#{type_call_params})
|
82
|
-
end
|
83
|
-
rescue Dry::Types::ConstraintError => e
|
84
|
-
raise Dry::Initializer::CoercionError.new(e, '#{@source}')
|
85
|
-
end
|
86
|
-
COERCE
|
75
|
+
|
76
|
+
if arity.equal?(1) || arity.negative?
|
77
|
+
"#{@val} = #{@item}.type.call(#{@val}) unless #{@null} == #{@val}"
|
78
|
+
else
|
79
|
+
"#{@val} = #{@item}.type.call(#{@val}, self) unless #{@null} == #{@val}"
|
80
|
+
end
|
87
81
|
end
|
88
82
|
|
89
83
|
def assignment_line
|
90
84
|
"#{@ivar} = #{@val}" \
|
91
|
-
|
85
|
+
" unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
|
92
86
|
end
|
93
87
|
end
|
94
88
|
end
|
@@ -28,8 +28,8 @@ module Dry
|
|
28
28
|
|
29
29
|
def undef_line
|
30
30
|
"undef :#{@target} if method_defined?(:#{@target})" \
|
31
|
-
|
32
|
-
|
31
|
+
" || private_method_defined?(:#{@target})" \
|
32
|
+
" || protected_method_defined?(:#{@target})"
|
33
33
|
end
|
34
34
|
|
35
35
|
def attribute_line
|
@@ -109,7 +109,7 @@ module Dry
|
|
109
109
|
def finalize
|
110
110
|
@definitions = final_definitions
|
111
111
|
check_order_of_params
|
112
|
-
mixin.class_eval(code)
|
112
|
+
mixin.class_eval(code, "#{__FILE__}:#{__LINE__} class_eval")
|
113
113
|
children.each(&:finalize)
|
114
114
|
self
|
115
115
|
end
|
@@ -140,11 +140,11 @@ module Dry
|
|
140
140
|
def add_definition(option, name, type, block, **opts)
|
141
141
|
opts = {
|
142
142
|
parent: extended_class,
|
143
|
-
option
|
144
|
-
null
|
143
|
+
option:,
|
144
|
+
null:,
|
145
145
|
source: name,
|
146
|
-
type
|
147
|
-
block
|
146
|
+
type:,
|
147
|
+
block:,
|
148
148
|
**opts
|
149
149
|
}
|
150
150
|
|
@@ -177,7 +177,7 @@ module Dry
|
|
177
177
|
current
|
178
178
|
elsif optional
|
179
179
|
raise SyntaxError, "#{extended_class}: required #{current}" \
|
180
|
-
|
180
|
+
" goes after optional #{optional}"
|
181
181
|
else
|
182
182
|
optional
|
183
183
|
end
|
@@ -19,7 +19,7 @@ module Dry
|
|
19
19
|
check_certainty!(source, type, block)
|
20
20
|
check_name!(target, block)
|
21
21
|
type ||= build_nested_type(parent, target, block)
|
22
|
-
{parent
|
22
|
+
{parent:, source:, target:, type:, **options}
|
23
23
|
end
|
24
24
|
# rubocop: enable Metrics/ParameterLists
|
25
25
|
|
@@ -58,7 +58,6 @@ module Dry
|
|
58
58
|
|
59
59
|
def build_struct(klass_name, block)
|
60
60
|
# rubocop: disable Security/Eval
|
61
|
-
# rubocop: disable Style/DocumentDynamicEvalDefinition
|
62
61
|
eval <<~RUBY, TOPLEVEL_BINDING, __FILE__, __LINE__ + 1
|
63
62
|
class #{klass_name} < Dry::Initializer::Struct
|
64
63
|
end
|
@@ -14,7 +14,7 @@ module Dry
|
|
14
14
|
default = callable! default
|
15
15
|
check_arity! default
|
16
16
|
|
17
|
-
{default
|
17
|
+
{default:, optional: (optional | default), **options}
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
@@ -38,8 +38,8 @@ module Dry
|
|
38
38
|
|
39
39
|
def invalid!(default)
|
40
40
|
raise TypeError, "The #{default.inspect} should be" \
|
41
|
-
|
42
|
-
|
41
|
+
" either convertable to proc with no arguments," \
|
42
|
+
" or respond to #call without arguments."
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# - `:source` -- the name of source option
|
10
10
|
# - `:target` -- the target name of the reader
|
11
11
|
# - `:reader` -- if the reader's privacy (:public, :protected, :private, nil)
|
12
|
-
# - `:ivar` -- the target
|
12
|
+
# - `:ivar` -- the target name of the variable
|
13
13
|
# - `:type` -- the callable coercer of the source value
|
14
14
|
# - `:optional` -- if the argument is optional
|
15
15
|
# - `:default` -- the proc returning the default value of the source value
|
@@ -88,7 +88,7 @@ module Dry
|
|
88
88
|
# @return [Hash<Symbol, Objct>] normalized set of options
|
89
89
|
#
|
90
90
|
def call(**options)
|
91
|
-
options = {null
|
91
|
+
options = {null:, **options}
|
92
92
|
pipeline.reduce(options) { |opts, dispatcher| dispatcher.call(**opts) }
|
93
93
|
end
|
94
94
|
|
data/lib/dry/initializer/dsl.rb
CHANGED
@@ -25,8 +25,8 @@ module Dry
|
|
25
25
|
# @return [Module]
|
26
26
|
# @yield proc defining params and options
|
27
27
|
def define(procedure = nil, &block)
|
28
|
-
config = Config.new(null:
|
29
|
-
config.instance_exec(&
|
28
|
+
config = Config.new(null:)
|
29
|
+
config.instance_exec(&procedure || block)
|
30
30
|
config.mixin.include Mixin::Root
|
31
31
|
config.mixin
|
32
32
|
end
|
@@ -34,7 +34,7 @@ module Dry
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def extended(klass)
|
37
|
-
config = Config.new(klass, null:
|
37
|
+
config = Config.new(klass, null:)
|
38
38
|
klass.send :instance_variable_set, :@dry_initializer, config
|
39
39
|
klass.include Mixin::Root
|
40
40
|
end
|
@@ -9,7 +9,7 @@ module Dry
|
|
9
9
|
# @deprecated
|
10
10
|
def self.extended(klass)
|
11
11
|
warn "[DEPRECATED] Use Dry::Initializer instead of its alias" \
|
12
|
-
|
12
|
+
" Dry::Initializer::Mixin. The later will be removed in v2.1.0"
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
data/lib/dry/initializer.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-initializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev (marshall-lee)
|
8
8
|
- Andrew Kozin (nepalez)
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -71,7 +71,6 @@ files:
|
|
71
71
|
- lib/dry/initializer/dispatchers/unwrap_type.rb
|
72
72
|
- lib/dry/initializer/dispatchers/wrap_type.rb
|
73
73
|
- lib/dry/initializer/dsl.rb
|
74
|
-
- lib/dry/initializer/errors.rb
|
75
74
|
- lib/dry/initializer/mixin.rb
|
76
75
|
- lib/dry/initializer/mixin/local.rb
|
77
76
|
- lib/dry/initializer/mixin/root.rb
|
@@ -85,10 +84,10 @@ licenses:
|
|
85
84
|
- MIT
|
86
85
|
metadata:
|
87
86
|
allowed_push_host: https://rubygems.org
|
88
|
-
changelog_uri: https://github.com/dry-rb/dry-initializer/blob/
|
87
|
+
changelog_uri: https://github.com/dry-rb/dry-initializer/blob/main/CHANGELOG.md
|
89
88
|
source_code_uri: https://github.com/dry-rb/dry-initializer
|
90
89
|
bug_tracker_uri: https://github.com/dry-rb/dry-initializer/issues
|
91
|
-
post_install_message:
|
90
|
+
post_install_message:
|
92
91
|
rdoc_options: []
|
93
92
|
require_paths:
|
94
93
|
- lib
|
@@ -96,15 +95,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
95
|
requirements:
|
97
96
|
- - ">="
|
98
97
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
98
|
+
version: 3.1.0
|
100
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
100
|
requirements:
|
102
101
|
- - ">="
|
103
102
|
- !ruby/object:Gem::Version
|
104
103
|
version: '0'
|
105
104
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
107
|
-
signing_key:
|
105
|
+
rubygems_version: 3.3.27
|
106
|
+
signing_key:
|
108
107
|
specification_version: 4
|
109
108
|
summary: DSL for declaring params and options of the initializer
|
110
109
|
test_files: []
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dry
|
4
|
-
module Initializer
|
5
|
-
class CoercionError < ::StandardError
|
6
|
-
def initialize(constraint_error, field)
|
7
|
-
@constraint_error = constraint_error
|
8
|
-
@field = field
|
9
|
-
super(message)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Ensure that the field name is in the error message
|
13
|
-
def message
|
14
|
-
if @constraint_error.message =~ /#{@field}/
|
15
|
-
@constraint_error.message
|
16
|
-
else
|
17
|
-
"#{@constraint_error.message} for field :#{@field}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|