dry-initializer 1.1.0 → 1.1.1
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/.rubocop.yml +9 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -3
- data/dry-initializer.gemspec +1 -1
- data/lib/dry/initializer/attribute.rb +10 -0
- data/lib/dry/initializer/builder.rb +10 -1
- data/lib/dry/initializer/exceptions/params_order_error.rb +1 -1
- data/lib/dry/initializer/option.rb +2 -4
- data/lib/dry/initializer/param.rb +2 -4
- data/spec/missed_default_spec.rb +1 -1
- data/spec/options_var_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bb3cc8fc0769ecd8c81518372df7bb0d74969f4
|
4
|
+
data.tar.gz: ace5842b26ce417325dbd6b1f653a3ffd1212c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e0d784c9b40a88473e22bbb075ef31074ea207f864093f144a7792c3e485b8ffe92a95fd164d3b27a1301131c4b10006bd9a6631e2ed0509c49e1bc7263551
|
7
|
+
data.tar.gz: fc4bf50667a8a5164d957851cad69976941a240be37aa3bc8c68201dadfdce1a521d687e327a42bc22c87d72378c10169b1691a502ffa228895a6e83bba435e7
|
data/.rubocop.yml
CHANGED
@@ -5,12 +5,21 @@ AllCops:
|
|
5
5
|
StyleGuideCopsOnly: true
|
6
6
|
TargetRubyVersion: 2.2
|
7
7
|
|
8
|
+
Bundler/DuplicatedGem:
|
9
|
+
Enabled: false
|
10
|
+
|
8
11
|
Style/CaseEquality:
|
9
12
|
Enabled: false
|
10
13
|
|
11
14
|
Style/ClassVars:
|
12
15
|
Enabled: false
|
13
16
|
|
17
|
+
Style/ClassAndModuleChildren:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
14
23
|
Style/DoubleNegation:
|
15
24
|
Enabled: false
|
16
25
|
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -4,8 +4,6 @@ source "https://rubygems.org"
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :benchmarks do
|
7
|
-
gem "benchmark-ips", "~> 2.5"
|
8
|
-
|
9
7
|
if RUBY_VERSION < "2.4"
|
10
8
|
gem "activesupport", "< 5"
|
11
9
|
else
|
@@ -15,13 +13,14 @@ group :benchmarks do
|
|
15
13
|
gem "active_attr"
|
16
14
|
gem "anima"
|
17
15
|
gem "attr_extras"
|
16
|
+
gem "benchmark-ips", "~> 2.5"
|
18
17
|
gem "concord"
|
19
18
|
gem "fast_attributes"
|
20
19
|
gem "kwattr"
|
20
|
+
gem "ruby-prof"
|
21
21
|
gem "value_struct"
|
22
22
|
gem "values"
|
23
23
|
gem "virtus"
|
24
|
-
gem "ruby-prof"
|
25
24
|
end
|
26
25
|
|
27
26
|
group :development, :test do
|
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 = "1.1.
|
3
|
+
gem.version = "1.1.1"
|
4
4
|
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
|
5
5
|
gem.email = ["hashtable@yandex.ru", "andrew.kozin@gmail.com"]
|
6
6
|
gem.homepage = "https://github.com/dryrb/dry-initializer"
|
@@ -88,5 +88,15 @@ module Dry::Initializer
|
|
88
88
|
return if coercer.nil? || coercer.respond_to?(:call)
|
89
89
|
fail TypeConstraintError.new(source, coercer)
|
90
90
|
end
|
91
|
+
|
92
|
+
def default_hash(type)
|
93
|
+
default ? { :"#{type}_#{source}" => default } : {}
|
94
|
+
end
|
95
|
+
|
96
|
+
def coercer_hash(type)
|
97
|
+
return {} unless coercer
|
98
|
+
value = proc { |v| v == Dry::Initializer::UNDEFINED ? v : coercer.(v) }
|
99
|
+
{ :"#{type}_#{source}" => value }
|
100
|
+
end
|
91
101
|
end
|
92
102
|
end
|
@@ -33,7 +33,7 @@ module Dry::Initializer
|
|
33
33
|
def code
|
34
34
|
<<-RUBY.gsub(/^ +\|/, "")
|
35
35
|
|def __initialize__(#{initializer_signatures})
|
36
|
-
| @__options__ =
|
36
|
+
| @__options__ = #{defined_options}
|
37
37
|
|#{initializer_presetters}
|
38
38
|
|#{initializer_setters}
|
39
39
|
|end
|
@@ -75,6 +75,15 @@ module Dry::Initializer
|
|
75
75
|
end.compact.uniq.join("\n")
|
76
76
|
end
|
77
77
|
|
78
|
+
def defined_options
|
79
|
+
if @options.any?
|
80
|
+
keys = @options.map(&:target).join(" ")
|
81
|
+
"__options__.select { |key| %i(#{keys}).include? key }"
|
82
|
+
else
|
83
|
+
"{}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
78
87
|
def getters
|
79
88
|
attributes.map(&:getter).compact.uniq.join("\n")
|
80
89
|
end
|
@@ -22,14 +22,12 @@ module Dry::Initializer
|
|
22
22
|
|
23
23
|
# part of __defaults__
|
24
24
|
def default_hash
|
25
|
-
|
25
|
+
super :option
|
26
26
|
end
|
27
27
|
|
28
28
|
# part of __coercers__
|
29
29
|
def coercer_hash
|
30
|
-
|
31
|
-
value = proc { |v| (v == Dry::Initializer::UNDEFINED) ? v : coercer.(v) }
|
32
|
-
{ :"option_#{source}" => value }
|
30
|
+
super :option
|
33
31
|
end
|
34
32
|
|
35
33
|
private
|
@@ -18,14 +18,12 @@ module Dry::Initializer
|
|
18
18
|
|
19
19
|
# part of __defaults__
|
20
20
|
def default_hash
|
21
|
-
|
21
|
+
super :param
|
22
22
|
end
|
23
23
|
|
24
24
|
# part of __coercers__
|
25
25
|
def coercer_hash
|
26
|
-
|
27
|
-
value = proc { |v| (v == Dry::Initializer::UNDEFINED) ? v : coercer.(v) }
|
28
|
-
{ :"param_#{target}" => value }
|
26
|
+
super :param
|
29
27
|
end
|
30
28
|
|
31
29
|
private
|
data/spec/missed_default_spec.rb
CHANGED
data/spec/options_var_spec.rb
CHANGED
@@ -30,8 +30,8 @@ describe "@__options__" do
|
|
30
30
|
expect(subject.instance_variable_get(:@__options__)).to eq({})
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
34
|
-
subject = Test::Foo.new(1, baz: :QUX)
|
33
|
+
it "slices allowed options only" do
|
34
|
+
subject = Test::Foo.new(1, baz: :QUX, qux: :BAZ)
|
35
35
|
|
36
36
|
expect(subject.instance_variable_get(:@__options__)).to eq({ baz: :QUX })
|
37
37
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
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: 2017-
|
12
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|