dry-initializer 2.4.0 → 3.0.3
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 +5 -5
- data/.codeclimate.yml +10 -21
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/custom_ci.yml +58 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +56 -0
- data/.gitignore +2 -0
- data/.rspec +1 -1
- data/.rubocop.yml +76 -25
- data/CHANGELOG.md +150 -14
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +25 -18
- data/Gemfile.devtools +16 -0
- data/Guardfile +3 -3
- data/LICENSE +20 -0
- data/README.md +17 -79
- data/Rakefile +4 -4
- data/benchmarks/compare_several_defaults.rb +27 -27
- data/benchmarks/plain_options.rb +14 -14
- data/benchmarks/plain_params.rb +22 -22
- data/benchmarks/with_coercion.rb +14 -14
- data/benchmarks/with_defaults.rb +17 -17
- data/benchmarks/with_defaults_and_coercion.rb +14 -14
- data/bin/.gitkeep +0 -0
- data/docsite/source/attributes.html.md +106 -0
- data/docsite/source/container-version.html.md +39 -0
- data/docsite/source/index.html.md +43 -0
- data/docsite/source/inheritance.html.md +43 -0
- data/docsite/source/optionals-and-defaults.html.md +130 -0
- data/docsite/source/options-tolerance.html.md +27 -0
- data/docsite/source/params-and-options.html.md +74 -0
- data/docsite/source/rails-support.html.md +101 -0
- data/docsite/source/readers.html.md +43 -0
- data/docsite/source/skip-undefined.html.md +59 -0
- data/docsite/source/type-constraints.html.md +160 -0
- data/dry-initializer.gemspec +13 -13
- data/lib/dry-initializer.rb +1 -1
- data/lib/dry/initializer.rb +17 -16
- data/lib/dry/initializer/builders.rb +2 -2
- data/lib/dry/initializer/builders/attribute.rb +16 -11
- data/lib/dry/initializer/builders/initializer.rb +9 -13
- data/lib/dry/initializer/builders/reader.rb +4 -2
- data/lib/dry/initializer/builders/signature.rb +3 -3
- data/lib/dry/initializer/config.rb +25 -12
- data/lib/dry/initializer/definition.rb +20 -71
- data/lib/dry/initializer/dispatchers.rb +101 -33
- data/lib/dry/initializer/dispatchers/build_nested_type.rb +59 -0
- data/lib/dry/initializer/dispatchers/check_type.rb +43 -0
- data/lib/dry/initializer/dispatchers/prepare_default.rb +40 -0
- data/lib/dry/initializer/dispatchers/prepare_ivar.rb +12 -0
- data/lib/dry/initializer/dispatchers/prepare_optional.rb +13 -0
- data/lib/dry/initializer/dispatchers/prepare_reader.rb +30 -0
- data/lib/dry/initializer/dispatchers/prepare_source.rb +28 -0
- data/lib/dry/initializer/dispatchers/prepare_target.rb +44 -0
- data/lib/dry/initializer/dispatchers/unwrap_type.rb +22 -0
- data/lib/dry/initializer/dispatchers/wrap_type.rb +28 -0
- data/lib/dry/initializer/mixin.rb +4 -4
- data/lib/dry/initializer/mixin/root.rb +1 -0
- data/lib/dry/initializer/struct.rb +39 -0
- data/lib/dry/initializer/undefined.rb +2 -0
- data/lib/dry/initializer/version.rb +5 -0
- data/lib/tasks/benchmark.rake +13 -13
- data/lib/tasks/profile.rake +16 -16
- data/project.yml +2 -0
- data/spec/attributes_spec.rb +7 -7
- data/spec/coercion_of_nil_spec.rb +25 -0
- data/spec/custom_dispatchers_spec.rb +6 -6
- data/spec/custom_initializer_spec.rb +2 -2
- data/spec/default_values_spec.rb +9 -9
- data/spec/definition_spec.rb +16 -12
- data/spec/invalid_default_spec.rb +2 -2
- data/spec/list_type_spec.rb +32 -0
- data/spec/missed_default_spec.rb +2 -2
- data/spec/nested_type_spec.rb +48 -0
- data/spec/optional_spec.rb +16 -16
- data/spec/options_tolerance_spec.rb +2 -2
- data/spec/public_attributes_utility_spec.rb +5 -5
- data/spec/reader_spec.rb +13 -13
- data/spec/repetitive_definitions_spec.rb +9 -9
- data/spec/several_assignments_spec.rb +9 -9
- data/spec/spec_helper.rb +6 -3
- data/spec/subclassing_spec.rb +5 -5
- data/spec/support/coverage.rb +7 -0
- data/spec/support/warnings.rb +7 -0
- data/spec/type_argument_spec.rb +15 -15
- data/spec/type_constraint_spec.rb +46 -28
- data/spec/value_coercion_via_dry_types_spec.rb +8 -8
- metadata +51 -34
- data/.travis.yml +0 -24
data/spec/type_argument_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require 'dry-types'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'type argument' do
|
4
4
|
before do
|
5
5
|
class Test::Foo
|
6
6
|
extend Dry::Initializer
|
7
|
-
param :foo, Dry::Types[
|
8
|
-
option :bar, Dry::Types[
|
7
|
+
param :foo, Dry::Types['strict.string']
|
8
|
+
option :bar, Dry::Types['strict.string']
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
context
|
13
|
-
subject { Test::Foo.new 1, bar:
|
12
|
+
context 'in case of param mismatch' do
|
13
|
+
subject { Test::Foo.new 1, bar: '2' }
|
14
14
|
|
15
|
-
it
|
16
|
-
expect { subject }.to raise_error
|
15
|
+
it 'raises TypeError' do
|
16
|
+
expect { subject }.to raise_error Dry::Types::ConstraintError, /1/
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
subject { Test::Foo.new
|
20
|
+
context 'in case of option mismatch' do
|
21
|
+
subject { Test::Foo.new '1', bar: 2 }
|
22
22
|
|
23
|
-
it
|
24
|
-
expect { subject }.to raise_error
|
23
|
+
it 'raises TypeError' do
|
24
|
+
expect { subject }.to raise_error Dry::Types::ConstraintError, /2/
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
29
|
-
subject { Test::Foo.new
|
28
|
+
context 'in case of match' do
|
29
|
+
subject { Test::Foo.new '1', bar: '2' }
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'completes the initialization' do
|
32
32
|
expect { subject }.not_to raise_error
|
33
33
|
end
|
34
34
|
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require 'dry-types'
|
2
2
|
|
3
|
-
describe
|
4
|
-
context
|
3
|
+
describe 'type constraint' do
|
4
|
+
context 'by a proc with 1 argument' do
|
5
5
|
before do
|
6
6
|
class Test::Foo
|
7
7
|
extend Dry::Initializer
|
8
|
-
param :
|
8
|
+
param :__foo__, proc(&:to_s), optional: true
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
subject { Test::Foo.new :foo }
|
13
13
|
|
14
|
-
it
|
15
|
-
expect(subject.
|
14
|
+
it 'coerces a value' do
|
15
|
+
expect(subject.__foo__).to eq 'foo'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
context
|
19
|
+
context 'by a proc with 2 arguments' do
|
20
20
|
before do
|
21
21
|
class Test::Foo
|
22
22
|
extend Dry::Initializer
|
@@ -26,53 +26,71 @@ describe "type constraint" do
|
|
26
26
|
|
27
27
|
subject { Test::Foo.new :foo }
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'coerces a value with self as a second argument' do
|
30
30
|
expect(subject.foo).to eq "#{subject.hash}:foo"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
34
|
+
context 'by dry-type' do
|
35
35
|
before do
|
36
|
-
|
36
|
+
constraint = self.constraint
|
37
|
+
|
38
|
+
Test::Foo = Class.new do
|
37
39
|
extend Dry::Initializer
|
38
|
-
param :foo,
|
40
|
+
param :foo, constraint, optional: true
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
context
|
43
|
-
|
44
|
+
context 'with a strict string' do
|
45
|
+
let(:constraint) { Dry::Types['strict.string'] }
|
46
|
+
|
47
|
+
context 'in case of mismatch' do
|
48
|
+
subject { Test::Foo.new 1 }
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
it 'raises ArgumentError' do
|
51
|
+
expect { subject }.to raise_error Dry::Types::ConstraintError, /1/
|
52
|
+
end
|
47
53
|
end
|
48
|
-
end
|
49
54
|
|
50
|
-
|
51
|
-
|
55
|
+
context 'in case of match' do
|
56
|
+
subject { Test::Foo.new 'foo' }
|
57
|
+
|
58
|
+
it 'completes the initialization' do
|
59
|
+
expect { subject }.not_to raise_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'if optional value not set' do
|
64
|
+
subject { Test::Foo.new }
|
52
65
|
|
53
|
-
|
54
|
-
|
66
|
+
it 'not applicable to Dry::Initializer::UNDEFINED' do
|
67
|
+
expect(subject.instance_variable_get(:@foo))
|
68
|
+
.to eq Dry::Initializer::UNDEFINED
|
69
|
+
end
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
58
|
-
context
|
59
|
-
|
73
|
+
context 'with a member array string' do
|
74
|
+
let(:constraint) { Dry::Types['array'].of(Dry::Types['strict.string']) }
|
75
|
+
|
76
|
+
context 'with arity other than 1' do
|
77
|
+
subject { Test::Foo.new ['foo'] }
|
60
78
|
|
61
|
-
|
62
|
-
|
63
|
-
|
79
|
+
it 'completes the initialization' do
|
80
|
+
expect { subject }.not_to raise_error
|
81
|
+
end
|
64
82
|
end
|
65
83
|
end
|
66
84
|
end
|
67
85
|
|
68
|
-
context
|
69
|
-
it
|
86
|
+
context 'by invalid constraint' do
|
87
|
+
it 'raises ArgumentError' do
|
70
88
|
expect do
|
71
89
|
class Test::Foo
|
72
90
|
extend Dry::Initializer
|
73
91
|
param :foo, type: String
|
74
92
|
end
|
75
|
-
end.to raise_error(
|
93
|
+
end.to raise_error(ArgumentError)
|
76
94
|
end
|
77
95
|
end
|
78
96
|
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require 'dry-types'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'value coercion via dry-types' do
|
4
4
|
before do
|
5
5
|
module Test::Types
|
6
|
-
include Dry
|
6
|
+
include Dry.Types
|
7
7
|
end
|
8
8
|
|
9
9
|
class Test::Foo
|
10
10
|
extend Dry::Initializer
|
11
11
|
|
12
12
|
param :foo, type: Test::Types::Coercible::String
|
13
|
-
option :bar, proc(&:to_i), default: proc {
|
13
|
+
option :bar, proc(&:to_i), default: proc { '16' }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
subject = Test::Foo.new :foo, bar:
|
17
|
+
it 'coerces assigned values' do
|
18
|
+
subject = Test::Foo.new :foo, bar: '13'
|
19
19
|
|
20
|
-
expect(subject.foo).to eql
|
20
|
+
expect(subject.foo).to eql 'foo'
|
21
21
|
expect(subject.bar).to eql 13
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'coerces defaults as well' do
|
25
25
|
subject = Test::Foo.new :foo
|
26
26
|
|
27
27
|
expect(subject.bar).to eql 16
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-initializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev (marshall-lee)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -39,50 +39,32 @@ dependencies:
|
|
39
39
|
- - ">"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '10'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: dry-types
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 0.5.1
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.5.1
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rubocop
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0.42'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0.42'
|
70
42
|
description:
|
71
43
|
email: andrew.kozin@gmail.com
|
72
44
|
executables: []
|
73
45
|
extensions: []
|
74
46
|
extra_rdoc_files:
|
75
47
|
- README.md
|
48
|
+
- LICENSE
|
76
49
|
- CHANGELOG.md
|
77
50
|
files:
|
78
51
|
- ".codeclimate.yml"
|
52
|
+
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
53
|
+
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
54
|
+
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
55
|
+
- ".github/workflows/custom_ci.yml"
|
56
|
+
- ".github/workflows/docsite.yml"
|
57
|
+
- ".github/workflows/sync_configs.yml"
|
79
58
|
- ".gitignore"
|
80
59
|
- ".rspec"
|
81
60
|
- ".rubocop.yml"
|
82
|
-
- ".travis.yml"
|
83
61
|
- CHANGELOG.md
|
62
|
+
- CODE_OF_CONDUCT.md
|
63
|
+
- CONTRIBUTING.md
|
84
64
|
- Gemfile
|
65
|
+
- Gemfile.devtools
|
85
66
|
- Guardfile
|
67
|
+
- LICENSE
|
86
68
|
- LICENSE.txt
|
87
69
|
- README.md
|
88
70
|
- Rakefile
|
@@ -92,6 +74,18 @@ files:
|
|
92
74
|
- benchmarks/with_coercion.rb
|
93
75
|
- benchmarks/with_defaults.rb
|
94
76
|
- benchmarks/with_defaults_and_coercion.rb
|
77
|
+
- bin/.gitkeep
|
78
|
+
- docsite/source/attributes.html.md
|
79
|
+
- docsite/source/container-version.html.md
|
80
|
+
- docsite/source/index.html.md
|
81
|
+
- docsite/source/inheritance.html.md
|
82
|
+
- docsite/source/optionals-and-defaults.html.md
|
83
|
+
- docsite/source/options-tolerance.html.md
|
84
|
+
- docsite/source/params-and-options.html.md
|
85
|
+
- docsite/source/rails-support.html.md
|
86
|
+
- docsite/source/readers.html.md
|
87
|
+
- docsite/source/skip-undefined.html.md
|
88
|
+
- docsite/source/type-constraints.html.md
|
95
89
|
- dry-initializer.gemspec
|
96
90
|
- lib/dry-initializer.rb
|
97
91
|
- lib/dry/initializer.rb
|
@@ -103,19 +97,36 @@ files:
|
|
103
97
|
- lib/dry/initializer/config.rb
|
104
98
|
- lib/dry/initializer/definition.rb
|
105
99
|
- lib/dry/initializer/dispatchers.rb
|
100
|
+
- lib/dry/initializer/dispatchers/build_nested_type.rb
|
101
|
+
- lib/dry/initializer/dispatchers/check_type.rb
|
102
|
+
- lib/dry/initializer/dispatchers/prepare_default.rb
|
103
|
+
- lib/dry/initializer/dispatchers/prepare_ivar.rb
|
104
|
+
- lib/dry/initializer/dispatchers/prepare_optional.rb
|
105
|
+
- lib/dry/initializer/dispatchers/prepare_reader.rb
|
106
|
+
- lib/dry/initializer/dispatchers/prepare_source.rb
|
107
|
+
- lib/dry/initializer/dispatchers/prepare_target.rb
|
108
|
+
- lib/dry/initializer/dispatchers/unwrap_type.rb
|
109
|
+
- lib/dry/initializer/dispatchers/wrap_type.rb
|
106
110
|
- lib/dry/initializer/dsl.rb
|
107
111
|
- lib/dry/initializer/mixin.rb
|
108
112
|
- lib/dry/initializer/mixin/local.rb
|
109
113
|
- lib/dry/initializer/mixin/root.rb
|
114
|
+
- lib/dry/initializer/struct.rb
|
115
|
+
- lib/dry/initializer/undefined.rb
|
116
|
+
- lib/dry/initializer/version.rb
|
110
117
|
- lib/tasks/benchmark.rake
|
111
118
|
- lib/tasks/profile.rake
|
119
|
+
- project.yml
|
112
120
|
- spec/attributes_spec.rb
|
121
|
+
- spec/coercion_of_nil_spec.rb
|
113
122
|
- spec/custom_dispatchers_spec.rb
|
114
123
|
- spec/custom_initializer_spec.rb
|
115
124
|
- spec/default_values_spec.rb
|
116
125
|
- spec/definition_spec.rb
|
117
126
|
- spec/invalid_default_spec.rb
|
127
|
+
- spec/list_type_spec.rb
|
118
128
|
- spec/missed_default_spec.rb
|
129
|
+
- spec/nested_type_spec.rb
|
119
130
|
- spec/optional_spec.rb
|
120
131
|
- spec/options_tolerance_spec.rb
|
121
132
|
- spec/public_attributes_utility_spec.rb
|
@@ -124,10 +135,12 @@ files:
|
|
124
135
|
- spec/several_assignments_spec.rb
|
125
136
|
- spec/spec_helper.rb
|
126
137
|
- spec/subclassing_spec.rb
|
138
|
+
- spec/support/coverage.rb
|
139
|
+
- spec/support/warnings.rb
|
127
140
|
- spec/type_argument_spec.rb
|
128
141
|
- spec/type_constraint_spec.rb
|
129
142
|
- spec/value_coercion_via_dry_types_spec.rb
|
130
|
-
homepage: https://github.com/
|
143
|
+
homepage: https://github.com/dry-rb/dry-initializer
|
131
144
|
licenses:
|
132
145
|
- MIT
|
133
146
|
metadata: {}
|
@@ -146,19 +159,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
159
|
- !ruby/object:Gem::Version
|
147
160
|
version: '0'
|
148
161
|
requirements: []
|
149
|
-
|
150
|
-
rubygems_version: 2.6.14
|
162
|
+
rubygems_version: 3.0.3
|
151
163
|
signing_key:
|
152
164
|
specification_version: 4
|
153
165
|
summary: DSL for declaring params and options of the initializer
|
154
166
|
test_files:
|
155
167
|
- spec/attributes_spec.rb
|
168
|
+
- spec/coercion_of_nil_spec.rb
|
156
169
|
- spec/custom_dispatchers_spec.rb
|
157
170
|
- spec/custom_initializer_spec.rb
|
158
171
|
- spec/default_values_spec.rb
|
159
172
|
- spec/definition_spec.rb
|
160
173
|
- spec/invalid_default_spec.rb
|
174
|
+
- spec/list_type_spec.rb
|
161
175
|
- spec/missed_default_spec.rb
|
176
|
+
- spec/nested_type_spec.rb
|
162
177
|
- spec/optional_spec.rb
|
163
178
|
- spec/options_tolerance_spec.rb
|
164
179
|
- spec/public_attributes_utility_spec.rb
|
@@ -167,6 +182,8 @@ test_files:
|
|
167
182
|
- spec/several_assignments_spec.rb
|
168
183
|
- spec/spec_helper.rb
|
169
184
|
- spec/subclassing_spec.rb
|
185
|
+
- spec/support/coverage.rb
|
186
|
+
- spec/support/warnings.rb
|
170
187
|
- spec/type_argument_spec.rb
|
171
188
|
- spec/type_constraint_spec.rb
|
172
189
|
- spec/value_coercion_via_dry_types_spec.rb
|
data/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
bundler_args: --without benchmarks tools
|
6
|
-
script:
|
7
|
-
- bundle exec rake spec
|
8
|
-
rvm:
|
9
|
-
- 2.3.0
|
10
|
-
- 2.4.0
|
11
|
-
- jruby-9000
|
12
|
-
- rbx-3
|
13
|
-
- ruby-head
|
14
|
-
env:
|
15
|
-
global:
|
16
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
17
|
-
matrix:
|
18
|
-
allow_failures:
|
19
|
-
- rvm: rbx-3
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
22
|
-
include:
|
23
|
-
- rvm: jruby-head
|
24
|
-
before_install: gem install bundler --no-ri --no-rdoc
|