dry-initializer 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/dry-initializer.gemspec +1 -1
- data/lib/dry/initializer/builder.rb +8 -4
- data/lib/dry/initializer/option.rb +5 -0
- data/lib/dry/initializer/param.rb +2 -0
- data/spec/options_var_spec.rb +7 -11
- 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: 77c08e7da9990b73b8c94815830a19694b424317
|
4
|
+
data.tar.gz: df1ab88700f059cd3327e7c1745d41aaa901000a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b04de090fba7b94c917791ebdbff775e3dfd4ae4bfb2c7d51ec9785ae7007324802870c476daf348a397a0ef3ff8c34d70c17fa28777cbb338eb4de44acb137
|
7
|
+
data.tar.gz: 8bb88fc5ada80331a4c1a8d1a076200294db7d2c66009f6da79edef7742fe03e5094d69f5ac97ee57c336354504f00dcc95bf02ac527d21880dfb0ba2be043f4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v1.2.0 2017-03-05
|
2
|
+
|
3
|
+
# Fixed
|
4
|
+
- The `@__options__` variable collects renamed options after default values and coercions were applied (nepalez)
|
5
|
+
|
6
|
+
[Compare v1.1.3...v1.2.0](https://github.com/dry-rb/dry-initializer/compare/v1.1.3...v1.2.0)
|
7
|
+
|
1
8
|
## v1.1.3 2017-03-01
|
2
9
|
|
3
10
|
# Added
|
@@ -15,7 +22,7 @@
|
|
15
22
|
## v1.1.1 2017-02-04
|
16
23
|
|
17
24
|
# Bugs Fixed
|
18
|
-
- `@
|
25
|
+
- `@__options__` collects defined options only (nepalez)
|
19
26
|
|
20
27
|
[Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-initializer/compare/v1.1.0...v1.1.1)
|
21
28
|
|
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.
|
3
|
+
gem.version = "1.2.0"
|
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"
|
@@ -42,9 +42,10 @@ module Dry::Initializer
|
|
42
42
|
def code
|
43
43
|
<<-RUBY.gsub(/^ +\|/, "")
|
44
44
|
|def __initialize__(#{initializer_signatures})
|
45
|
-
| @__options__ =
|
45
|
+
| @__options__ = {}
|
46
46
|
|#{initializer_presetters}
|
47
47
|
|#{initializer_setters}
|
48
|
+
|#{initializer_postsetters}
|
48
49
|
|end
|
49
50
|
|private :__initialize__
|
50
51
|
|private :__defaults__
|
@@ -72,9 +73,8 @@ module Dry::Initializer
|
|
72
73
|
|
73
74
|
def initializer_presetters
|
74
75
|
dups = duplications
|
75
|
-
attributes
|
76
|
-
|
77
|
-
.compact.uniq.join("\n")
|
76
|
+
attributes.map { |a| " #{a.presetter}" if dups.include? a.target }
|
77
|
+
.compact.uniq.join("\n")
|
78
78
|
end
|
79
79
|
|
80
80
|
def initializer_setters
|
@@ -84,6 +84,10 @@ module Dry::Initializer
|
|
84
84
|
end.compact.uniq.join("\n")
|
85
85
|
end
|
86
86
|
|
87
|
+
def initializer_postsetters
|
88
|
+
attributes.map { |a| " #{a.postsetter}" }.compact.uniq.join("\n")
|
89
|
+
end
|
90
|
+
|
87
91
|
def defined_options
|
88
92
|
if @options.any?
|
89
93
|
keys = @options.map(&:target).join(" ")
|
@@ -20,6 +20,11 @@ module Dry::Initializer
|
|
20
20
|
"Dry::Initializer::UNDEFINED"
|
21
21
|
end
|
22
22
|
|
23
|
+
def postsetter
|
24
|
+
"@__options__[:#{target}] = @#{target}" \
|
25
|
+
" unless @#{target} == Dry::Initializer::UNDEFINED"
|
26
|
+
end
|
27
|
+
|
23
28
|
# part of __defaults__
|
24
29
|
def default_hash
|
25
30
|
super :option
|
data/spec/options_var_spec.rb
CHANGED
@@ -18,22 +18,18 @@ describe "@__options__" do
|
|
18
18
|
before do
|
19
19
|
class Test::Foo
|
20
20
|
extend Dry::Initializer::Mixin
|
21
|
-
|
22
|
-
option :bar,
|
21
|
+
option :foo
|
22
|
+
option :bar, default: proc { 1 }
|
23
23
|
option :baz, optional: true
|
24
|
+
option :qux, proc(&:to_s), as: :quxx
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
it "
|
28
|
-
subject = Test::Foo.new(
|
29
|
-
|
30
|
-
expect(subject.instance_variable_get(:@__options__)).to eq({})
|
31
|
-
end
|
32
|
-
|
33
|
-
it "slices allowed options only" do
|
34
|
-
subject = Test::Foo.new(1, baz: :QUX, qux: :BAZ)
|
28
|
+
it "collects coerced and renamed options with default values" do
|
29
|
+
subject = Test::Foo.new(foo: :FOO, qux: :QUX)
|
35
30
|
|
36
|
-
expect(subject.instance_variable_get(:@__options__))
|
31
|
+
expect(subject.instance_variable_get(:@__options__))
|
32
|
+
.to eq({ foo: :FOO, bar: 1, quxx: "QUX" })
|
37
33
|
end
|
38
34
|
end
|
39
35
|
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.
|
4
|
+
version: 1.2.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: 2017-03-
|
12
|
+
date: 2017-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|