dry-validation-matchers 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/dry/validation/matchers/validate_matcher.rb +35 -1
- data/lib/dry/validation/matchers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 114a34fb8b5a6e38dd5940013d850f90c143b3ac
|
4
|
+
data.tar.gz: 8de84e039e1f043018ffb97d591c73b65a361abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9684d7132fce67d1d6933e22b124979fa32f415fa4bcd169d3acba074e4636d870514c676752ba2e6db51d998c0919ef9411f27514bdcefb6f00cf2165c38d3
|
7
|
+
data.tar.gz: f3889efd51bedc92d9b2a8d650f3a9543ed35061dadce9f06cab7b3fbbaf012ecdbe86338dbac2a97ce30c7f19593f03de8bbccee4026049788c7dca434e8328
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
+
## [0.4.0] - 2016-11-10
|
8
|
+
### Added
|
9
|
+
- Add support for checking that the value is included_in
|
10
|
+
|
7
11
|
## [0.3.0] - 2016-11-09
|
8
12
|
### Added
|
9
13
|
- Add support for float, decimal, bool, date, time, date_time, array, hash
|
@@ -49,6 +49,7 @@ module Dry::Validation::Matchers
|
|
49
49
|
@attr = attr
|
50
50
|
@acceptance = acceptance
|
51
51
|
@type = DEFAULT_TYPE
|
52
|
+
@value_rules = []
|
52
53
|
end
|
53
54
|
|
54
55
|
def description
|
@@ -87,7 +88,8 @@ module Dry::Validation::Matchers
|
|
87
88
|
|
88
89
|
check_required_or_optional!(schema) &&
|
89
90
|
check_filled!(schema) &&
|
90
|
-
check_filled_with_type!(schema)
|
91
|
+
check_filled_with_type!(schema) &&
|
92
|
+
check_value!(schema)
|
91
93
|
end
|
92
94
|
|
93
95
|
def filled(type=:str)
|
@@ -96,6 +98,11 @@ module Dry::Validation::Matchers
|
|
96
98
|
self
|
97
99
|
end
|
98
100
|
|
101
|
+
def value(value_rules)
|
102
|
+
@value_rules = value_rules
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
99
106
|
private
|
100
107
|
|
101
108
|
def check_required_or_optional!(schema)
|
@@ -131,5 +138,32 @@ module Dry::Validation::Matchers
|
|
131
138
|
unallowed_errors.empty?
|
132
139
|
end
|
133
140
|
|
141
|
+
def check_value!(schema)
|
142
|
+
@value_rules.map do |rule|
|
143
|
+
method_name = :"check_value_#{rule[0]}!"
|
144
|
+
return true if !self.class.private_method_defined?(method_name)
|
145
|
+
send(method_name, schema, rule)
|
146
|
+
end.none? {|result| result == false}
|
147
|
+
end
|
148
|
+
|
149
|
+
def check_value_included_in!(schema, rule)
|
150
|
+
predicate = rule[0]
|
151
|
+
allowed_values = rule[1]
|
152
|
+
|
153
|
+
invalid_for_expected_values = allowed_values.map do |v|
|
154
|
+
result = schema.(@attr => v)
|
155
|
+
error_messages = result.errors[@attr]
|
156
|
+
error_messages.present? && error_messages.grep(/must be one of/).any?
|
157
|
+
end.all? {|result| result == true}
|
158
|
+
return false if invalid_for_expected_values
|
159
|
+
|
160
|
+
value_outside_required = allowed_values.sample.to_s + SecureRandom.hex(2)
|
161
|
+
result = schema.(@attr => value_outside_required)
|
162
|
+
error_messages = result.errors[@attr]
|
163
|
+
return false if error_messages.nil?
|
164
|
+
return true if error_messages.grep(/must be one of/).any?
|
165
|
+
false
|
166
|
+
end
|
167
|
+
|
134
168
|
end
|
135
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-validation-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Tayag
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|