datacaster 4.1.0 → 4.2.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 +4 -4
- data/README.md +29 -0
- data/config/locales/en.yml +9 -2
- data/lib/datacaster/predefined.rb +42 -0
- data/lib/datacaster/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 351d202f9afcb51c391c23e852f4d9d289a60df1a4f890473f532aac47ca668c
|
4
|
+
data.tar.gz: '031040811b8f5a2c319c5c48295c44d347f76dcb52fbfaeadd37f586f0d06582'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c53e86295d1f47bc80d0d5e1805b5076e85f8ded528f14039ebcbd88a810bd4e8e4897b16a41b30422c8b18556049a54256ce60fa5fecc04c176cda3de363890
|
7
|
+
data.tar.gz: 67111b7dfa26fcfc844ca33336f884738a961c9629e01486ad4cef5423406f33ec030d92746e32c66739c624a0d0b0c6b9a89c8609dc40d0509cdf85298767ec
|
data/README.md
CHANGED
@@ -26,10 +26,13 @@ It is currently used in production in several projects (mainly as request parame
|
|
26
26
|
- [`float(error_key = nil)`](#floaterror_key--nil)
|
27
27
|
- [`hash_value(error_key = nil)`](#hash_valueerror_key--nil)
|
28
28
|
- [`integer(error_key = nil)`](#integererror_key--nil)
|
29
|
+
- [`numeric(error_key = nil)`](#numericerror_key--nil)
|
29
30
|
- [`string(error_key = nil)`](#stringerror_key--nil)
|
30
31
|
- [Convenience types](#convenience-types)
|
31
32
|
- [`hash_with_symbolized_keys(error_key = nil)`](#hash_with_symbolized_keyserror_key--nil)
|
32
33
|
- [`integer32(error_key = nil)`](#integer32error_key--nil)
|
34
|
+
- [`maximum(max, error_key = nil, inclusive: true)`](#maximummax-error_key--nil-inclusive-true)
|
35
|
+
- [`minimum(min, error_key = nil, inclusive: true)`](#minimummin-error_key--nil-inclusive-true)
|
33
36
|
- [`non_empty_string(error_key = nil)`](#non_empty_stringerror_key--nil)
|
34
37
|
- [`pattern(regexp, error_key = nil)`](#patternregexp-error_key--nil)
|
35
38
|
- [`uuid(error_key = nil)`](#uuiderror_key--nil)
|
@@ -500,6 +503,12 @@ Returns ValidResult if and only if provided value is an integer. Doesn't transfo
|
|
500
503
|
|
501
504
|
I18n keys: `error_key`, `'.integer'`, `'datacaster.errors.integer'`.
|
502
505
|
|
506
|
+
#### `numeric(error_key = nil)`
|
507
|
+
|
508
|
+
Returns ValidResult if and only if provided value is a number (Ruby's `Numeric`). Doesn't transform the value.
|
509
|
+
|
510
|
+
I18n keys: `error_key`, `'.numeric'`, `'datacaster.errors.numeric'`.
|
511
|
+
|
503
512
|
#### `string(error_key = nil)`
|
504
513
|
|
505
514
|
Returns ValidResult if and only if provided value is a string. Doesn't transform the value.
|
@@ -523,6 +532,26 @@ I18n keys:
|
|
523
532
|
* not an integer – `error_key`, `'.integer'`, `'datacaster.errors.integer'`
|
524
533
|
* too big – `error_key`, `'.integer32'`, `'datacaster.errors.integer32'`
|
525
534
|
|
535
|
+
#### `maximum(max, error_key = nil, inclusive: true)`
|
536
|
+
|
537
|
+
Returns ValidResult if and only if provided value is a number and is less than `max`. If `inclusive` set to true, provided value should be less than or equal to `max`. Doesn't transform the value.
|
538
|
+
|
539
|
+
I18n keys:
|
540
|
+
|
541
|
+
* not a number – `error_key`, `'.numeric'`, `'datacaster.errors.numeric'`
|
542
|
+
* is less (when `inclusive` is `true`) – `error_key`, `'.maximum.lteq'`, `'datacaster.errors.maximum.lteq'`
|
543
|
+
* is less (when `inclusive` is `false`) – `error_key`, `'.maximum.lt'`, `'datacaster.errors.maximum.lt'`
|
544
|
+
|
545
|
+
#### `minimum(min, error_key = nil, inclusive: true)`
|
546
|
+
|
547
|
+
Returns ValidResult if and only if provided value is a number and is greater than `min`. If `inclusive` set to true, provided value should be greater than or equal to `min`. Doesn't transform the value.
|
548
|
+
|
549
|
+
I18n keys:
|
550
|
+
|
551
|
+
* not a number – `error_key`, `'.numeric'`, `'datacaster.errors.numeric'`
|
552
|
+
* is greater (when `inclusive` is `true`) – `error_key`, `'.minimum.gteq'`, `'datacaster.errors.minimum.gteq'`
|
553
|
+
* is greater (when `inclusive` is `false`) – `error_key`, `'.minimum.gt'`, `'datacaster.errors.minimum.gt'`
|
554
|
+
|
526
555
|
#### `non_empty_string(error_key = nil)`
|
527
556
|
|
528
557
|
Returns ValidResult if and only if provided value is a string and is not empty. Doesn't transform the value.
|
data/config/locales/en.yml
CHANGED
@@ -6,7 +6,7 @@ en:
|
|
6
6
|
array: should be an array
|
7
7
|
cast: is invalid
|
8
8
|
check: is invalid
|
9
|
-
compare:
|
9
|
+
compare: does not equal %{reference}
|
10
10
|
decimal: is not a decimal number
|
11
11
|
empty: should not be empty
|
12
12
|
float: is not a float
|
@@ -15,7 +15,14 @@ en:
|
|
15
15
|
integer: is not an integer
|
16
16
|
integer32: is not a 32-bit integer
|
17
17
|
iso8601: is not a string with ISO-8601 date and time
|
18
|
-
|
18
|
+
maximum:
|
19
|
+
lt: should be less than %{max}
|
20
|
+
lteq: should be less than or equal to %{max}
|
21
|
+
minimum:
|
22
|
+
gt: should be greater than %{min}
|
23
|
+
gteq: should be greater than or equal to %{min}
|
24
|
+
must_be: is not %{reference}
|
25
|
+
numeric: is not a number
|
19
26
|
pattern: has invalid format
|
20
27
|
relate: "%{left} should be %{op} %{right}"
|
21
28
|
responds_to: "does not respond to %{reference}"
|
@@ -296,6 +296,12 @@ module Datacaster
|
|
296
296
|
|
297
297
|
# Strict types
|
298
298
|
|
299
|
+
def numeric(error_key = nil)
|
300
|
+
error_keys = ['.numeric', 'datacaster.errors.numeric']
|
301
|
+
error_keys.unshift(error_key) if error_key
|
302
|
+
check { |x| x.is_a?(Numeric) }.i18n_key(*error_keys)
|
303
|
+
end
|
304
|
+
|
299
305
|
def decimal(digits = 8, error_key = nil)
|
300
306
|
error_keys = ['.decimal', 'datacaster.errors.decimal']
|
301
307
|
error_keys.unshift(error_key) if error_key
|
@@ -355,6 +361,42 @@ module Datacaster
|
|
355
361
|
integer(error_key) & check { |x| x.abs <= 2_147_483_647 }.i18n_key(*error_keys)
|
356
362
|
end
|
357
363
|
|
364
|
+
def maximum(max, error_key = nil, inclusive: true)
|
365
|
+
subkey = 'lt'
|
366
|
+
subkey += 'eq' if inclusive
|
367
|
+
|
368
|
+
error_keys = [".maximum.#{subkey}", "datacaster.errors.maximum.#{subkey}"]
|
369
|
+
|
370
|
+
error_keys.unshift(error_key) if error_key
|
371
|
+
|
372
|
+
caster =
|
373
|
+
if inclusive
|
374
|
+
check { |x| x <= max }
|
375
|
+
else
|
376
|
+
check { |x| x < max }
|
377
|
+
end
|
378
|
+
|
379
|
+
numeric(error_key) & caster.i18n_key(*error_keys, max:)
|
380
|
+
end
|
381
|
+
|
382
|
+
def minimum(min, error_key = nil, inclusive: true)
|
383
|
+
subkey = 'gt'
|
384
|
+
subkey += 'eq' if inclusive
|
385
|
+
|
386
|
+
error_keys = [".minimum.#{subkey}", "datacaster.errors.minimum.#{subkey}"]
|
387
|
+
|
388
|
+
error_keys.unshift(error_key) if error_key
|
389
|
+
|
390
|
+
caster =
|
391
|
+
if inclusive
|
392
|
+
check { |x| x >= min }
|
393
|
+
else
|
394
|
+
check { |x| x > min }
|
395
|
+
end
|
396
|
+
|
397
|
+
numeric(error_key) & caster.i18n_key(*error_keys, min:)
|
398
|
+
end
|
399
|
+
|
358
400
|
def string(error_key = nil)
|
359
401
|
error_keys = ['.string', 'datacaster.errors.string']
|
360
402
|
error_keys.unshift(error_key) if error_key
|
data/lib/datacaster/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Zolotarev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
- - "<"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '3'
|
109
|
-
description:
|
109
|
+
description:
|
110
110
|
email:
|
111
111
|
- eugzol@gmail.com
|
112
112
|
executables: []
|
@@ -178,7 +178,7 @@ licenses:
|
|
178
178
|
- MIT
|
179
179
|
metadata:
|
180
180
|
source_code_uri: https://github.com/EugZol/datacaster
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
197
|
-
signing_key:
|
196
|
+
rubygems_version: 3.5.20
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Run-time type checker and transformer for Ruby
|
200
200
|
test_files: []
|