dry-types 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -0
- data/dry-types.gemspec +2 -2
- data/lib/dry/types.rb +2 -0
- data/lib/dry/types/builder.rb +3 -3
- data/lib/dry/types/coercions/form.rb +21 -17
- data/lib/dry/types/compiler.rb +1 -1
- data/lib/dry/types/form.rb +2 -2
- data/lib/dry/types/maybe.rb +3 -2
- data/lib/dry/types/options.rb +1 -1
- data/lib/dry/types/sum.rb +1 -0
- data/lib/dry/types/version.rb +1 -1
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1311828855bfe56729ac94279d1522da021a55
|
4
|
+
data.tar.gz: 20154b9c7e7cdbd446d722e3f472382d7563008d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 244f03d865c9c63d2a1bf7b84bdf1dd5e52d6c4066a86b2603b5b2462411dc5f0411ff014e7567ccc5eda9eb325e82c26c9eec81656976ad3a48e77d1822c944
|
7
|
+
data.tar.gz: ef5a74967de5c2a3824cac9717ec80982f3749858751af79d0ff32f1368220c17b6e6d7ddfa9c8337596cb119ad97555d12aaf0030ed403fe915c1f99acfd533
|
data/.travis.yml
CHANGED
@@ -12,7 +12,6 @@ rvm:
|
|
12
12
|
- rbx-2
|
13
13
|
- jruby-9000
|
14
14
|
- ruby-head
|
15
|
-
- jruby-head
|
16
15
|
env:
|
17
16
|
global:
|
18
17
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
@@ -20,6 +19,9 @@ matrix:
|
|
20
19
|
allow_failures:
|
21
20
|
- rvm: ruby-head
|
22
21
|
- rvm: jruby-head
|
22
|
+
include:
|
23
|
+
- rvm: jruby-head
|
24
|
+
before_install: gem install bundler --no-ri --no-rdoc
|
23
25
|
notifications:
|
24
26
|
email: false
|
25
27
|
webhooks:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
# v0.7.2 2016-05-11
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- `Bool#default` gladly accepts `false` as its value (solnic)
|
6
|
+
- Creating an empty schema with input processor no longer fails (lasseebert)
|
7
|
+
|
8
|
+
## Changes
|
9
|
+
- Allow multiple calls to meta (solnic)
|
10
|
+
- Allow capitalised versions of true and false values for boolean coercions (nil0bject)
|
11
|
+
- Replace kleisli with dry-monads (flash-gordon)
|
12
|
+
- Use coercions from Kernel (flash-gordon)
|
13
|
+
- Decimal coercions now work with Float (flash-gordon)
|
14
|
+
- Coerce empty strings in form posts to blank arrays and hashes (timriley)
|
15
|
+
- update to use dry-logic v0.2.3 (fran-worley)
|
16
|
+
|
17
|
+
[Compare v0.7.0...v0.7.1](https://github.com/dryrb/dry-types/compare/v0.7.1...v0.7.2)
|
18
|
+
|
1
19
|
# v0.7.1 2016-04-06
|
2
20
|
|
3
21
|
## Added
|
data/Gemfile
CHANGED
data/dry-types.gemspec
CHANGED
@@ -31,9 +31,9 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_runtime_dependency 'dry-container', '~> 0.3'
|
32
32
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
33
33
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
|
34
|
-
spec.add_runtime_dependency 'dry-logic', '~> 0.2', '>= 0.2.
|
34
|
+
spec.add_runtime_dependency 'dry-logic', '~> 0.2', '>= 0.2.3'
|
35
35
|
spec.add_runtime_dependency 'inflecto', '~> 0.0.0', '>= 0.0.2'
|
36
|
-
spec.add_runtime_dependency '
|
36
|
+
spec.add_runtime_dependency 'dry-monads', '>= 0.0.1'
|
37
37
|
|
38
38
|
spec.add_development_dependency "bundler", "~> 1.6"
|
39
39
|
spec.add_development_dependency "rake", "~> 11.0"
|
data/lib/dry/types.rb
CHANGED
data/lib/dry/types/builder.rb
CHANGED
@@ -22,8 +22,8 @@ module Dry
|
|
22
22
|
constrained_type.new(self, rule: Types.Rule(options))
|
23
23
|
end
|
24
24
|
|
25
|
-
def default(input =
|
26
|
-
value = input ?
|
25
|
+
def default(input = Undefined, &block)
|
26
|
+
value = input == Undefined ? block : input
|
27
27
|
|
28
28
|
if value.is_a?(Proc) || valid?(value)
|
29
29
|
Default[value].new(self, value: value)
|
@@ -33,7 +33,7 @@ module Dry
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def enum(*values)
|
36
|
-
Enum.new(constrained(
|
36
|
+
Enum.new(constrained(included_in: values), values: values)
|
37
37
|
end
|
38
38
|
|
39
39
|
def safe
|
@@ -5,8 +5,8 @@ module Dry
|
|
5
5
|
module Types
|
6
6
|
module Coercions
|
7
7
|
module Form
|
8
|
-
TRUE_VALUES = %w[1 on
|
9
|
-
FALSE_VALUES = %w[0 off f false n no].freeze
|
8
|
+
TRUE_VALUES = %w[1 on On ON t true True TRUE y yes Yes YES].freeze
|
9
|
+
FALSE_VALUES = %w[0 off Off OFF f false False FALSE n no No NO].freeze
|
10
10
|
BOOLEAN_MAP = ::Hash[TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])].freeze
|
11
11
|
|
12
12
|
extend Coercions
|
@@ -20,38 +20,42 @@ module Dry
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.to_int(input)
|
23
|
-
|
24
|
-
|
25
|
-
result = input.to_i
|
26
|
-
|
27
|
-
if result === 0 && !input.eql?('0')
|
28
|
-
input
|
23
|
+
if empty_str?(input)
|
24
|
+
nil
|
29
25
|
else
|
30
|
-
|
26
|
+
Integer(input)
|
31
27
|
end
|
28
|
+
rescue ArgumentError, TypeError
|
29
|
+
input
|
32
30
|
end
|
33
31
|
|
34
32
|
def self.to_float(input)
|
35
|
-
|
36
|
-
|
37
|
-
result = input.to_f
|
38
|
-
|
39
|
-
if result.eql?(0.0) && (!input.eql?('0') && !input.eql?('0.0'))
|
40
|
-
input
|
33
|
+
if empty_str?(input)
|
34
|
+
nil
|
41
35
|
else
|
42
|
-
|
36
|
+
Float(input)
|
43
37
|
end
|
38
|
+
rescue ArgumentError, TypeError
|
39
|
+
input
|
44
40
|
end
|
45
41
|
|
46
42
|
def self.to_decimal(input)
|
47
43
|
result = to_float(input)
|
48
44
|
|
49
45
|
if result.instance_of?(Float)
|
50
|
-
|
46
|
+
input.to_d
|
51
47
|
else
|
52
48
|
result
|
53
49
|
end
|
54
50
|
end
|
51
|
+
|
52
|
+
def self.to_ary(input)
|
53
|
+
empty_str?(input) ? [] : input
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.to_hash(input)
|
57
|
+
empty_str?(input) ? {} : input
|
58
|
+
end
|
55
59
|
end
|
56
60
|
end
|
57
61
|
end
|
data/lib/dry/types/compiler.rb
CHANGED
data/lib/dry/types/form.rb
CHANGED
@@ -43,11 +43,11 @@ module Dry
|
|
43
43
|
end
|
44
44
|
|
45
45
|
register('form.array') do
|
46
|
-
self['array'].safe
|
46
|
+
self['array'].safe.constructor(Coercions::Form.method(:to_ary))
|
47
47
|
end
|
48
48
|
|
49
49
|
register('form.hash') do
|
50
|
-
self['hash'].safe
|
50
|
+
self['hash'].safe.constructor(Coercions::Form.method(:to_hash))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/lib/dry/types/maybe.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'dry/monads/maybe'
|
2
2
|
require 'dry/types/decorator'
|
3
3
|
|
4
4
|
module Dry
|
@@ -6,9 +6,10 @@ module Dry
|
|
6
6
|
class Maybe
|
7
7
|
include Decorator
|
8
8
|
include Builder
|
9
|
+
include Dry::Monads::Maybe::Mixin
|
9
10
|
|
10
11
|
def call(input)
|
11
|
-
input.is_a?(
|
12
|
+
input.is_a?(Dry::Monads::Maybe) ? input : Maybe(type[input])
|
12
13
|
end
|
13
14
|
alias_method :[], :call
|
14
15
|
|
data/lib/dry/types/options.rb
CHANGED
data/lib/dry/types/sum.rb
CHANGED
data/lib/dry/types/version.rb
CHANGED
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.7.
|
4
|
+
version: 0.7.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: 2016-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
version: '0.2'
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: 0.2.
|
78
|
+
version: 0.2.3
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
version: '0.2'
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.2.
|
88
|
+
version: 0.2.3
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: inflecto
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,19 +107,19 @@ dependencies:
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: 0.0.2
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
|
-
name:
|
110
|
+
name: dry-monads
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
|
-
- - "
|
113
|
+
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
115
|
+
version: 0.0.1
|
116
116
|
type: :runtime
|
117
117
|
prerelease: false
|
118
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- - "
|
120
|
+
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
122
|
+
version: 0.0.1
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
name: bundler
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -236,10 +236,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
236
|
version: '0'
|
237
237
|
requirements: []
|
238
238
|
rubyforge_project:
|
239
|
-
rubygems_version: 2.
|
239
|
+
rubygems_version: 2.4.8
|
240
240
|
signing_key:
|
241
241
|
specification_version: 4
|
242
242
|
summary: Type system for Ruby supporting coercions, constraints and complex types
|
243
243
|
like structs, value objects, enums etc.
|
244
244
|
test_files: []
|
245
|
-
has_rdoc:
|