dry-initializer 0.8.0 → 0.8.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/CHANGELOG.md +10 -0
- data/dry-initializer.gemspec +1 -1
- data/lib/dry/initializer/mixin.rb +4 -2
- data/spec/type_argument_spec.rb +35 -0
- data/spec/type_constraint_spec.rb +1 -5
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b5d5685f90f815d5bc7b45fcc0e342bb5d4545a
|
4
|
+
data.tar.gz: d6d8c4c59b72d4f7a9933dfb10e9b15350c16ecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e40ba0777d78ec4fcb44ced947679cf4b0e5db97e28d774b6c4e1d9edf27c971dee92387f35a2e4501ce5eaf516b4e4e8586268fc8bdcf2dca8cb7132a052ea
|
7
|
+
data.tar.gz: 1dfdc453fbff8f8050c18bd5f13ecf4ec5c3586386ece9198067d793629e08bb0c433e3aaaa1a4f7a080e9edc19f9e14b9034bc8bf9128dd3556eace65329e87
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.8.1 2016-11-05
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Support for `dry-struct`ish syntax for constraints (type as a second parameter) (@nepalez)
|
6
|
+
|
7
|
+
option :name, Dry::Types['strict.string']
|
8
|
+
|
9
|
+
[Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-initializer/compare/v0.8.0..v0.8.1)
|
10
|
+
|
1
11
|
## v0.8.0 2016-11-05
|
2
12
|
|
3
13
|
In this version we switched from key arguments to ** to support special keys:
|
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 = "0.8.
|
3
|
+
gem.version = "0.8.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"
|
@@ -13,7 +13,8 @@ module Dry::Initializer
|
|
13
13
|
#
|
14
14
|
# @return [self] itself
|
15
15
|
#
|
16
|
-
def param(name, **options)
|
16
|
+
def param(name, type = nil, **options)
|
17
|
+
options[:type] = type if type
|
17
18
|
@initializer_builder = \
|
18
19
|
initializer_builder.define(name, option: false, **options)
|
19
20
|
initializer_builder.call(self)
|
@@ -25,7 +26,8 @@ module Dry::Initializer
|
|
25
26
|
# @option (see #param)
|
26
27
|
# @return (see #param)
|
27
28
|
#
|
28
|
-
def option(name, **options)
|
29
|
+
def option(name, type = nil, **options)
|
30
|
+
options[:type] = type if type
|
29
31
|
@initializer_builder = \
|
30
32
|
initializer_builder.define(name, option: true, **options)
|
31
33
|
initializer_builder.call(self)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "dry-types"
|
2
|
+
|
3
|
+
describe "type argument" do
|
4
|
+
before do
|
5
|
+
class Test::Foo
|
6
|
+
extend Dry::Initializer::Mixin
|
7
|
+
param :foo, Dry::Types["strict.string"]
|
8
|
+
option :bar, Dry::Types["strict.string"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "in case of param mismatch" do
|
13
|
+
subject { Test::Foo.new 1, bar: "2" }
|
14
|
+
|
15
|
+
it "raises TypeError" do
|
16
|
+
expect { subject }.to raise_error TypeError, /1/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "in case of option mismatch" do
|
21
|
+
subject { Test::Foo.new "1", bar: 2 }
|
22
|
+
|
23
|
+
it "raises TypeError" do
|
24
|
+
expect { subject }.to raise_error TypeError, /2/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "in case of match" do
|
29
|
+
subject { Test::Foo.new "1", bar: "2" }
|
30
|
+
|
31
|
+
it "completes the initialization" do
|
32
|
+
expect { subject }.not_to raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -3,13 +3,9 @@ require "dry-types"
|
|
3
3
|
describe "type constraint" do
|
4
4
|
context "by dry-type" do
|
5
5
|
before do
|
6
|
-
module Test::Types
|
7
|
-
include Dry::Types.module
|
8
|
-
end
|
9
|
-
|
10
6
|
class Test::Foo
|
11
7
|
extend Dry::Initializer::Mixin
|
12
|
-
param :foo, type:
|
8
|
+
param :foo, type: Dry::Types["strict.string"], optional: true
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
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.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev (marshall-lee)
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- spec/shared_definitions_spec.rb
|
136
136
|
- spec/spec_helper.rb
|
137
137
|
- spec/subclassing_spec.rb
|
138
|
+
- spec/type_argument_spec.rb
|
138
139
|
- spec/type_constraint_spec.rb
|
139
140
|
- spec/value_coercion_via_dry_types_spec.rb
|
140
141
|
homepage: https://github.com/dryrb/dry-initializer
|
@@ -176,5 +177,6 @@ test_files:
|
|
176
177
|
- spec/shared_definitions_spec.rb
|
177
178
|
- spec/spec_helper.rb
|
178
179
|
- spec/subclassing_spec.rb
|
180
|
+
- spec/type_argument_spec.rb
|
179
181
|
- spec/type_constraint_spec.rb
|
180
182
|
- spec/value_coercion_via_dry_types_spec.rb
|