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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ca173b64639db4a874bc33694d2a8df9f9e0500
4
- data.tar.gz: 4bcf324022827e5145dc0cbcc4376a0958e5595f
3
+ metadata.gz: 7c1311828855bfe56729ac94279d1522da021a55
4
+ data.tar.gz: 20154b9c7e7cdbd446d722e3f472382d7563008d
5
5
  SHA512:
6
- metadata.gz: 4f44642bb9ddfb9911fba8439b5dbcbfaa55bafbd47755c23f6279bc37da155c06e6100c56bdaebc1c783fdccd8e892b14f5b36b6eee9c81d21a3b0a9ebe2971
7
- data.tar.gz: 5db7721ac8611a08167a91106ad5097db5796fb8664c3f36502ef7ac92706902b3e262bf5c1e9e4c1b20b045df9bfe87073acdd555322bda8b303e9bdb2088a6
6
+ metadata.gz: 244f03d865c9c63d2a1bf7b84bdf1dd5e52d6c4066a86b2603b5b2462411dc5f0411ff014e7567ccc5eda9eb325e82c26c9eec81656976ad3a48e77d1822c944
7
+ data.tar.gz: ef5a74967de5c2a3824cac9717ec80982f3749858751af79d0ff32f1368220c17b6e6d7ddfa9c8337596cb119ad97555d12aaf0030ed403fe915c1f99acfd533
@@ -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:
@@ -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
@@ -20,3 +20,5 @@ group :benchmarks do
20
20
  gem 'fast_attributes'
21
21
  gem 'attrio'
22
22
  end
23
+
24
+ gem "dry-logic", git: 'https://github.com/dry-rb/dry-logic.git', branch: "master"
@@ -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.0'
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 'kleisli', '~> 0.2'
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"
@@ -21,6 +21,8 @@ module Dry
21
21
  module Types
22
22
  extend Dry::Configurable
23
23
 
24
+ Undefined = Object.new.freeze
25
+
24
26
  setting :namespace, self
25
27
 
26
28
  TYPE_SPEC_REGEX = %r[(.+)<(.+)>].freeze
@@ -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 = nil, &block)
26
- value = input ? input : block
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(inclusion: values), values: values)
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 t true y yes].freeze
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
- return if empty_str?(input)
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
- result
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
- return if empty_str?(input)
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
- result
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
- result.to_d
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
@@ -77,7 +77,7 @@ module Dry
77
77
 
78
78
  def merge_with(hash_id, constructor, schema)
79
79
  registry[hash_id].__send__(
80
- constructor, schema.map { |key| visit(key) }.reduce(:merge)
80
+ constructor, schema.map { |key| visit(key) }.reduce({}, :merge)
81
81
  )
82
82
  end
83
83
  end
@@ -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
@@ -1,4 +1,4 @@
1
- require 'kleisli/maybe'
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?(Kleisli::Maybe) ? input : Maybe(type[input])
12
+ input.is_a?(Dry::Monads::Maybe) ? input : Maybe(type[input])
12
13
  end
13
14
  alias_method :[], :call
14
15
 
@@ -16,7 +16,7 @@ module Dry
16
16
  end
17
17
 
18
18
  def meta(data = nil)
19
- data ? with(meta: data) : @meta
19
+ data ? with(meta: @meta.merge(data)) : @meta
20
20
  end
21
21
  end
22
22
  end
@@ -3,6 +3,7 @@ require 'dry/types/options'
3
3
  module Dry
4
4
  module Types
5
5
  class Sum
6
+ include Dry::Equalizer(:left, :right, :options)
6
7
  include Builder
7
8
  include Options
8
9
 
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Types
3
- VERSION = '0.7.1'.freeze
3
+ VERSION = '0.7.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.7.1
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-04-06 00:00:00.000000000 Z
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.0
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.0
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: kleisli
110
+ name: dry-monads
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '0.2'
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: '0.2'
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.5.1
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: