dry-initializer 0.4.0 → 0.5.0

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: 7db8f3d16f5e690b2184d79d06d2417e2dab2810
4
- data.tar.gz: 03a361fa17734d5d37d8da5f647e975e36ee8d1f
3
+ metadata.gz: 741920ad4c93079821b5dd2f4031fadaf6e4c3b7
4
+ data.tar.gz: b64f94cc5b3295a3a9decc367fd00fd46bd0ee36
5
5
  SHA512:
6
- metadata.gz: f879fb0ae4169c9a402df913d7b00f4c38e9349ca7d200c43687f5c28970e81466c3152a19b61249299451213b93ee9ce971b949d3eb0f163ebce6c55304bf3b
7
- data.tar.gz: cc7a1b201b934f10c1d09a09f2b22820361135c4da201c4778828836b55dd7633e0b8db8e9673071e3344a56c73498ab036f787dec8be57bd57169c07872532b
6
+ metadata.gz: 1716c91a5cebe7bd125542c3a3004fed51fef824d865351609332b18f234a1adbe99420e91045d5f5144dbf44d69bde670a84d578bd433137611af7c4daea12a
7
+ data.tar.gz: 71b93072383a3ec4ad127057a4db3f99b0f1b21b6d50d0d8dda5776e21b43943de82c15f8a3e94668152339112fda1952e08fc1bd905439dd08d409012232737
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v0.5.0 2016-08-21
2
+
3
+ ### Added
4
+
5
+ * Allow `optional` attribute to be left undefined (@nepalez)
6
+
7
+ [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-initializer/compare/v0.4.0..v0.5.0)
8
+
1
9
  ## v0.4.0 2016-05-28
2
10
 
3
11
  ### Deleted (backward-incompatible changes)
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
 
6
6
  group :benchmarks do
7
7
  gem "benchmark-ips", "~> 2.5"
8
-
8
+ gem "activesupport", "< 5"
9
9
  gem "active_attr"
10
10
  gem "anima"
11
11
  gem "attr_extras"
data/README.md CHANGED
@@ -49,7 +49,7 @@ class User
49
49
 
50
50
  # Params of the initializer along with corresponding readers
51
51
  param :name
52
- param :role, default: proc { 'customer' }
52
+ param :role, default: proc { 'customer' }
53
53
  # Options of the initializer along with corresponding readers
54
54
  option :admin, default: proc { false }
55
55
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "0.4.0"
3
+ gem.version = "0.5.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"
@@ -17,8 +17,12 @@ module Dry::Initializer::Plugins
17
17
  settings.key? :default
18
18
  end
19
19
 
20
+ def optional?
21
+ default? || settings.key?(:optional)
22
+ end
23
+
20
24
  def call
21
- case [param?, default?]
25
+ case [param?, optional?]
22
26
  when [true, false] then name.to_s
23
27
  when [false, false] then "#{name}:"
24
28
  when [true, true] then "#{name} = #{undefined}"
@@ -43,8 +43,8 @@ module Dry::Initializer
43
43
  end
44
44
 
45
45
  def validates_order_of(signature)
46
- return unless signature.param? && !signature.default?
47
- return unless any? { |item| item.param? && item.default? }
46
+ return unless signature.param? && !signature.optional?
47
+ return unless any? { |item| item.param? && item.optional? }
48
48
 
49
49
  fail OrderError.new(signature.name)
50
50
  end
@@ -0,0 +1,44 @@
1
+ describe "optional value" do
2
+ context "when has no default value" do
3
+ before do
4
+ class Test::Foo
5
+ extend Dry::Initializer::Mixin
6
+
7
+ param :foo
8
+ param :bar, optional: true
9
+ end
10
+ end
11
+
12
+ it "is left UNDEFINED by default" do
13
+ subject = Test::Foo.new(1)
14
+
15
+ expect(subject.foo).to eq 1
16
+ expect(subject.bar).to eq Dry::Initializer::UNDEFINED
17
+ end
18
+
19
+ it "can be set explicitly" do
20
+ subject = Test::Foo.new(1, "qux")
21
+
22
+ expect(subject.foo).to eq 1
23
+ expect(subject.bar).to eq "qux"
24
+ end
25
+ end
26
+
27
+ context "when has default value" do
28
+ before do
29
+ class Test::Foo
30
+ extend Dry::Initializer::Mixin
31
+
32
+ param :foo
33
+ param :bar, optional: true, default: proc { "baz" }
34
+ end
35
+ end
36
+
37
+ it "is takes default value" do
38
+ subject = Test::Foo.new(1)
39
+
40
+ expect(subject.foo).to eq 1
41
+ expect(subject.bar).to eq "baz"
42
+ end
43
+ end
44
+ 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: 0.4.0
4
+ version: 0.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: 2016-05-28 00:00:00.000000000 Z
12
+ date: 2016-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -112,6 +112,7 @@ files:
112
112
  - spec/dry/default_values_spec.rb
113
113
  - spec/dry/invalid_default_spec.rb
114
114
  - spec/dry/missed_default_spec.rb
115
+ - spec/dry/optional_spec.rb
115
116
  - spec/dry/options_tolerance_spec.rb
116
117
  - spec/dry/plugin_registry_spec.rb
117
118
  - spec/dry/reader_spec.rb
@@ -151,6 +152,7 @@ test_files:
151
152
  - spec/dry/default_values_spec.rb
152
153
  - spec/dry/invalid_default_spec.rb
153
154
  - spec/dry/missed_default_spec.rb
155
+ - spec/dry/optional_spec.rb
154
156
  - spec/dry/options_tolerance_spec.rb
155
157
  - spec/dry/plugin_registry_spec.rb
156
158
  - spec/dry/reader_spec.rb
@@ -159,4 +161,3 @@ test_files:
159
161
  - spec/dry/type_constraint_spec.rb
160
162
  - spec/dry/value_coercion_via_dry_types_spec.rb
161
163
  - spec/spec_helper.rb
162
- has_rdoc: