dry-initializer 2.4.0 → 2.5.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/README.md +2 -2
- data/dry-initializer.gemspec +2 -2
- data/lib/dry/initializer.rb +1 -2
- data/lib/dry/initializer/builders/attribute.rb +4 -4
- data/lib/dry/initializer/builders/reader.rb +1 -1
- data/lib/dry/initializer/config.rb +3 -4
- data/spec/coercion_of_nil_spec.rb +25 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 861264b64b414e7ff11f68071a530e3208093092
|
4
|
+
data.tar.gz: f3426ffd2670dbe47c276d67fd972e86fdeb9677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3205f5f09066d20a3f05255a71ae8451ec6c00b0c6701bdf2fb4d8a854a61d49d5b1eea952d4cd08d05e3165e8748d73dd1e530a39a12d85bb90e5514bf6c37c
|
7
|
+
data.tar.gz: 05205f55be677d470f553ec0e9fcf8d357ffc3ba245c9195b144c24cac478dd3aa2e1e8d6bcbbd6fc1b6b04d92d8e3e8345762bc76838651dab26d90632a31d2
|
data/README.md
CHANGED
@@ -70,11 +70,11 @@ See full documentation on the [Dry project official site][docs]
|
|
70
70
|
|
71
71
|
## Benchmarks
|
72
72
|
|
73
|
-
The `dry-initializer` is pretty fast for rubies 2.
|
73
|
+
The `dry-initializer` is pretty fast for rubies 2.3+ [comparing to other libraries][benchmarks].
|
74
74
|
|
75
75
|
## Compatibility
|
76
76
|
|
77
|
-
Tested under rubies [compatible to MRI 2.
|
77
|
+
Tested under rubies [compatible to MRI 2.3+](.travis.yml).
|
78
78
|
|
79
79
|
## Contributing
|
80
80
|
|
data/dry-initializer.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "dry-initializer"
|
3
|
-
gem.version = "2.
|
3
|
+
gem.version = "2.5.0"
|
4
4
|
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
|
5
5
|
gem.email = "andrew.kozin@gmail.com"
|
6
6
|
gem.homepage = "https://github.com/dryrb/dry-initializer"
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.add_development_dependency "rspec", "~> 3.0"
|
17
17
|
gem.add_development_dependency "rake", "> 10"
|
18
18
|
gem.add_development_dependency "dry-types", "> 0.5.1"
|
19
|
-
gem.add_development_dependency "rubocop", "~> 0.
|
19
|
+
gem.add_development_dependency "rubocop", "~> 0.49.0"
|
20
20
|
end
|
data/lib/dry/initializer.rb
CHANGED
@@ -27,8 +27,7 @@ module Dry
|
|
27
27
|
|
28
28
|
# Adds or redefines a parameter of [#dry_initializer]
|
29
29
|
# @param [Symbol] name
|
30
|
-
# @param [#call, nil]
|
31
|
-
# @option opts [#call] :type
|
30
|
+
# @param [#call, nil] type (nil)
|
32
31
|
# @option opts [Proc] :default
|
33
32
|
# @option opts [Boolean] :optional
|
34
33
|
# @option opts [Symbol] :as
|
@@ -60,22 +60,22 @@ module Dry::Initializer::Builders
|
|
60
60
|
|
61
61
|
def default_line
|
62
62
|
return unless @default
|
63
|
-
"#{@val} = instance_exec(&#{@item}.default) if #{@
|
63
|
+
"#{@val} = instance_exec(&#{@item}.default) if #{@null} == #{@val}"
|
64
64
|
end
|
65
65
|
|
66
66
|
def coercion_line
|
67
67
|
return unless @type
|
68
68
|
arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
|
69
69
|
if arity.abs == 1
|
70
|
-
"#{@val} = #{@item}.type.call(#{@val}) unless #{@
|
70
|
+
"#{@val} = #{@item}.type.call(#{@val}) unless #{@null} == #{@val}"
|
71
71
|
else
|
72
|
-
"#{@val} = #{@item}.type.call(#{@val}, self) unless #{@
|
72
|
+
"#{@val} = #{@item}.type.call(#{@val}, self) unless #{@null} == #{@val}"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def assignment_line
|
77
77
|
"#{@ivar} = #{@val}" \
|
78
|
-
" unless #{@
|
78
|
+
" unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -51,8 +51,7 @@ module Dry::Initializer
|
|
51
51
|
|
52
52
|
# Adds or redefines a parameter
|
53
53
|
# @param [Symbol] name
|
54
|
-
# @param [#call, nil]
|
55
|
-
# @option opts [#call] :type
|
54
|
+
# @param [#call, nil] type (nil)
|
56
55
|
# @option opts [Proc] :default
|
57
56
|
# @option opts [Boolean] :optional
|
58
57
|
# @option opts [Symbol] :as
|
@@ -80,7 +79,7 @@ module Dry::Initializer
|
|
80
79
|
key = item.target
|
81
80
|
next unless instance.respond_to? key
|
82
81
|
val = instance.send(key)
|
83
|
-
obj[key] = val unless
|
82
|
+
obj[key] = val unless null == val
|
84
83
|
end
|
85
84
|
end
|
86
85
|
|
@@ -91,7 +90,7 @@ module Dry::Initializer
|
|
91
90
|
definitions.values.each_with_object({}) do |item, obj|
|
92
91
|
key = item.target
|
93
92
|
val = instance.send(:instance_variable_get, item.ivar)
|
94
|
-
obj[key] = val unless
|
93
|
+
obj[key] = val unless null == val
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe "coercion of nil" do
|
2
|
+
before do
|
3
|
+
class Test::Foo
|
4
|
+
extend Dry::Initializer
|
5
|
+
param :bar, proc(&:to_i)
|
6
|
+
end
|
7
|
+
|
8
|
+
class Test::Baz
|
9
|
+
include Dry::Initializer.define -> do
|
10
|
+
param :qux, proc(&:to_i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:foo) { Test::Foo.new(nil) }
|
16
|
+
let(:baz) { Test::Baz.new(nil) }
|
17
|
+
|
18
|
+
it "works with extend syntax" do
|
19
|
+
expect(foo.bar).to eq 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it "works with include syntax" do
|
23
|
+
expect(baz.qux).to eq 0
|
24
|
+
end
|
25
|
+
end
|
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
|
+
version: 2.5.0
|
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-
|
12
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 0.49.0
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 0.49.0
|
70
70
|
description:
|
71
71
|
email: andrew.kozin@gmail.com
|
72
72
|
executables: []
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/tasks/benchmark.rake
|
111
111
|
- lib/tasks/profile.rake
|
112
112
|
- spec/attributes_spec.rb
|
113
|
+
- spec/coercion_of_nil_spec.rb
|
113
114
|
- spec/custom_dispatchers_spec.rb
|
114
115
|
- spec/custom_initializer_spec.rb
|
115
116
|
- spec/default_values_spec.rb
|
@@ -153,6 +154,7 @@ specification_version: 4
|
|
153
154
|
summary: DSL for declaring params and options of the initializer
|
154
155
|
test_files:
|
155
156
|
- spec/attributes_spec.rb
|
157
|
+
- spec/coercion_of_nil_spec.rb
|
156
158
|
- spec/custom_dispatchers_spec.rb
|
157
159
|
- spec/custom_initializer_spec.rb
|
158
160
|
- spec/default_values_spec.rb
|