dry-initializer 2.4.0 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +10 -21
  3. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
  4. data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
  5. data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
  6. data/.github/workflows/custom_ci.yml +58 -0
  7. data/.github/workflows/docsite.yml +34 -0
  8. data/.github/workflows/sync_configs.yml +56 -0
  9. data/.gitignore +2 -0
  10. data/.rspec +1 -1
  11. data/.rubocop.yml +76 -25
  12. data/CHANGELOG.md +150 -14
  13. data/CODE_OF_CONDUCT.md +13 -0
  14. data/CONTRIBUTING.md +29 -0
  15. data/Gemfile +25 -18
  16. data/Gemfile.devtools +16 -0
  17. data/Guardfile +3 -3
  18. data/LICENSE +20 -0
  19. data/README.md +17 -79
  20. data/Rakefile +4 -4
  21. data/benchmarks/compare_several_defaults.rb +27 -27
  22. data/benchmarks/plain_options.rb +14 -14
  23. data/benchmarks/plain_params.rb +22 -22
  24. data/benchmarks/with_coercion.rb +14 -14
  25. data/benchmarks/with_defaults.rb +17 -17
  26. data/benchmarks/with_defaults_and_coercion.rb +14 -14
  27. data/bin/.gitkeep +0 -0
  28. data/docsite/source/attributes.html.md +106 -0
  29. data/docsite/source/container-version.html.md +39 -0
  30. data/docsite/source/index.html.md +43 -0
  31. data/docsite/source/inheritance.html.md +43 -0
  32. data/docsite/source/optionals-and-defaults.html.md +130 -0
  33. data/docsite/source/options-tolerance.html.md +27 -0
  34. data/docsite/source/params-and-options.html.md +74 -0
  35. data/docsite/source/rails-support.html.md +101 -0
  36. data/docsite/source/readers.html.md +43 -0
  37. data/docsite/source/skip-undefined.html.md +59 -0
  38. data/docsite/source/type-constraints.html.md +160 -0
  39. data/dry-initializer.gemspec +13 -13
  40. data/lib/dry-initializer.rb +1 -1
  41. data/lib/dry/initializer.rb +17 -16
  42. data/lib/dry/initializer/builders.rb +2 -2
  43. data/lib/dry/initializer/builders/attribute.rb +16 -11
  44. data/lib/dry/initializer/builders/initializer.rb +9 -13
  45. data/lib/dry/initializer/builders/reader.rb +4 -2
  46. data/lib/dry/initializer/builders/signature.rb +3 -3
  47. data/lib/dry/initializer/config.rb +25 -12
  48. data/lib/dry/initializer/definition.rb +20 -71
  49. data/lib/dry/initializer/dispatchers.rb +101 -33
  50. data/lib/dry/initializer/dispatchers/build_nested_type.rb +59 -0
  51. data/lib/dry/initializer/dispatchers/check_type.rb +43 -0
  52. data/lib/dry/initializer/dispatchers/prepare_default.rb +40 -0
  53. data/lib/dry/initializer/dispatchers/prepare_ivar.rb +12 -0
  54. data/lib/dry/initializer/dispatchers/prepare_optional.rb +13 -0
  55. data/lib/dry/initializer/dispatchers/prepare_reader.rb +30 -0
  56. data/lib/dry/initializer/dispatchers/prepare_source.rb +28 -0
  57. data/lib/dry/initializer/dispatchers/prepare_target.rb +44 -0
  58. data/lib/dry/initializer/dispatchers/unwrap_type.rb +22 -0
  59. data/lib/dry/initializer/dispatchers/wrap_type.rb +28 -0
  60. data/lib/dry/initializer/mixin.rb +4 -4
  61. data/lib/dry/initializer/mixin/root.rb +1 -0
  62. data/lib/dry/initializer/struct.rb +39 -0
  63. data/lib/dry/initializer/undefined.rb +2 -0
  64. data/lib/dry/initializer/version.rb +5 -0
  65. data/lib/tasks/benchmark.rake +13 -13
  66. data/lib/tasks/profile.rake +16 -16
  67. data/project.yml +2 -0
  68. data/spec/attributes_spec.rb +7 -7
  69. data/spec/coercion_of_nil_spec.rb +25 -0
  70. data/spec/custom_dispatchers_spec.rb +6 -6
  71. data/spec/custom_initializer_spec.rb +2 -2
  72. data/spec/default_values_spec.rb +9 -9
  73. data/spec/definition_spec.rb +16 -12
  74. data/spec/invalid_default_spec.rb +2 -2
  75. data/spec/list_type_spec.rb +32 -0
  76. data/spec/missed_default_spec.rb +2 -2
  77. data/spec/nested_type_spec.rb +48 -0
  78. data/spec/optional_spec.rb +16 -16
  79. data/spec/options_tolerance_spec.rb +2 -2
  80. data/spec/public_attributes_utility_spec.rb +5 -5
  81. data/spec/reader_spec.rb +13 -13
  82. data/spec/repetitive_definitions_spec.rb +9 -9
  83. data/spec/several_assignments_spec.rb +9 -9
  84. data/spec/spec_helper.rb +6 -3
  85. data/spec/subclassing_spec.rb +5 -5
  86. data/spec/support/coverage.rb +7 -0
  87. data/spec/support/warnings.rb +7 -0
  88. data/spec/type_argument_spec.rb +15 -15
  89. data/spec/type_constraint_spec.rb +46 -28
  90. data/spec/value_coercion_via_dry_types_spec.rb +8 -8
  91. metadata +51 -34
  92. data/.travis.yml +0 -24
