dry-initializer 1.1.3 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37ac42279e4e9b15878d9b97d369ec986c298a19
4
- data.tar.gz: d151c2e841969c7c726f77ec7148168798b819f2
3
+ metadata.gz: 77c08e7da9990b73b8c94815830a19694b424317
4
+ data.tar.gz: df1ab88700f059cd3327e7c1745d41aaa901000a
5
5
  SHA512:
6
- metadata.gz: f5b4b8b3551d90860e091204e5b56c42f4d4679bdf0bda21dec183024566ddae301c5def3b6f5edb4b3ac68a3f83666239e054eb333243c29572a53b39341ef1
7
- data.tar.gz: 03bf3a13c91c5c7f9e1d4423885f77925e51cac17e3a0b48d4affefcb501837a459c6814e72b2f664eec48caee9b9e5b87934a814590fa3df3f8a5b5630f9f49
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
- - `@__option__` collects defined options only (nepalez)
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "1.1.3"
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__ = #{defined_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
- .map { |a| " #{a.presetter}" if dups.include? a.target }
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
@@ -16,6 +16,8 @@ module Dry::Initializer
16
16
  safe_setter
17
17
  end
18
18
 
19
+ def postsetter; end
20
+
19
21
  # part of __defaults__
20
22
  def default_hash
21
23
  super :param
@@ -18,22 +18,18 @@ describe "@__options__" do
18
18
  before do
19
19
  class Test::Foo
20
20
  extend Dry::Initializer::Mixin
21
- param :foo
22
- option :bar, optional: true
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 "is set to empty hash if no options assigned" do
28
- subject = Test::Foo.new(1)
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__)).to eq({ baz: :QUX })
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.1.3
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-01 00:00:00.000000000 Z
12
+ date: 2017-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec