dry-types 0.12.0 → 0.12.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: 336c6e4da78c6b66a32a43671d7961b5a9e26e78
4
- data.tar.gz: 282770ba63247f594e89071ad36677689fe7ddc7
3
+ metadata.gz: 7886fadf19e4beced5252aba4a5db6b6912804e6
4
+ data.tar.gz: e305a68af891e5e6c68be0859dcc1866f20d460e
5
5
  SHA512:
6
- metadata.gz: af9f5770f1ae7e750589b016bba706eb874cacb8d282b013493ec81c2344af35abde95eb3609c6f80fb907ca17abc7c964f25a9c290ee0fe9992f3cd131885e6
7
- data.tar.gz: 9a7711e6c22eb5889448ce10adbcbb48cb02e1d6a9ee91c43707556e68b6e57e048507382a13d28a00940befca06d88329ec99ce7132dcefd4857a3435b92b8c
6
+ metadata.gz: 9373b3e8c70db220e865639b9e1080f24c9c8e8c0b6033863ac098af08e5c37d900cd063933402fb42cec26f55a60bf6fcdf2ed846ecaf02572cddf031e25fc8
7
+ data.tar.gz: b3f2ba541fd524998b71b243e84500a5a290ba1d98ef7d2089e96d34bf0658abed961b2a2ce1a468774c36cdf34ffdb32798fe9cc3403a0e4452741f6d5e3d9a
@@ -1,3 +1,14 @@
1
+ # v0.12.1 to-be-released
2
+
3
+ ## Fixed
4
+
5
+ * `Constructor#try` rescues `ArgumentError` (raised in cases like `Integer('foo')`) (flash-gordon)
6
+ * `#constructor` works correctly for default and enum types (solnic)
7
+ * Optional sum types work correctly in `safe` mode (GustavoCaso)
8
+ * The equalizer of constrained types respects meta (flash-gordon)
9
+
10
+ [Compare v0.12.0...master](https://github.com/dry-rb/dry-types/compare/v0.12.0...master)
11
+
1
12
  # v0.12.0 2017-09-15
2
13
 
3
14
  ## Added
data/Gemfile CHANGED
@@ -20,6 +20,7 @@ group :benchmarks do
20
20
  gem 'virtus'
21
21
  gem 'fast_attributes'
22
22
  gem 'attrio'
23
+ gem 'dry-struct'
23
24
  end
24
25
 
25
26
  gem 'dry-logic', git: 'https://github.com/dry-rb/dry-logic'
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ task :run_specs do
7
7
  RSpec::Core::Runner.run(['spec/dry'])
8
8
  RSpec.clear_examples
9
9
 
10
- load 'spec/dry/types.rb'
11
10
  Dry::Types.load_extensions(:maybe)
12
11
  RSpec::Core::Runner.run(['spec'])
13
12
  end
@@ -16,6 +16,11 @@ module Dry
16
16
  send(:"visit_#{ type }", body)
17
17
  end
18
18
 
19
+ def visit_constrained(node)
20
+ definition, rule, meta = node
21
+ Types::Constrained.new(visit(definition), rule: visit_rule(rule)).meta(meta)
22
+ end
23
+
19
24
  def visit_constructor(node)
20
25
  definition, fn_register_name, meta = node
21
26
  fn = Dry::Types::FnContainer[fn_register_name]
@@ -38,6 +43,11 @@ module Dry
38
43
  end
39
44
  end
40
45
 
46
+ def visit_rule(node)
47
+ operator, rule = node
48
+ Dry::Types.rule_compiler.(rule).reduce(operator)
49
+ end
50
+
41
51
  def visit_sum(node)
42
52
  *types, meta = node
43
53
  types.map { |type| visit(type) }.reduce(:|).meta(meta)
@@ -6,7 +6,7 @@ module Dry
6
6
  module Types
7
7
  class Constrained
8
8
  include Type
9
- include Dry::Equalizer(:type, :options, :rule)
9
+ include Dry::Equalizer(:type, :options, :rule, :meta)
10
10
  include Decorator
11
11
  include Builder
12
12
 
@@ -54,7 +54,7 @@ module Dry
54
54
  # @return [Object] if block given and try fails
55
55
  def try(input, &block)
56
56
  type.try(fn[input], &block)
57
- rescue TypeError => e
57
+ rescue TypeError, ArgumentError => e
58
58
  failure(input, e.message)
59
59
  end
60
60
 
@@ -14,11 +14,6 @@ module Dry
14
14
  @type = type
15
15
  end
16
16
 
17
- # @return [Constructor]
18
- def constructor
19
- type.constructor
20
- end
21
-
22
17
  # @param [Object] input
23
18
  # @param [#call, nil] block
24
19
  # @return [Result,Logic::Result]
@@ -73,4 +73,12 @@ RSpec.shared_examples_for Dry::Types::Definition do
73
73
  expect(type.primitive).to be_instance_of(Class)
74
74
  end
75
75
  end
76
+
77
+ describe '#constructor' do
78
+ it 'returns a constructor' do
79
+ constructor = type.constructor(&:to_s)
80
+
81
+ expect(constructor).to be_instance_of(Dry::Types::Constructor)
82
+ end
83
+ end
76
84
  end
@@ -91,6 +91,24 @@ module Dry
91
91
  end
92
92
  end
93
93
 
94
+ def success(input)
95
+ if left.valid?(input)
96
+ left.success(input)
97
+ elsif right.valid?(input)
98
+ right.success(input)
99
+ else
100
+ raise ArgumentError, "Invalid success value '#{input}' for #{inspect}"
101
+ end
102
+ end
103
+
104
+ def failure(input)
105
+ if !left.valid?(input)
106
+ left.failure(input, left.try(input).error)
107
+ else
108
+ right.failure(input, right.try(input).error)
109
+ end
110
+ end
111
+
94
112
  # @param [Object] value
95
113
  # @return [Boolean]
96
114
  def primitive?(value)
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Types
3
- VERSION = '0.12.0'.freeze
3
+ VERSION = '0.12.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -248,10 +248,10 @@ files:
248
248
  - lib/dry/types/options.rb
249
249
  - lib/dry/types/result.rb
250
250
  - lib/dry/types/safe.rb
251
+ - lib/dry/types/spec/types.rb
251
252
  - lib/dry/types/sum.rb
252
253
  - lib/dry/types/type.rb
253
254
  - lib/dry/types/version.rb
254
- - lib/spec/dry/types.rb
255
255
  - log/.gitkeep
256
256
  homepage: https://github.com/dry-rb/dry-types
257
257
  licenses: