validation_profiler 0.1.7 → 0.1.8
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: e53851548256582e39989a8a22b0018199efdc0e
|
4
|
+
data.tar.gz: 5f37078093a5739ca512b91e78889d9370944eae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1c2f130d07fed5ded2e1400601d1e025702f705acc146689b06878d570a84e31fd8ce1021fa9ffe4a1af17e3dbc6d09ac6a3c4c862f850febba8e07c22e3d5b
|
7
|
+
data.tar.gz: e8214446621be710d79bc9466cd5d2e8633ccb10b6b5c5ab0dbdde3f5e4a3f2af44b98d16e803da05667f29475f059f082843fda6c9d6f5b66f4287541cebfaf
|
@@ -442,4 +442,69 @@ class ConditionValidationRule < ValidationRule
|
|
442
442
|
eval("#{a} #{expression} #{b}")
|
443
443
|
end
|
444
444
|
|
445
|
+
end
|
446
|
+
|
447
|
+
class NotAllowedValidationRule < ValidationRule
|
448
|
+
|
449
|
+
def error_message(field, attributes = {})
|
450
|
+
#check if a custom error message has been specified in the attributes
|
451
|
+
if attributes[:message] == nil
|
452
|
+
#no custom error message has been specified so create the default message.
|
453
|
+
"#{field} is not allowed."
|
454
|
+
else
|
455
|
+
attributes[:message]
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
|
460
|
+
def validate(obj, field, attributes = {})
|
461
|
+
|
462
|
+
#attempt to get the field value from the object
|
463
|
+
field_value = get_field_value(obj, field)
|
464
|
+
|
465
|
+
if field_value != nil
|
466
|
+
return false
|
467
|
+
end
|
468
|
+
|
469
|
+
return true
|
470
|
+
|
471
|
+
end
|
472
|
+
|
473
|
+
end
|
474
|
+
|
475
|
+
class ListValidationRule < ValidationRule
|
476
|
+
|
477
|
+
def error_message(field, attributes = {})
|
478
|
+
#check if a custom error message has been specified in the attributes
|
479
|
+
if attributes[:message] == nil
|
480
|
+
#no custom error message has been specified so create the default message.
|
481
|
+
"#{field} is not an accepted value."
|
482
|
+
else
|
483
|
+
attributes[:message]
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
|
488
|
+
def validate(obj, field, attributes = {})
|
489
|
+
|
490
|
+
#attempt to get the field value from the object
|
491
|
+
field_value = get_field_value(obj, field)
|
492
|
+
|
493
|
+
if !is_required?(field_value, attributes)
|
494
|
+
return true
|
495
|
+
end
|
496
|
+
|
497
|
+
list = attributes[:list]
|
498
|
+
if list == nil || !list.is_a?(Array)
|
499
|
+
raise InvalidRuleAttributes.new(ListValidationRule, field)
|
500
|
+
end
|
501
|
+
|
502
|
+
if !list.include?(field_value)
|
503
|
+
return false
|
504
|
+
end
|
505
|
+
|
506
|
+
return true
|
507
|
+
|
508
|
+
end
|
509
|
+
|
445
510
|
end
|
@@ -62,6 +62,8 @@ class ValidationRuleManager
|
|
62
62
|
@rules.push({ key: :regex, instance: RegexValidationRule.new })
|
63
63
|
@rules.push({ key: :match, instance: MatchValidationRule.new })
|
64
64
|
@rules.push({ key: :condition, instance: ConditionValidationRule.new })
|
65
|
+
@rules.push({ key: :not_allowed, instance: NotAllowedValidationRule.new })
|
66
|
+
@rules.push({ key: :list, instance: ListValidationRule.new })
|
65
67
|
|
66
68
|
end
|
67
69
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|