dry-logic 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: '092fd6393e21a754ce653a7b24dfdcb2dacb719723b9e3bb6607c2ba73962bde'
4
- data.tar.gz: 3b3a2407f0cdf5f4d17c3bae1888f32d8c63ca666cecc5d6266ee4604ce6f551
3
+ metadata.gz: 6a09361d1d78293fe7254b7c92dd29b26df899630db88cf5aa9c8a99b369eb38
4
+ data.tar.gz: 8aa9c03d77c492207dbef23a8b06d10f698e0f54def07e356847e4116eb9ca69
5
5
  SHA512:
6
- metadata.gz: a0ddca4a58b60a896077cc5c1d4b66e4c54470fb4182475e343bc90e3cdb6ec0e913784fc0c992c6e247532cfcdd50c2d47f48f467f443b71cab0f92fbf5d6da
7
- data.tar.gz: a164d2b12242437c48d035e0cb139b1a24373d1d79f074d6b718fb81e7a6303f23cfc85c352fbfe8fdd9adf9602e44049d0bdcb15689d376b43a5b56fce549a6
6
+ metadata.gz: 5780b5badd5db51a5bd8f8c275cf114a786d0860be4c949a88327b243476a779a020d4e3323e2561fa96ba87382e64b63cdc473b10ce346d13ea533fc67b1936
7
+ data.tar.gz: 649e7727b08808abf58378ffaa191796945070e45f2bf5c502b560f7c1a33506d5e17d55cef52c52827431d145bb1907bbc81622ff64870428cfdbd0afec3bdb
@@ -1,3 +1,23 @@
1
+ # v1.0.3 2019-08-01
2
+
3
+ ### Added
4
+
5
+ * `bytesize?` predicate (@bmalinconico)
6
+ * `min_bytesize?` predicate (@bmalinconico)
7
+ * `max_bytesize? predicate (@bmalinconico)
8
+
9
+ ### Changed
10
+
11
+ * Min ruby version was set to `>= 2.4.0` (@flash-gordon)
12
+
13
+ [Compare v1.0.2...v1.0.3](https://github.com/dry-rb/dry-logic/compare/v1.0.2...v1.0.3)
14
+
15
+ # v1.0.2 2019-06-14
16
+
17
+ Re-pushed 1.0.1 after dry-schema 1.2.0 release.
18
+
19
+ [Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-logic/compare/v1.0.1...v1.0.2)
20
+
1
21
  # v1.0.1 2019-06-04 (yanked)
2
22
 
3
23
  ### Added
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [gem]: https://rubygems.org/gems/dry-logic
2
- [travis]: https://travis-ci.org/dry-rb/dry-logic
2
+ [travis]: https://travis-ci.com/dry-rb/dry-logic
3
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-logic
4
4
  [chat]: https://dry-rb.zulipchat.com
5
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-logic
@@ -7,7 +7,7 @@
7
7
  # dry-logic [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/dry-logic.svg)][gem]
10
- [![Build Status](https://travis-ci.org/dry-rb/dry-logic.svg?branch=master)][travis]
10
+ [![Build Status](https://travis-ci.com/dry-rb/dry-logic.svg?branch=master)][travis]
11
11
  [![Code Climate](https://codeclimate.com/github/dry-rb/dry-logic/badges/gpa.svg)][codeclimate]
12
12
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-logic/badges/coverage.svg)][codeclimate]
13
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-logic.svg?branch=master)][inchpages]
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.files = `git ls-files -z`.split("\x0")
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ['lib']
17
+ spec.required_ruby_version = '>= 2.4.0'
17
18
 
18
19
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
19
20
  spec.add_runtime_dependency 'dry-core', '~> 0.2'
@@ -59,11 +59,9 @@ module Dry
59
59
  end
60
60
 
61
61
  def number?(input)
62
- begin
63
- true if Float(input)
64
- rescue ArgumentError, TypeError
65
- false
66
- end
62
+ true if Float(input)
63
+ rescue ArgumentError, TypeError
64
+ false
67
65
  end
68
66
 
69
67
  def int?(input)
@@ -116,7 +114,7 @@ module Dry
116
114
 
117
115
  def size?(size, input)
118
116
  case size
119
- when Integer then size == input.size
117
+ when Integer then size.equal?(input.size)
120
118
  when Range, Array then size.include?(input.size)
121
119
  else
122
120
  raise ArgumentError, "+#{size}+ is not supported type for size? predicate."
@@ -131,6 +129,23 @@ module Dry
131
129
  input.size <= num
132
130
  end
133
131
 
132
+ def bytesize?(size, input)
133
+ case size
134
+ when Integer then size.equal?(input.bytesize)
135
+ when Range, Array then size.include?(input.bytesize)
136
+ else
137
+ raise ArgumentError, "+#{size}+ is not supported type for bytesize? predicate."
138
+ end
139
+ end
140
+
141
+ def min_bytesize?(num, input)
142
+ input.bytesize >= num
143
+ end
144
+
145
+ def max_bytesize?(num, input)
146
+ input.bytesize <= num
147
+ end
148
+
134
149
  def inclusion?(list, input)
135
150
  ::Kernel.warn 'inclusion is deprecated - use included_in instead.'
136
151
  included_in?(list, input)
@@ -150,15 +165,13 @@ module Dry
150
165
  end
151
166
 
152
167
  def includes?(value, input)
153
- begin
154
- if input.respond_to?(:include?)
155
- input.include?(value)
156
- else
157
- false
158
- end
159
- rescue TypeError
168
+ if input.respond_to?(:include?)
169
+ input.include?(value)
170
+ else
160
171
  false
161
172
  end
173
+ rescue TypeError
174
+ false
162
175
  end
163
176
 
164
177
  def excludes?(value, input)
@@ -185,14 +198,8 @@ module Dry
185
198
  value.equal?(false)
186
199
  end
187
200
 
188
- if RUBY_VERSION < '2.4'
189
- def format?(regex, input)
190
- !regex.match(input).nil?
191
- end
192
- else
193
- def format?(regex, input)
194
- regex.match?(input)
195
- end
201
+ def format?(regex, input)
202
+ regex.match?(input)
196
203
  end
197
204
 
198
205
  def case?(pattern, input)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Logic
5
- VERSION = '1.0.2'.freeze
5
+ VERSION = '1.0.3'.freeze
6
6
  end
7
7
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#bytesize?' do
7
+ let(:predicate_name) { :bytesize? }
8
+
9
+ context 'when value size is equal to n' do
10
+ let(:arguments_list) do
11
+ [
12
+ [4, 'こa'],
13
+ [1..8, 'こa']
14
+ ]
15
+ end
16
+
17
+ it_behaves_like 'a passing predicate'
18
+ end
19
+
20
+ context 'when value size is greater than n' do
21
+ let(:arguments_list) do
22
+ [
23
+ [3, 'こa'],
24
+ [1..3, 'こa']
25
+ ]
26
+ end
27
+
28
+ it_behaves_like 'a failing predicate'
29
+ end
30
+
31
+ context 'with value size is less than n' do
32
+ let(:arguments_list) do
33
+ [
34
+ [5, 'こa'],
35
+ [5..10, 'こa']
36
+ ]
37
+ end
38
+
39
+ it_behaves_like 'a failing predicate'
40
+ end
41
+
42
+ context 'with an unsupported size' do
43
+ it 'raises an error' do
44
+ expect { Predicates[:bytesize?].call('oops', 1) }.to raise_error(ArgumentError, /oops/)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#hash?' do
7
+ let(:predicate_name) { :hash? }
8
+
9
+ context 'when value is a hash' do
10
+ let(:arguments_list) do
11
+ [
12
+ [{}],
13
+ [foo: :bar],
14
+ [Hash.new]
15
+ ]
16
+ end
17
+
18
+ it_behaves_like 'a passing predicate'
19
+ end
20
+
21
+ context 'when value is not a hash' do
22
+ let(:arguments_list) do
23
+ [
24
+ [''],
25
+ [[]],
26
+ [nil],
27
+ [:symbol],
28
+ [String],
29
+ [1],
30
+ [1.0],
31
+ [true],
32
+ [Array.new],
33
+ [Hash]
34
+ ]
35
+ end
36
+
37
+ it_behaves_like 'a failing predicate'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#max_bytesize?' do
7
+ let(:predicate_name) { :max_bytesize? }
8
+
9
+ context 'when value size is less than n' do
10
+ let(:arguments_list) do
11
+ [
12
+ [5, 'こa']
13
+ ]
14
+ end
15
+
16
+ it_behaves_like 'a passing predicate'
17
+ end
18
+
19
+ context 'when value size is equal to n' do
20
+ let(:arguments_list) do
21
+ [
22
+ [5, 'こab']
23
+ ]
24
+ end
25
+
26
+ it_behaves_like 'a passing predicate'
27
+ end
28
+
29
+ context 'with value size is greater than n' do
30
+ let(:arguments_list) do
31
+ [
32
+ [5, 'こabc']
33
+ ]
34
+ end
35
+
36
+ it_behaves_like 'a failing predicate'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#min_bytesize?' do
7
+ let(:predicate_name) { :min_bytesize? }
8
+
9
+ context 'when value size is greater than n' do
10
+ let(:arguments_list) do
11
+ [
12
+ [3, 'こa']
13
+ ]
14
+ end
15
+
16
+ it_behaves_like 'a passing predicate'
17
+ end
18
+
19
+ context 'when value size is equal to n' do
20
+ let(:arguments_list) do
21
+ [
22
+ [5, 'こab']
23
+ ]
24
+ end
25
+
26
+ it_behaves_like 'a passing predicate'
27
+ end
28
+
29
+ context 'with value size is less than n' do
30
+ let(:arguments_list) do
31
+ [
32
+ [5, 'こ']
33
+ ]
34
+ end
35
+
36
+ it_behaves_like 'a failing predicate'
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-logic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-14 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -161,6 +161,7 @@ files:
161
161
  - spec/unit/predicates/array_spec.rb
162
162
  - spec/unit/predicates/attr_spec.rb
163
163
  - spec/unit/predicates/bool_spec.rb
164
+ - spec/unit/predicates/bytesize_spec.rb
164
165
  - spec/unit/predicates/case_spec.rb
165
166
  - spec/unit/predicates/date_spec.rb
166
167
  - spec/unit/predicates/date_time_spec.rb
@@ -176,13 +177,16 @@ files:
176
177
  - spec/unit/predicates/format_spec.rb
177
178
  - spec/unit/predicates/gt_spec.rb
178
179
  - spec/unit/predicates/gteq_spec.rb
180
+ - spec/unit/predicates/hash_spec.rb
179
181
  - spec/unit/predicates/included_in_spec.rb
180
182
  - spec/unit/predicates/includes_spec.rb
181
183
  - spec/unit/predicates/int_spec.rb
182
184
  - spec/unit/predicates/key_spec.rb
183
185
  - spec/unit/predicates/lt_spec.rb
184
186
  - spec/unit/predicates/lteq_spec.rb
187
+ - spec/unit/predicates/max_bytesize_spec.rb
185
188
  - spec/unit/predicates/max_size_spec.rb
189
+ - spec/unit/predicates/min_bytesize_spec.rb
186
190
  - spec/unit/predicates/min_size_spec.rb
187
191
  - spec/unit/predicates/none_spec.rb
188
192
  - spec/unit/predicates/not_eql_spec.rb
@@ -211,14 +215,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
215
  requirements:
212
216
  - - ">="
213
217
  - !ruby/object:Gem::Version
214
- version: '0'
218
+ version: 2.4.0
215
219
  required_rubygems_version: !ruby/object:Gem::Requirement
216
220
  requirements:
217
221
  - - ">="
218
222
  - !ruby/object:Gem::Version
219
223
  version: '0'
220
224
  requirements: []
221
- rubygems_version: 3.0.1
225
+ rubygems_version: 3.0.3
222
226
  signing_key:
223
227
  specification_version: 4
224
228
  summary: Predicate logic with rule composition
@@ -242,6 +246,7 @@ test_files:
242
246
  - spec/unit/predicates/array_spec.rb
243
247
  - spec/unit/predicates/attr_spec.rb
244
248
  - spec/unit/predicates/bool_spec.rb
249
+ - spec/unit/predicates/bytesize_spec.rb
245
250
  - spec/unit/predicates/case_spec.rb
246
251
  - spec/unit/predicates/date_spec.rb
247
252
  - spec/unit/predicates/date_time_spec.rb
@@ -257,13 +262,16 @@ test_files:
257
262
  - spec/unit/predicates/format_spec.rb
258
263
  - spec/unit/predicates/gt_spec.rb
259
264
  - spec/unit/predicates/gteq_spec.rb
265
+ - spec/unit/predicates/hash_spec.rb
260
266
  - spec/unit/predicates/included_in_spec.rb
261
267
  - spec/unit/predicates/includes_spec.rb
262
268
  - spec/unit/predicates/int_spec.rb
263
269
  - spec/unit/predicates/key_spec.rb
264
270
  - spec/unit/predicates/lt_spec.rb
265
271
  - spec/unit/predicates/lteq_spec.rb
272
+ - spec/unit/predicates/max_bytesize_spec.rb
266
273
  - spec/unit/predicates/max_size_spec.rb
274
+ - spec/unit/predicates/min_bytesize_spec.rb
267
275
  - spec/unit/predicates/min_size_spec.rb
268
276
  - spec/unit/predicates/none_spec.rb
269
277
  - spec/unit/predicates/not_eql_spec.rb