@@ -0,0 +1,7 @@
1
+ # this file is managed by dry-rb/devtools
2
+
3
+ if ENV['COVERAGE'] == 'true'
4
+ require 'codacy-coverage'
5
+
6
+ Codacy::Reporter.start
7
+ end
@@ -0,0 +1,7 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ require 'warning'
4
+
5
+ Warning.ignore(%r{rspec/core})
6
+ Warning.ignore(/codacy/)
7
+ Warning[:experimental] = false if Warning.respond_to?(:[])
@@ -1,34 +1,34 @@
1
- require "dry-types"
1
+ require 'dry-types'
2
2
 
3
- describe "type argument" do
3
+ describe 'type argument' do
4
4
  before do
5
5
  class Test::Foo
6
6
  extend Dry::Initializer
7
- param :foo, Dry::Types["strict.string"]
8
- option :bar, Dry::Types["strict.string"]
7
+ param :foo, Dry::Types['strict.string']
8
+ option :bar, Dry::Types['strict.string']
9
9
  end
10
10
  end
11
11
 
12
- context "in case of param mismatch" do
13
- subject { Test::Foo.new 1, bar: "2" }
12
+ context 'in case of param mismatch' do
13
+ subject { Test::Foo.new 1, bar: '2' }
14
14
 
15
- it "raises TypeError" do
16
- expect { subject }.to raise_error TypeError, /1/
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 "in case of option mismatch" do
21
- subject { Test::Foo.new "1", bar: 2 }
20
+ context 'in case of option mismatch' do
21
+ subject { Test::Foo.new '1', bar: 2 }
22
22
 
23
- it "raises TypeError" do
24
- expect { subject }.to raise_error TypeError, /2/
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 "in case of match" do
29
- subject { Test::Foo.new "1", bar: "2" }
28
+ context 'in case of match' do
29
+ subject { Test::Foo.new '1', bar: '2' }
30
30
 
31
- it "completes the initialization" do
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 "dry-types"
1
+ require 'dry-types'
2
2
 
3
- describe "type constraint" do
4
- context "by a proc with 1 argument" do
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 :foo, proc(&:to_s), optional: true
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 "coerces a value" do
15
- expect(subject.foo).to eq "foo"
14
+ it 'coerces a value' do
15
+ expect(subject.__foo__).to eq 'foo'
16
16
  end
17
17
  end
18
18
 
19
- context "by a proc with 2 arguments" do
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 "coerces a value with self as a second argument" do
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 "by dry-type" do
34
+ context 'by dry-type' do
35
35
  before do
36
- class Test::Foo
36
+ constraint = self.constraint
37
+
38
+ Test::Foo = Class.new do
37
39
  extend Dry::Initializer
38
- param :foo, Dry::Types["strict.string"], optional: true
40
+ param :foo, constraint, optional: true
39
41
  end
40
42
  end
41
43
 
42
- context "in case of mismatch" do
43
- subject { Test::Foo.new 1 }
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
- it "raises TypeError" do
46
- expect { subject }.to raise_error TypeError, /1/
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
- context "in case of match" do
51
- subject { Test::Foo.new "foo" }
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
- it "completes the initialization" do
54
- expect { subject }.not_to raise_error
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 "if optional value not set" do
59
- subject { Test::Foo.new }
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
- it "not applicable to Dry::Initializer::UNDEFINED" do
62
- expect(subject.instance_variable_get(:@foo))
63
- .to eq Dry::Initializer::UNDEFINED
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 "by invalid constraint" do
69
- it "raises TypeError" do
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(TypeError)
93
+ end.to raise_error(ArgumentError)
76
94
  end
77
95
  end
78
96
  end
@@ -1,27 +1,27 @@
1
- require "dry-types"
1
+ require 'dry-types'
2
2
 
3
- describe "value coercion via dry-types" do
3
+ describe 'value coercion via dry-types' do
4
4
  before do
5
5
  module Test::Types
6
- include Dry::Types.module
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 { "16" }
13
+ option :bar, proc(&:to_i), default: proc { '16' }
14
14
  end
15
15
  end
16
16
 
17
- it "coerces assigned values" do
18
- subject = Test::Foo.new :foo, bar: "13"
17
+ it 'coerces assigned values' do
18
+ subject = Test::Foo.new :foo, bar: '13'
19
19
 
20
- expect(subject.foo).to eql "foo"
20
+ expect(subject.foo).to eql 'foo'
21
21
  expect(subject.bar).to eql 13
22
22
  end
23
23
 
24
- it "coerces defaults as well" do
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: 2.4.0
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: 2018-02-02 00:00:00.000000000 Z
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/dryrb/dry-initializer
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
- rubyforge_project:
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