dry-types 0.12.1 → 0.12.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7886fadf19e4beced5252aba4a5db6b6912804e6
4
- data.tar.gz: e305a68af891e5e6c68be0859dcc1866f20d460e
3
+ metadata.gz: 1e6d84eedd9c2c6d676816a1e1284c049ff33312
4
+ data.tar.gz: ed578364c03b1762bfa45c13b0fa81d70d4a4acd
5
5
  SHA512:
6
- metadata.gz: 9373b3e8c70db220e865639b9e1080f24c9c8e8c0b6033863ac098af08e5c37d900cd063933402fb42cec26f55a60bf6fcdf2ed846ecaf02572cddf031e25fc8
7
- data.tar.gz: b3f2ba541fd524998b71b243e84500a5a290ba1d98ef7d2089e96d34bf0658abed961b2a2ce1a468774c36cdf34ffdb32798fe9cc3403a0e4452741f6d5e3d9a
6
+ metadata.gz: 3895ac984bbc35327603c300f188672910c81906108ea6150163a67dae00281b54198a89bbb71ef0f1abf2b6dc207089c9a3f635c168ba8002d8db99df765143
7
+ data.tar.gz: b228f7f664b88127c0ed884ea3eb317c0d6f43c0c9692cbae151c2df45273b58768c7c3f42e335a97cc1e85a914d20909ec7d651c90b318aa3a3a78adc92d8dd
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- # v0.12.1 to-be-released
1
+ # v0.12.2 2017-11-04
2
+
3
+ ## Fixed
4
+
5
+ * The type compiler was fixed for simple rules such as used for strict type checks (flash-gordon)
6
+ * Fixed an error on `Dry::Types['json.decimal'].try(nil)` (nesaulov)
7
+ * Fixed an error on calling `try` on an array type built of constrained types (flash-gordon)
8
+ * Implemented `===` for enum types (GustavoCaso)
9
+
10
+ [Compare v0.12.1...v0.12.2](https://github.com/dry-rb/dry-types/compare/v0.12.1...v0.12.2)
11
+
12
+ # v0.12.1 2017-10-11
2
13
 
3
14
  ## Fixed
4
15
 
@@ -7,7 +18,7 @@
7
18
  * Optional sum types work correctly in `safe` mode (GustavoCaso)
8
19
  * The equalizer of constrained types respects meta (flash-gordon)
9
20
 
10
- [Compare v0.12.0...master](https://github.com/dry-rb/dry-types/compare/v0.12.0...master)
21
+ [Compare v0.12.0...v0.12.1](https://github.com/dry-rb/dry-types/compare/v0.12.0...v0.12.1)
11
22
 
12
23
  # v0.12.0 2017-09-15
13
24
 
data/CONTRIBUTING.md CHANGED
@@ -6,11 +6,11 @@ If you found a bug, report an issue and describe what's the expected behavior ve
6
6
 
7
7
  ## Reporting feature requests
8
8
 
9
- Report a feature request **only after discussing it first on [discuss.dry-rb.org](https://discuss.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
9
+ Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
10
 
11
11
  ## Reporting questions, support requests, ideas, concerns etc.
12
12
 
13
- **PLEASE DON'T** - use [discuss.dry-rb.org](http://discuss.dry-rb.org) instead.
13
+ **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
14
14
 
15
15
  # Pull Request Guidelines
16
16
 
@@ -26,4 +26,4 @@ Other requirements:
26
26
 
27
27
  # Asking for help
28
28
 
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discuss.dry-rb.org](https://discuss.dry-rb.org).
29
+ If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ group :test do
10
10
  end
11
11
 
12
12
  group :tools do
13
- gem 'byebug', platform: :mri
13
+ gem 'pry-byebug', platform: :mri
14
14
  gem 'mutant'
15
15
  gem 'mutant-rspec'
16
16
  end
data/lib/dry/types/any.rb CHANGED
@@ -15,6 +15,7 @@ module Dry
15
15
  def valid?(_)
16
16
  true
17
17
  end
18
+ alias_method :===, :valid?
18
19
 
19
20
  # @param [Hash] new_options
20
21
  # @return [Type]
@@ -12,6 +12,7 @@ module Dry
12
12
  # @param [#to_d, Object] input
13
13
  # @return [BigDecimal,nil]
14
14
  def self.to_decimal(input)
15
+ return if input.nil?
15
16
  input.to_d unless empty_str?(input)
16
17
  end
17
18
  end
@@ -44,8 +44,7 @@ module Dry
44
44
  end
45
45
 
46
46
  def visit_rule(node)
47
- operator, rule = node
48
- Dry::Types.rule_compiler.(rule).reduce(operator)
47
+ Dry::Types.rule_compiler.([node])[0]
49
48
  end
50
49
 
51
50
  def visit_sum(node)
@@ -1,14 +1,12 @@
1
1
  module Dry
2
2
  module Types
3
3
  class Constrained
4
- include Type
5
-
6
4
  class Coercible < Constrained
7
5
  # @param [Object] input
8
6
  # @param [#call,nil] block
9
7
  # @yieldparam [Failure] failure
10
8
  # @yieldreturn [Result]
11
- # @return [Result,Logic::Result,nil]
9
+ # @return [Result,nil]
12
10
  def try(input, &block)
13
11
  result = type.try(input)
14
12
 
@@ -18,7 +16,8 @@ module Dry
18
16
  if validation.success?
19
17
  result
20
18
  else
21
- block ? yield(validation) : validation
19
+ failure = failure(result.input, validation)
20
+ block ? yield(failure) : failure
22
21
  end
23
22
  else
24
23
  block ? yield(result) : result
@@ -74,6 +74,7 @@ module Dry
74
74
  def valid?(value)
75
75
  super && type.valid?(value)
76
76
  end
77
+ alias_method :===, :valid?
77
78
 
78
79
  # @return [Class]
79
80
  def constrained_type
@@ -27,6 +27,7 @@ module Dry
27
27
  def valid?(value)
28
28
  type.valid?(value)
29
29
  end
30
+ alias_method :===, :valid?
30
31
 
31
32
  # @return [Boolean]
32
33
  def default?
@@ -69,6 +69,14 @@ module Dry
69
69
  ]
70
70
  end
71
71
 
72
+ # @param [Hash] hash
73
+ # @return [Boolean]
74
+ def valid?(hash)
75
+ result = try(hash)
76
+ result.success?
77
+ end
78
+ alias_method :===, :valid?
79
+
72
80
  private
73
81
 
74
82
  def hash_type
@@ -78,7 +78,7 @@ RSpec.shared_examples_for Dry::Types::Definition do
78
78
  it 'returns a constructor' do
79
79
  constructor = type.constructor(&:to_s)
80
80
 
81
- expect(constructor).to be_instance_of(Dry::Types::Constructor)
81
+ expect(constructor).to be_a(Dry::Types::Type)
82
82
  end
83
83
  end
84
84
  end
data/lib/dry/types/sum.rb CHANGED
@@ -120,6 +120,7 @@ module Dry
120
120
  def valid?(value)
121
121
  left.valid?(value) || right.valid?(value)
122
122
  end
123
+ alias_method :===, :valid?
123
124
 
124
125
  # @api public
125
126
  #
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Types
3
- VERSION = '0.12.1'.freeze
3
+ VERSION = '0.12.2'.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.1
4
+ version: 0.12.2
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-10-11 00:00:00.000000000 Z
11
+ date: 2017-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  version: '0'
275
275
  requirements: []
276
276
  rubyforge_project:
277
- rubygems_version: 2.6.11
277
+ rubygems_version: 2.6.13
278
278
  signing_key:
279
279
  specification_version: 4
280
280
  summary: Type system for Ruby supporting coercions, constraints and complex types