standalone_validator 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee76a41270f159a0fa58356c11739379f388b937
|
4
|
+
data.tar.gz: f482deae225caae5f396ff7995b808472e170573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f9183664c27a3bf6cfb812d8a47ebf5f2b15d83e548974b7e77e0ae1b899c0e13550b74f815fd1506276a998c3fb05b689ed1ecb15dd2e4d532f73b145b3aa9
|
7
|
+
data.tar.gz: 52ace947a6ff30a932c9c25e3db10be2d4625ad7280fa05f21cda29f9727e37faf35208d8c89c4b2264fd19332e9fa7089c7f224c7bcafa3021db4b933cbd17d
|
@@ -9,14 +9,18 @@ class StandaloneValidator
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
ALWAYS_TRUE =
|
12
|
+
ALWAYS_TRUE = ->(*) { true }.freeze
|
13
13
|
|
14
14
|
def self.condition_for(options)
|
15
15
|
if options.has_key?(:if)
|
16
16
|
options[:if].to_proc
|
17
17
|
elsif options.has_key?(:unless)
|
18
18
|
reverse_condition = options[:unless].to_proc
|
19
|
-
|
19
|
+
|
20
|
+
->(*args) {
|
21
|
+
negates = instance_exec(*args, &reverse_condition)
|
22
|
+
not negates
|
23
|
+
}
|
20
24
|
else
|
21
25
|
ALWAYS_TRUE
|
22
26
|
end
|
@@ -29,7 +33,7 @@ class StandaloneValidator
|
|
29
33
|
module ClassMethods
|
30
34
|
def include_validation(&block)
|
31
35
|
super do |object, result|
|
32
|
-
if
|
36
|
+
if instance_exec(object, &condition)
|
33
37
|
instance_exec(object, result, &block)
|
34
38
|
end
|
35
39
|
end
|