dry-initializer 0.3.3 → 0.4.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: bd083cbbcdfaa027e91d0c7aa5c3ecd1f7a7b360
4
- data.tar.gz: 62d78221803dee64e5941047f50d340b84437e57
3
+ metadata.gz: 7db8f3d16f5e690b2184d79d06d2417e2dab2810
4
+ data.tar.gz: 03a361fa17734d5d37d8da5f647e975e36ee8d1f
5
5
  SHA512:
6
- metadata.gz: 12eaa06d640341428da9beb87c79c33b9c2ce09ada2da4229c731693c362395e8f4c132856dbbd4fe986ccbd80532bf71448de6e1c6f1ce1cd050f19bad8b2fa
7
- data.tar.gz: 93bbdd93691abe4efaa68d48510690a23a6b698673fbf9d52327ecb83539c55ebce5607c494d11430390ee182661dd71e56f516d963363785c4c6214b03261a5
6
+ metadata.gz: f879fb0ae4169c9a402df913d7b00f4c38e9349ca7d200c43687f5c28970e81466c3152a19b61249299451213b93ee9ce971b949d3eb0f163ebce6c55304bf3b
7
+ data.tar.gz: cc7a1b201b934f10c1d09a09f2b22820361135c4da201c4778828836b55dd7633e0b8db8e9673071e3344a56c73498ab036f787dec8be57bd57169c07872532b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v0.4.0 2016-05-28
2
+
3
+ ### Deleted (backward-incompatible changes)
4
+
5
+ * Support of modules and case equality as type constraints (@nepalez)
6
+
7
+ [Compare v0.3.3...v0.4.0](https://github.com/dry-rb/dry-initializer/compare/v0.3.3..v0.4.0)
8
+
1
9
  ## v0.3.3 2016-05-28
2
10
 
3
11
  * Add deprecation warnings about modules and case equality as type constraints (@nepalez)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "0.3.3"
3
+ gem.version = "0.4.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"
@@ -5,7 +5,6 @@ module Dry::Initializer
5
5
  require_relative "errors/order_error"
6
6
  require_relative "errors/plugin_error"
7
7
  require_relative "errors/redefinition_error"
8
- require_relative "errors/type_error"
9
8
  require_relative "errors/type_constraint_error"
10
9
  end
11
10
  end
@@ -1,6 +1,5 @@
1
1
  class Dry::Initializer::Errors::TypeConstraintError < TypeError
2
2
  def initialize(name, type)
3
- super "#{type} is inacceptable constraint for the argument '#{name}'." \
4
- " Use either plain Ruby module/class, or dry-type."
3
+ super "#{type} used as constraint for argument '#{name}' is not a dry-type."
5
4
  end
6
5
  end
@@ -4,60 +4,15 @@ module Dry::Initializer::Plugins
4
4
  class TypeConstraint < Base
5
5
  def call
6
6
  return unless settings.key? :type
7
- dry_type_constraint || module_type_constraint || object_type_constraint
8
- end
9
-
10
- private
11
-
12
- def type
13
- @type ||= settings[:type]
14
- end
15
-
16
- def dry_type?
17
- type.respond_to? :call
18
- end
19
-
20
- def plain_type?
21
- Module === type
22
- end
23
-
24
- def module_type_constraint
25
- return unless plain_type?
26
-
27
- warn "[DEPRECATION] support for ruby modules as type constraint" \
28
- " is deprecated. Use dry-types instead."
29
-
30
- "fail #{TypeError}.new(:#{name}, #{type}, @#{name})" \
31
- " unless @#{name} == Dry::Initializer::UNDEFINED ||" \
32
- " #{type} === @#{name}"
33
- end
34
7
 
35
- def dry_type_constraint
36
- return unless dry_type?
8
+ type = settings[:type]
9
+ fail TypeConstraintError.new(name, type) unless type.respond_to? :call
37
10
 
38
11
  ivar = :"@#{name}"
39
- constraint = type
40
-
41
- lambda do |*|
42
- value = instance_variable_get(ivar)
43
- return if value == Dry::Initializer::UNDEFINED
44
-
45
- instance_variable_set ivar, constraint[value]
46
- end
47
- end
48
-
49
- def object_type_constraint
50
- warn "[DEPRECATION] support for case equality (===) as type constraint" \
51
- " is deprecated. Use dry-types instead."
52
-
53
- ivar = :"@#{name}"
54
- constraint = type
55
-
56
12
  lambda do |*|
57
13
  value = instance_variable_get(ivar)
58
14
  return if value == Dry::Initializer::UNDEFINED
59
-
60
- fail TypeError.new(ivar, constraint, value) unless constraint === value
15
+ instance_variable_set ivar, type.call(value)
61
16
  end
62
17
  end
63
18
  end
@@ -0,0 +1,43 @@
1
+ require "dry-types"
2
+
3
+ describe "type constraint" do
4
+ context "by dry-type" do
5
+ before do
6
+ module Test::Types
7
+ include Dry::Types.module
8
+ end
9
+
10
+ class Test::Foo
11
+ extend Dry::Initializer::Mixin
12
+ param :foo, type: Test::Types::Strict::String
13
+ end
14
+ end
15
+
16
+ context "in case of mismatch" do
17
+ subject { Test::Foo.new 1 }
18
+
19
+ it "raises TypeError" do
20
+ expect { subject }.to raise_error TypeError, /1/
21
+ end
22
+ end
23
+
24
+ context "in case of match" do
25
+ subject { Test::Foo.new "foo" }
26
+
27
+ it "completes the initialization" do
28
+ expect { subject }.not_to raise_error
29
+ end
30
+ end
31
+ end
32
+
33
+ context "by invalid constraint" do
34
+ it "raises TypeError" do
35
+ expect {
36
+ class Test::Foo
37
+ extend Dry::Initializer::Mixin
38
+ param :foo, type: String
39
+ end
40
+ }.to raise_error(TypeError)
41
+ end
42
+ end
43
+ 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.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kochnev (marshall-lee)
@@ -98,7 +98,6 @@ files:
98
98
  - lib/dry/initializer/errors/plugin_error.rb
99
99
  - lib/dry/initializer/errors/redefinition_error.rb
100
100
  - lib/dry/initializer/errors/type_constraint_error.rb
101
- - lib/dry/initializer/errors/type_error.rb
102
101
  - lib/dry/initializer/mixin.rb
103
102
  - lib/dry/initializer/plugins.rb
104
103
  - lib/dry/initializer/plugins/base.rb
@@ -111,16 +110,14 @@ files:
111
110
  - spec/dry/container_spec.rb
112
111
  - spec/dry/default_nil_spec.rb
113
112
  - spec/dry/default_values_spec.rb
114
- - spec/dry/dry_type_constraint_spec.rb
115
113
  - spec/dry/invalid_default_spec.rb
116
114
  - spec/dry/missed_default_spec.rb
117
- - spec/dry/object_type_constraint_spec.rb
118
115
  - spec/dry/options_tolerance_spec.rb
119
- - spec/dry/plain_type_constraint_spec.rb
120
116
  - spec/dry/plugin_registry_spec.rb
121
117
  - spec/dry/reader_spec.rb
122
118
  - spec/dry/repetitive_definitions_spec.rb
123
119
  - spec/dry/subclassing_spec.rb
120
+ - spec/dry/type_constraint_spec.rb
124
121
  - spec/dry/value_coercion_via_dry_types_spec.rb
125
122
  - spec/spec_helper.rb
126
123
  homepage: https://github.com/dryrb/dry-initializer
@@ -152,16 +149,14 @@ test_files:
152
149
  - spec/dry/container_spec.rb
153
150
  - spec/dry/default_nil_spec.rb
154
151
  - spec/dry/default_values_spec.rb
155
- - spec/dry/dry_type_constraint_spec.rb
156
152
  - spec/dry/invalid_default_spec.rb
157
153
  - spec/dry/missed_default_spec.rb
158
- - spec/dry/object_type_constraint_spec.rb
159
154
  - spec/dry/options_tolerance_spec.rb
160
- - spec/dry/plain_type_constraint_spec.rb
161
155
  - spec/dry/plugin_registry_spec.rb
162
156
  - spec/dry/reader_spec.rb
163
157
  - spec/dry/repetitive_definitions_spec.rb
164
158
  - spec/dry/subclassing_spec.rb
159
+ - spec/dry/type_constraint_spec.rb
165
160
  - spec/dry/value_coercion_via_dry_types_spec.rb
166
161
  - spec/spec_helper.rb
167
162
  has_rdoc:
@@ -1,6 +0,0 @@
1
- class Dry::Initializer::Errors::TypeError < TypeError
2
- def initialize(name, type, value)
3
- super "A value #{value.inspect} assigned to the argument '#{name}'" \
4
- " mismatches type constraint: #{type}."
5
- end
6
- end
@@ -1,30 +0,0 @@
1
- require "dry-types"
2
-
3
- describe "Dry type constraint" do
4
- before do
5
- module Test::Types
6
- include Dry::Types.module
7
- end
8
-
9
- class Test::Foo
10
- extend Dry::Initializer::Mixin
11
- param :foo, type: Test::Types::Strict::String
12
- end
13
- end
14
-
15
- context "in case of mismatch" do
16
- subject { Test::Foo.new 1 }
17
-
18
- it "raises TypeError" do
19
- expect { subject }.to raise_error TypeError, /1/
20
- end
21
- end
22
-
23
- context "in case of match" do
24
- subject { Test::Foo.new "foo" }
25
-
26
- it "completes the initialization" do
27
- expect { subject }.not_to raise_error
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- describe "object type constraint" do
2
- before do
3
- class Test::Foo
4
- extend Dry::Initializer::Mixin
5
-
6
- param :foo, type: /bar/
7
- end
8
- end
9
-
10
- context "in case of mismatch" do
11
- subject { Test::Foo.new "baz" }
12
-
13
- it "raises TypeError" do
14
- expect { subject }.to raise_error TypeError
15
- end
16
- end
17
-
18
- context "in case of match" do
19
- subject { Test::Foo.new "barbar" }
20
-
21
- it "completes the initialization" do
22
- expect { subject }.not_to raise_error
23
- end
24
- end
25
- end
@@ -1,33 +0,0 @@
1
- describe "plain type constraint" do
2
- before do
3
- class Test::Foo
4
- extend Dry::Initializer::Mixin
5
-
6
- param :foo, type: String
7
- end
8
- end
9
-
10
- context "in case of mismatch" do
11
- subject { Test::Foo.new :foo }
12
-
13
- it "raises TypeError" do
14
- expect { subject }.to raise_error TypeError, /:foo/
15
- end
16
- end
17
-
18
- context "in case of match" do
19
- subject { Test::Foo.new "foo" }
20
-
21
- it "completes the initialization" do
22
- expect { subject }.not_to raise_error
23
- end
24
- end
25
-
26
- context "in case of soft match" do
27
- subject { Test::Foo.new Class.new(String).new "foo" }
28
-
29
- it "completes the initialization" do
30
- expect { subject }.not_to raise_error
31
- end
32
- end
33
- end