dry-validation 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +9 -6
- data/CHANGELOG.md +58 -0
- data/Gemfile +3 -3
- data/benchmarks/benchmark_form_invalid.rb +64 -0
- data/benchmarks/benchmark_form_valid.rb +64 -0
- data/benchmarks/profile_schema_call_invalid.rb +20 -0
- data/benchmarks/profile_schema_call_valid.rb +20 -0
- data/benchmarks/profile_schema_definition.rb +14 -0
- data/benchmarks/profile_schema_messages_invalid.rb +20 -0
- data/benchmarks/suite.rb +5 -0
- data/config/errors.yml +12 -5
- data/dry-validation.gemspec +2 -2
- data/examples/basic.rb +2 -2
- data/examples/form.rb +2 -2
- data/examples/json.rb +2 -2
- data/examples/nested.rb +6 -6
- data/lib/dry/validation.rb +22 -3
- data/lib/dry/validation/deprecations.rb +23 -0
- data/lib/dry/validation/error_compiler.rb +31 -11
- data/lib/dry/validation/error_compiler/input.rb +44 -57
- data/lib/dry/validation/hint_compiler.rb +15 -7
- data/lib/dry/validation/input_processor_compiler.rb +13 -6
- data/lib/dry/validation/input_processor_compiler/form.rb +2 -0
- data/lib/dry/validation/input_processor_compiler/sanitizer.rb +1 -1
- data/lib/dry/validation/messages/abstract.rb +9 -1
- data/lib/dry/validation/predicate_registry.rb +101 -0
- data/lib/dry/validation/result.rb +8 -1
- data/lib/dry/validation/schema.rb +110 -44
- data/lib/dry/validation/schema/check.rb +4 -2
- data/lib/dry/validation/schema/deprecated.rb +31 -0
- data/lib/dry/validation/schema/dsl.rb +18 -11
- data/lib/dry/validation/schema/form.rb +1 -0
- data/lib/dry/validation/schema/json.rb +1 -0
- data/lib/dry/validation/schema/key.rb +23 -10
- data/lib/dry/validation/schema/rule.rb +81 -20
- data/lib/dry/validation/schema/value.rb +110 -25
- data/lib/dry/validation/version.rb +1 -1
- data/spec/fixtures/locales/en.yml +1 -0
- data/spec/fixtures/locales/pl.yml +1 -1
- data/spec/integration/custom_error_messages_spec.rb +2 -2
- data/spec/integration/custom_predicates_spec.rb +98 -15
- data/spec/integration/error_compiler_spec.rb +111 -96
- data/spec/integration/form/predicates/array_spec.rb +243 -0
- data/spec/integration/form/predicates/empty_spec.rb +263 -0
- data/spec/integration/form/predicates/eql_spec.rb +327 -0
- data/spec/integration/form/predicates/even_spec.rb +455 -0
- data/spec/integration/form/predicates/excluded_from_spec.rb +455 -0
- data/spec/integration/form/predicates/excludes_spec.rb +391 -0
- data/spec/integration/form/predicates/false_spec.rb +455 -0
- data/spec/integration/form/predicates/filled_spec.rb +467 -0
- data/spec/integration/form/predicates/format_spec.rb +454 -0
- data/spec/integration/form/predicates/gt_spec.rb +519 -0
- data/spec/integration/form/predicates/gteq_spec.rb +519 -0
- data/spec/integration/form/predicates/included_in_spec.rb +455 -0
- data/spec/integration/form/predicates/includes_spec.rb +391 -0
- data/spec/integration/form/predicates/key_spec.rb +75 -0
- data/spec/integration/form/predicates/lt_spec.rb +519 -0
- data/spec/integration/form/predicates/lteq_spec.rb +519 -0
- data/spec/integration/form/predicates/max_size_spec.rb +391 -0
- data/spec/integration/form/predicates/min_size_spec.rb +391 -0
- data/spec/integration/form/predicates/none_spec.rb +265 -0
- data/spec/integration/form/predicates/not_eql_spec.rb +327 -0
- data/spec/integration/form/predicates/odd_spec.rb +455 -0
- data/spec/integration/form/predicates/size/fixed_spec.rb +399 -0
- data/spec/integration/form/predicates/size/range_spec.rb +398 -0
- data/spec/integration/form/predicates/true_spec.rb +455 -0
- data/spec/integration/form/predicates/type_spec.rb +391 -0
- data/spec/integration/hints_spec.rb +90 -4
- data/spec/integration/injecting_rules_spec.rb +2 -2
- data/spec/integration/localized_error_messages_spec.rb +2 -2
- data/spec/integration/messages/i18n_spec.rb +3 -3
- data/spec/integration/optional_keys_spec.rb +3 -3
- data/spec/integration/schema/array_schema_spec.rb +49 -13
- data/spec/integration/schema/check_rules_spec.rb +6 -6
- data/spec/integration/schema/check_with_nested_el_spec.rb +3 -3
- data/spec/integration/schema/check_with_nth_el_spec.rb +1 -1
- data/spec/integration/schema/each_with_set_spec.rb +3 -3
- data/spec/integration/schema/extending_dsl_spec.rb +27 -0
- data/spec/integration/schema/form/explicit_types_spec.rb +182 -0
- data/spec/integration/schema/form_spec.rb +90 -18
- data/spec/integration/schema/hash_schema_spec.rb +47 -0
- data/spec/integration/schema/inheriting_schema_spec.rb +4 -4
- data/spec/integration/schema/input_processor_spec.rb +8 -8
- data/spec/integration/schema/json/explicit_types_spec.rb +157 -0
- data/spec/integration/schema/json_spec.rb +18 -18
- data/spec/integration/schema/macros/confirmation_spec.rb +1 -1
- data/spec/integration/schema/macros/each_spec.rb +177 -43
- data/spec/integration/schema/macros/{required_spec.rb → filled_spec.rb} +34 -6
- data/spec/integration/schema/macros/input_spec.rb +21 -0
- data/spec/integration/schema/macros/maybe_spec.rb +39 -2
- data/spec/integration/schema/macros/value_spec.rb +105 -0
- data/spec/integration/schema/macros/when_spec.rb +28 -8
- data/spec/integration/schema/nested_values_spec.rb +11 -8
- data/spec/integration/schema/not_spec.rb +2 -2
- data/spec/integration/schema/numbers_spec.rb +1 -1
- data/spec/integration/schema/option_with_default_spec.rb +1 -1
- data/spec/integration/schema/predicate_verification_spec.rb +9 -0
- data/spec/integration/schema/predicates/array_spec.rb +295 -0
- data/spec/integration/schema/predicates/custom_spec.rb +103 -0
- data/spec/integration/schema/predicates/empty_spec.rb +263 -0
- data/spec/integration/schema/predicates/eql_spec.rb +327 -0
- data/spec/integration/schema/predicates/even_spec.rb +455 -0
- data/spec/integration/schema/predicates/excluded_from_spec.rb +455 -0
- data/spec/integration/schema/predicates/excludes_spec.rb +391 -0
- data/spec/integration/schema/predicates/filled_spec.rb +467 -0
- data/spec/integration/schema/predicates/format_spec.rb +455 -0
- data/spec/integration/schema/predicates/gt_spec.rb +519 -0
- data/spec/integration/schema/predicates/gteq_spec.rb +519 -0
- data/spec/integration/schema/predicates/hash_spec.rb +69 -0
- data/spec/integration/schema/predicates/included_in_spec.rb +455 -0
- data/spec/integration/schema/predicates/includes_spec.rb +391 -0
- data/spec/integration/schema/predicates/key_spec.rb +88 -0
- data/spec/integration/schema/predicates/lt_spec.rb +520 -0
- data/spec/integration/schema/predicates/lteq_spec.rb +519 -0
- data/spec/integration/schema/predicates/max_size_spec.rb +391 -0
- data/spec/integration/schema/predicates/min_size_spec.rb +391 -0
- data/spec/integration/schema/predicates/none_spec.rb +265 -0
- data/spec/integration/schema/predicates/not_eql_spec.rb +391 -0
- data/spec/integration/schema/predicates/odd_spec.rb +455 -0
- data/spec/integration/schema/predicates/size/fixed_spec.rb +401 -0
- data/spec/integration/schema/predicates/size/range_spec.rb +399 -0
- data/spec/integration/schema/predicates/type_spec.rb +391 -0
- data/spec/integration/schema/reusing_schema_spec.rb +4 -4
- data/spec/integration/schema/using_types_spec.rb +24 -6
- data/spec/integration/schema/xor_spec.rb +2 -2
- data/spec/integration/schema_builders_spec.rb +15 -0
- data/spec/integration/schema_spec.rb +37 -12
- data/spec/shared/predicate_helper.rb +13 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/matchers.rb +38 -0
- data/spec/support/predicates_integration.rb +7 -0
- data/spec/unit/hint_compiler_spec.rb +10 -8
- data/spec/unit/input_processor_compiler/form_spec.rb +45 -43
- data/spec/unit/input_processor_compiler/json_spec.rb +37 -35
- data/spec/unit/predicate_registry_spec.rb +34 -0
- data/spec/unit/schema/key_spec.rb +12 -14
- data/spec/unit/schema/rule_spec.rb +4 -2
- data/spec/unit/schema/value_spec.rb +38 -121
- metadata +150 -16
- data/lib/dry/validation/schema/attr.rb +0 -15
- data/spec/integration/attr_spec.rb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16fb2c50b37c5d1aff843031ff3d7af6e87ab05a
|
4
|
+
data.tar.gz: 64f74fc7df4b183322908ec96120d4dbbb4b38c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 244e25e33c6a1795436fc015cab5d4c23961c974eaf7208144faf69a81c040ede351c54e7225efc1695283f061225b0543e2ee6120fce29c00069725fc0ee791
|
7
|
+
data.tar.gz: fc89edb2c0f6862d1771b46a77863b644947db429861a34d944cab9799d328df01e7bb0554291fa23f12d67ba545a276fe8f3c98435837485fb002bee55b5101
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
|
-
bundler_args: --without console benchmarks
|
4
|
+
bundler_args: --full-index --without console benchmarks
|
5
5
|
script:
|
6
6
|
- bundle exec rake spec
|
7
7
|
rvm:
|
8
8
|
- 2.0
|
9
|
-
- 2.1
|
10
|
-
- 2.2
|
11
|
-
- 2.3.
|
9
|
+
- 2.1.10
|
10
|
+
- 2.2.5
|
11
|
+
- 2.3.1
|
12
12
|
- rbx-2
|
13
|
-
- jruby-
|
13
|
+
- jruby-9.1.1.0
|
14
14
|
- ruby-head
|
15
|
-
- jruby-head
|
16
15
|
env:
|
17
16
|
global:
|
18
17
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
@@ -21,6 +20,10 @@ matrix:
|
|
21
20
|
- rvm: rbx-2
|
22
21
|
- rvm: ruby-head
|
23
22
|
- rvm: jruby-head
|
23
|
+
include:
|
24
|
+
- rvm: jruby-head
|
25
|
+
before_install: gem install bundler --no-ri --no-rdoc
|
26
|
+
|
24
27
|
notifications:
|
25
28
|
email: false
|
26
29
|
webhooks:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,61 @@
|
|
1
|
+
# v0.8.0 2016-07-01
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Explicit interface for type specs used to set up coercions, ie `required(:age, :int)` (solnic)
|
6
|
+
* Support new dry-logic predicates: `:excluded_from?`, `:excludes?`, `:included_in?`, `:includes?`, `:not_eql?`, `:odd?`, `:even?` (jodosha, fran-worley)
|
7
|
+
* Support for blocks in `value`, `filled` and `maybe` macros (solnic)
|
8
|
+
* Support for passing a schema to `value|filled|maybe` macros ie `maybe(SomeSchema)` (solnic)
|
9
|
+
* Support for `each(SomeSchema)` (solnic)
|
10
|
+
* Support for `value|filled|maybe` macros + `each` inside a block ie: `maybe(:filled?) { each(:int?) }` (solnic)
|
11
|
+
* Support for dedicated hint messages via `en.errors.#{predicate}.(hint|failure)` look-up paths (solnic)
|
12
|
+
* Support for configuring custom DSL extensions via `dsl_extensions` setting on Schema class (solnic)
|
13
|
+
* Support for preconfiguring a predicate for the input value ie `value :hash?` used for prerequisite-checks (solnic)
|
14
|
+
* Infer coercion from constrained types (solnic)
|
15
|
+
* Add value macro (coop)
|
16
|
+
* Enable .schema to accept objects that respond to #schema (ttdonovan)
|
17
|
+
* Support for schema predicates which don't need any arguments (fran-worley)
|
18
|
+
* Error and hint messages have access to all predicate arguments by default (fran-worley+solnic)
|
19
|
+
* Invalid predicate name in DSL will raise an error (solnic)
|
20
|
+
* Predicate with invalid arity in DSL will raise an error (solnic)
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
* Support for jRuby 9.1.1.0 (flash-gordon)
|
25
|
+
* Fix bug when using predicates with options in each and when (fran-worley)
|
26
|
+
* Fix bug when validating custom types (coop)
|
27
|
+
* Fix depending on deeply nested values in high-lvl rules (solnic)
|
28
|
+
* Fix duplicated error message for lt? when hint was used (solnic)
|
29
|
+
* Fix hints for nested schemas (solnic)
|
30
|
+
* Fix an issue where rules with same names inside nested schemas have incorrect hints (solnic)
|
31
|
+
* Fix a bug where hints were being generated 4 times (solnic)
|
32
|
+
* Fix duplicated error messages when message is different than a hint (solnic)
|
33
|
+
|
34
|
+
### Changed
|
35
|
+
|
36
|
+
* Uses new `:weak` hash constructor from dry-types 0.8.0 which can partially coerce invalid hash (solnic)
|
37
|
+
* `key` has been deprecated in favor of `required` (coop)
|
38
|
+
* `required` has been deprecated in favor of `filled` (coop)
|
39
|
+
* Now relies on dry-logic v0.3.0 and dry-types v0.8.0 (fran-worley)
|
40
|
+
* Tring to use illogical predicates with maybe and filled macros now raise InvalidSchemaError (fran-worley)
|
41
|
+
* Enable coercion on form.true and form.false (fran-worley)
|
42
|
+
* Remove attr (will be extracted to a separate gem) (coop)
|
43
|
+
* Deprecate required in favour of filled (coop)
|
44
|
+
* Deprecate key in favor of required (coop)
|
45
|
+
* Remove nested key syntax (solnic)
|
46
|
+
|
47
|
+
### Internal
|
48
|
+
|
49
|
+
* ~15% performance boost via various optimizations (solnic)
|
50
|
+
* When using explicit type specs building a schema is ~80-85x faster (solnic)
|
51
|
+
* No longer uses `Dry::Types::Predicates` as `:type?` predicate was moved to dry-logic (solnic)
|
52
|
+
* Integration specs covering predicates with Form and Schema (jodosha)
|
53
|
+
* Use latest ruby versions on travis (flash-gordon)
|
54
|
+
* Make pry console optional with IRB as a default (flash-gordon)
|
55
|
+
* Remove wrapping rules in :set nodes (solnic)
|
56
|
+
|
57
|
+
[Compare v0.7.4...master](https://github.com/dryrb/dry-validation/compare/v0.7.4...master)
|
58
|
+
|
1
59
|
# v0.7.4 2016-04-06
|
2
60
|
|
3
61
|
### Added
|
data/Gemfile
CHANGED
@@ -13,9 +13,9 @@ group :tools do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
group :benchmarks do
|
16
|
-
gem 'hotch'
|
17
|
-
gem 'activemodel', '5.0.0.
|
18
|
-
gem 'actionpack', '5.0.0.
|
16
|
+
gem 'hotch', platform: :mri
|
17
|
+
gem 'activemodel', '~> 5.0.0.rc'
|
18
|
+
gem 'actionpack', '~> 5.0.0.rc'
|
19
19
|
gem 'benchmark-ips'
|
20
20
|
gem 'virtus'
|
21
21
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'benchmark/ips'
|
2
|
+
require 'active_model'
|
3
|
+
|
4
|
+
require 'dry-validation'
|
5
|
+
|
6
|
+
I18n.locale = :en
|
7
|
+
I18n.backend.load_translations
|
8
|
+
|
9
|
+
class User
|
10
|
+
include ActiveModel::Validations
|
11
|
+
|
12
|
+
attr_reader :email, :age
|
13
|
+
|
14
|
+
validates :email, :age, presence: true
|
15
|
+
validates :age, numericality: { greater_than: 18 }
|
16
|
+
|
17
|
+
def initialize(attrs)
|
18
|
+
@email, @age = attrs.values_at('email', 'age')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
schema = Dry::Validation.Schema do
|
23
|
+
configure do
|
24
|
+
config.messages = :i18n
|
25
|
+
end
|
26
|
+
|
27
|
+
required(:email).filled
|
28
|
+
required(:age).filled(:int?, gt?: 18)
|
29
|
+
end
|
30
|
+
|
31
|
+
form = Dry::Validation.Form do
|
32
|
+
configure do
|
33
|
+
config.messages = :i18n
|
34
|
+
config.type_specs = true
|
35
|
+
end
|
36
|
+
|
37
|
+
required(:email, :string).filled
|
38
|
+
required(:age, :int).filled(:int?, gt?: 18)
|
39
|
+
end
|
40
|
+
|
41
|
+
params = { 'email' => '', 'age' => '18' }
|
42
|
+
coerced = { email: nil, age: 18 }
|
43
|
+
|
44
|
+
puts schema.(coerced).inspect
|
45
|
+
puts form.(params).inspect
|
46
|
+
puts User.new(params).validate
|
47
|
+
|
48
|
+
Benchmark.ips do |x|
|
49
|
+
x.report('ActiveModel::Validations') do
|
50
|
+
user = User.new(params)
|
51
|
+
user.validate
|
52
|
+
user.errors
|
53
|
+
end
|
54
|
+
|
55
|
+
x.report('dry-validation / schema') do
|
56
|
+
schema.(coerced).messages
|
57
|
+
end
|
58
|
+
|
59
|
+
x.report('dry-validation / form') do
|
60
|
+
form.(params).messages
|
61
|
+
end
|
62
|
+
|
63
|
+
x.compare!
|
64
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'benchmark/ips'
|
2
|
+
require 'active_model'
|
3
|
+
|
4
|
+
require 'dry-validation'
|
5
|
+
|
6
|
+
I18n.locale = :en
|
7
|
+
I18n.backend.load_translations
|
8
|
+
|
9
|
+
class User
|
10
|
+
include ActiveModel::Validations
|
11
|
+
|
12
|
+
attr_reader :email, :age
|
13
|
+
|
14
|
+
validates :email, :age, presence: true
|
15
|
+
validates :age, numericality: { greater_than: 18 }
|
16
|
+
|
17
|
+
def initialize(attrs)
|
18
|
+
@email, @age = attrs.values_at('email', 'age')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
schema = Dry::Validation.Schema do
|
23
|
+
configure do
|
24
|
+
config.messages = :i18n
|
25
|
+
end
|
26
|
+
|
27
|
+
required(:email).filled
|
28
|
+
required(:age).filled(:int?, gt?: 18)
|
29
|
+
end
|
30
|
+
|
31
|
+
form = Dry::Validation.Form do
|
32
|
+
configure do
|
33
|
+
config.messages = :i18n
|
34
|
+
config.type_specs = true
|
35
|
+
end
|
36
|
+
|
37
|
+
required(:email, :string).filled
|
38
|
+
required(:age, :int).filled(:int?, gt?: 18)
|
39
|
+
end
|
40
|
+
|
41
|
+
params = { 'email' => 'foo@bar.baz', 'age' => '19' }
|
42
|
+
coerced = { email: 'foo@bar.baz', age: 19 }
|
43
|
+
|
44
|
+
puts schema.(coerced).inspect
|
45
|
+
puts form.(params).inspect
|
46
|
+
puts User.new(params).validate
|
47
|
+
|
48
|
+
Benchmark.ips do |x|
|
49
|
+
x.report('ActiveModel::Validations') do
|
50
|
+
user = User.new(params)
|
51
|
+
user.validate
|
52
|
+
user.errors
|
53
|
+
end
|
54
|
+
|
55
|
+
x.report('dry-validation / schema') do
|
56
|
+
schema.(coerced).messages
|
57
|
+
end
|
58
|
+
|
59
|
+
x.report('dry-validation / form') do
|
60
|
+
form.(params).messages
|
61
|
+
end
|
62
|
+
|
63
|
+
x.compare!
|
64
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'suite'
|
2
|
+
require 'hotch'
|
3
|
+
|
4
|
+
schema = Dry::Validation.Schema do
|
5
|
+
configure { config.messages = :i18n }
|
6
|
+
|
7
|
+
required(:email).filled
|
8
|
+
required(:age).filled(:int?, gt?: 18)
|
9
|
+
required(:address).filled(:hash?)
|
10
|
+
end
|
11
|
+
|
12
|
+
input = { email: '', age: 18, address: {} }
|
13
|
+
|
14
|
+
puts schema.(input).inspect
|
15
|
+
|
16
|
+
Hotch() do
|
17
|
+
10_000.times do
|
18
|
+
schema.(input)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'suite'
|
2
|
+
require 'hotch'
|
3
|
+
|
4
|
+
schema = Dry::Validation.Schema do
|
5
|
+
configure { config.messages = :i18n }
|
6
|
+
|
7
|
+
required(:email).filled
|
8
|
+
required(:age).filled(:int?, gt?: 18)
|
9
|
+
required(:address).filled(:hash?)
|
10
|
+
end
|
11
|
+
|
12
|
+
input = { email: 'jane@doe.org', age: 19, address: { city: 'Krakow' } }
|
13
|
+
|
14
|
+
puts schema.(input).inspect
|
15
|
+
|
16
|
+
Hotch() do
|
17
|
+
10_000.times do
|
18
|
+
schema.(input)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'suite'
|
2
|
+
require 'hotch'
|
3
|
+
|
4
|
+
Hotch() do
|
5
|
+
1000.times do
|
6
|
+
Dry::Validation.Schema do
|
7
|
+
configure { config.messages = :i18n }
|
8
|
+
|
9
|
+
required(:email).filled
|
10
|
+
required(:age).filled(:int?, gt?: 18)
|
11
|
+
required(:address).filled(:hash?)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'suite'
|
2
|
+
require 'hotch'
|
3
|
+
|
4
|
+
schema = Dry::Validation.Schema do
|
5
|
+
configure { config.messages = :i18n }
|
6
|
+
|
7
|
+
required(:email).filled
|
8
|
+
required(:age).filled(:int?, gt?: 18)
|
9
|
+
required(:address).filled(:hash?)
|
10
|
+
end
|
11
|
+
|
12
|
+
input = { email: '', age: 18, address: {} }
|
13
|
+
|
14
|
+
puts schema.(input).inspect
|
15
|
+
|
16
|
+
Hotch() do
|
17
|
+
10_000.times do
|
18
|
+
schema.(input).messages
|
19
|
+
end
|
20
|
+
end
|
data/benchmarks/suite.rb
ADDED
data/config/errors.yml
CHANGED
@@ -4,9 +4,13 @@ en:
|
|
4
4
|
|
5
5
|
empty?: "must be empty"
|
6
6
|
|
7
|
-
|
7
|
+
excludes?: "must not include %{value}"
|
8
8
|
|
9
|
-
|
9
|
+
excluded_from?: "must not be one of: %{list}"
|
10
|
+
|
11
|
+
eql?: "must be equal to %{left}"
|
12
|
+
|
13
|
+
not_eql?: "must not be equal to %{left}"
|
10
14
|
|
11
15
|
filled?: "must be filled"
|
12
16
|
|
@@ -24,8 +28,11 @@ en:
|
|
24
28
|
|
25
29
|
hash?: "must be a hash"
|
26
30
|
|
31
|
+
included_in?: "must be one of: %{list}"
|
27
32
|
inclusion?: "must be one of: %{list}"
|
28
33
|
|
34
|
+
includes?: "must include %{value}"
|
35
|
+
|
29
36
|
bool?: "must be boolean"
|
30
37
|
|
31
38
|
true?: "must be true"
|
@@ -48,7 +55,7 @@ en:
|
|
48
55
|
|
49
56
|
attr?: "is missing"
|
50
57
|
|
51
|
-
lt?: "must be less than %{num}
|
58
|
+
lt?: "must be less than %{num}"
|
52
59
|
|
53
60
|
lteq?: "must be less than or equal to %{num}"
|
54
61
|
|
@@ -64,11 +71,11 @@ en:
|
|
64
71
|
|
65
72
|
size?:
|
66
73
|
arg:
|
67
|
-
default: "size must be %{
|
74
|
+
default: "size must be %{size}"
|
68
75
|
range: "size must be within %{left} - %{right}"
|
69
76
|
|
70
77
|
value:
|
71
78
|
string:
|
72
79
|
arg:
|
73
|
-
default: "length must be %{
|
80
|
+
default: "length must be %{size}"
|
74
81
|
range: "length must be within %{left} - %{right}"
|
data/dry-validation.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.1', '>= 0.1.3'
|
20
20
|
spec.add_runtime_dependency 'dry-container', '~> 0.2', '>= 0.2.8'
|
21
21
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
22
|
-
spec.add_runtime_dependency 'dry-logic', '~> 0.
|
23
|
-
spec.add_runtime_dependency 'dry-types', '~> 0.
|
22
|
+
spec.add_runtime_dependency 'dry-logic', '~> 0.3', '>= 0.3.0'
|
23
|
+
spec.add_runtime_dependency 'dry-types', '~> 0.8', '>= 0.8.0'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
26
|
spec.add_development_dependency 'rake'
|
data/examples/basic.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'dry-validation'
|
2
2
|
|
3
3
|
schema = Dry::Validation.Schema do
|
4
|
-
|
4
|
+
required(:email).filled
|
5
5
|
|
6
|
-
|
6
|
+
required(:age).filled(:int?, gt?: 18)
|
7
7
|
end
|
8
8
|
|
9
9
|
errors = schema.call(email: 'jane@doe.org', age: 19).messages
|
data/examples/form.rb
CHANGED
data/examples/json.rb
CHANGED
@@ -2,9 +2,9 @@ require 'json'
|
|
2
2
|
require 'dry-validation'
|
3
3
|
|
4
4
|
schema = Dry::Validation.JSON do
|
5
|
-
|
5
|
+
required(:email).filled
|
6
6
|
|
7
|
-
|
7
|
+
required(:age).filled(:int?, gt?: 18)
|
8
8
|
end
|
9
9
|
|
10
10
|
errors = schema.call(JSON.parse('{"email": "", "age": "18"}')).messages
|