dry-data 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 443ed733b824f1645a6e8fe1b6bc656110166920
4
- data.tar.gz: 97fe87cf2594a29d4034f5323876ec654b069c9c
3
+ metadata.gz: f8a5fe08504f98f2f3e85ae1f07ac1773cd53b18
4
+ data.tar.gz: e22495f0d07c2fe8f933ebc777aacbbc417b8fd3
5
5
  SHA512:
6
- metadata.gz: 49bef55bd41e2075c3448658bc4ac79ea62c3deb3dd3a6a79fb3d30142ed389f39559beaa31352b7bc966995042093e6ec1553c7434e85d0a3e3e983d123b644
7
- data.tar.gz: a4cf5f5e5f0c4d6510def73f6a4e65a6e3f59624254ee946442cf0f91943c7746224835e3cfe62b934f52043e95f1e7b85e91c3ad8f601da2e5e4003973677fd
6
+ metadata.gz: e72b078024b770b78a6b8bde42570314d57fedd55b1517a49d73b7b2f4f37d453fc36cd3db661f5b38c13f6340f4339c59fd5743fa57f9dcba651f5f1a89c2ef
7
+ data.tar.gz: 9518ca648f2fa8665c95742c3faaf18d138aab32af1d1c0ed2d9a9fe40fda47ca27369f0ff6e8799cde999c0fe041ea8c83261d42233b9eda0c52eccbeea7241
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.3.1 2015-12-09
2
+
3
+ ## Changed
4
+
5
+ * Removed require of constrained type and make it optional (solnic)
6
+
7
+ [Compare v0.3.0...v0.3.1](https://github.com/dryrb/dry-data/compare/v0.3.0...v0.3.1)
8
+
1
9
  # v0.3.0 2015-12-09
2
10
 
3
11
  ## Added
data/README.md CHANGED
@@ -179,6 +179,12 @@ and all of its predicates are supported.
179
179
  IMPORTANT: `dry-data` does not have a runtime dependency on `dry-validation` so
180
180
  if you want to use contrained types you need to add it to your Gemfile
181
181
 
182
+ If you want to use constrained type you need to require it explicitly:
183
+
184
+ ``` ruby
185
+ require "dry/data/type/constrained"
186
+ ```
187
+
182
188
  ``` ruby
183
189
  string = Dry::Data["strict.string"].constrained(min_size: 3)
184
190
 
data/lib/dry/data/type.rb CHANGED
@@ -4,7 +4,6 @@ require 'dry/data/type/array'
4
4
  require 'dry/data/type/enum'
5
5
 
6
6
  require 'dry/data/sum_type'
7
- require 'dry/data/constraints'
8
7
 
9
8
  module Dry
10
9
  module Data
@@ -59,10 +58,6 @@ module Dry
59
58
  @primitive = primitive
60
59
  end
61
60
 
62
- def constrained(options)
63
- Constrained.new(constructor, primitive, Data.Rule(primitive, options))
64
- end
65
-
66
61
  def enum(*values)
67
62
  Enum.new(values, constrained(inclusion: values))
68
63
  end
@@ -0,0 +1,31 @@
1
+ require 'dry/data/constraints'
2
+
3
+ module Dry
4
+ module Data
5
+ class Type
6
+ class Constrained < Type
7
+ attr_reader :rule
8
+
9
+ def initialize(constructor, primitive, rule)
10
+ super(constructor, primitive)
11
+ @rule = rule
12
+ end
13
+
14
+ def call(input)
15
+ result = super(input)
16
+
17
+ if rule.(result).success?
18
+ result
19
+ else
20
+ raise ConstraintError, "#{input.inspect} violates constraints"
21
+ end
22
+ end
23
+ alias_method :[], :call
24
+ end
25
+
26
+ def constrained(options)
27
+ Constrained.new(constructor, primitive, Data.Rule(primitive, options))
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Data
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.3.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
@@ -158,6 +158,7 @@ files:
158
158
  - lib/dry/data/sum_type.rb
159
159
  - lib/dry/data/type.rb
160
160
  - lib/dry/data/type/array.rb
161
+ - lib/dry/data/type/constrained.rb
161
162
  - lib/dry/data/type/enum.rb
162
163
  - lib/dry/data/type/hash.rb
163
164
  - lib/dry/data/type/optional.rb
@@ -185,9 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  version: '0'
186
187
  requirements: []
187
188
  rubyforge_project:
188
- rubygems_version: 2.4.5
189
+ rubygems_version: 2.4.5.1
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Simple type-system for Ruby
192
193
  test_files: []
193
- has_rdoc: