dry-initializer 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 852519c02a938d27a827cff9c4cfd1e40c9c9dac
4
- data.tar.gz: 94923136d38c0afbc74ffa76ed35c4074c9ba75b
3
+ metadata.gz: 5bb3cc8fc0769ecd8c81518372df7bb0d74969f4
4
+ data.tar.gz: ace5842b26ce417325dbd6b1f653a3ffd1212c47
5
5
  SHA512:
6
- metadata.gz: c4195fe8176762d89b1593f05cde79e4c249dda71ace60fb070a75f92222f344d349cc97b3567e032d3aa67ac4556e97bc4282133fac724ea655decc1a4e95e7
7
- data.tar.gz: 0d50b2012d31467424ff6c232c5c3d8fff0e5d601eacf533c23f080933205aaa384948b98cc0831496ec6ac30b38697bf99554ef8d79b3f04f0922ef10de0b7e
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
@@ -1,3 +1,10 @@
1
+ ## v1.1.1 2017-02-04
2
+
3
+ # Bugs Fixed
4
+ - `@__option__` collects defined options only (nepalez)
5
+
6
+ [Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-initializer/compare/v1.1.0...v1.1.1)
7
+
1
8
  ## v1.1.0 2017-01-28
2
9
 
3
10
  # Added:
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "1.1.0"
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__ = __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
@@ -1,5 +1,5 @@
1
1
  module Dry::Initializer
2
- class ParamsOrderError < SyntaxError
2
+ class ParamsOrderError < RuntimeError
3
3
  def initialize(required, optional)
4
4
  super "Optional param '#{optional}'" \
5
5
  " should not preceed required '#{required}'"
@@ -22,14 +22,12 @@ module Dry::Initializer
22
22
 
23
23
  # part of __defaults__
24
24
  def default_hash
25
- default ? { :"option_#{source}" => default } : {}
25
+ super :option
26
26
  end
27
27
 
28
28
  # part of __coercers__
29
29
  def coercer_hash
30
- return {} unless coercer
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
- default ? { :"param_#{target}" => default } : {}
21
+ super :param
22
22
  end
23
23
 
24
24
  # part of __coercers__
25
25
  def coercer_hash
26
- return {} unless coercer
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
@@ -9,6 +9,6 @@ describe "missed default values" do
9
9
  end
10
10
 
11
11
  it "raises SyntaxError" do
12
- expect { subject }.to raise_error SyntaxError, /bar/
12
+ expect { subject }.to raise_error RuntimeError, /bar/
13
13
  end
14
14
  end
@@ -30,8 +30,8 @@ describe "@__options__" do
30
30
  expect(subject.instance_variable_get(:@__options__)).to eq({})
31
31
  end
32
32
 
33
- it "is set to hash of assigned options" do
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.0
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-01-28 00:00:00.000000000 Z
12
+ date: 2017-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec