fluent_validation 0.0.3 → 0.0.4
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/lib/fluent_validation/attribute_rule.rb +2 -2
- data/lib/fluent_validation/results/validation_failure.rb +3 -1
- data/lib/fluent_validation/rule_builder.rb +5 -0
- data/lib/fluent_validation/validators/attribute_validator.rb +1 -1
- data/lib/fluent_validation/validators/attribute_validator_context.rb +3 -4
- data/lib/fluent_validation/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ecee8baed33039c0722b3130cf3c941e6234329
|
4
|
+
data.tar.gz: 2c6c36bf834751781320111537bc091b469ba340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d650612eb31c1643d98b4031e654ce7e51c58c53e64b6a01d2f5d626007c4244c2725416f54f161d2f488c0d8881d9de10c259afe3163357b71a4fd513830210
|
7
|
+
data.tar.gz: 63f5a5be4f37324ea92c4962ae295f9995b8ea228908bb57b2efa970c35ed10c2c0eb7c1266c9258104dc29d8db49e6f874f0bd71032a5ef6d7c1be0e5e5eafc
|
@@ -5,7 +5,7 @@ require 'fluent_validation/validators/attribute_validator_context'
|
|
5
5
|
module FluentValidation
|
6
6
|
class AttributeRule
|
7
7
|
attr_reader :expression, :validators
|
8
|
-
attr_accessor :attribute_name, :condition
|
8
|
+
attr_accessor :attribute_name, :condition, :error_code
|
9
9
|
|
10
10
|
def initialize(&expression)
|
11
11
|
@expression = expression
|
@@ -20,7 +20,7 @@ module FluentValidation
|
|
20
20
|
validation_failures = Array.new
|
21
21
|
if @condition.nil? || @condition.call(object)
|
22
22
|
value = expression.call object
|
23
|
-
validator_context = Validators::AttributeValidatorContext.new @attribute_name, value
|
23
|
+
validator_context = Validators::AttributeValidatorContext.new @attribute_name, value, @error_code
|
24
24
|
@validators.each do |validator|
|
25
25
|
result = validator.validate validator_context
|
26
26
|
validation_failures.concat result
|
@@ -2,10 +2,12 @@ module FluentValidation
|
|
2
2
|
module Results
|
3
3
|
class ValidationFailure
|
4
4
|
attr_reader :attribute_name
|
5
|
+
attr_reader :error_code
|
5
6
|
attr_reader :message
|
6
7
|
|
7
|
-
def initialize (attribute_name, message)
|
8
|
+
def initialize (attribute_name, error_code, message)
|
8
9
|
@attribute_name = attribute_name
|
10
|
+
@error_code = error_code
|
9
11
|
@message = message
|
10
12
|
end
|
11
13
|
end
|
@@ -10,7 +10,7 @@ module FluentValidation
|
|
10
10
|
|
11
11
|
unless is_valid?(validator_context)
|
12
12
|
failure_message = generate_failure_message(validator_context.attribute_name, validator_context.attribute_value)
|
13
|
-
validation_failures << Results::ValidationFailure.new(validator_context.attribute_name, failure_message)
|
13
|
+
validation_failures << Results::ValidationFailure.new(validator_context.attribute_name, validator_context.error_code, failure_message)
|
14
14
|
end
|
15
15
|
|
16
16
|
validation_failures
|
@@ -1,14 +1,13 @@
|
|
1
1
|
module FluentValidation
|
2
2
|
module Validators
|
3
3
|
class AttributeValidatorContext
|
4
|
-
attr_reader :attribute_name, :attribute_value
|
4
|
+
attr_reader :attribute_name, :attribute_value, :error_code
|
5
5
|
|
6
|
-
def initialize(attribute_name, attribute_value)
|
6
|
+
def initialize(attribute_name, attribute_value, error_code = nil)
|
7
7
|
@attribute_name = attribute_name
|
8
8
|
@attribute_value = attribute_value
|
9
|
+
@error_code = error_code
|
9
10
|
end
|
10
|
-
|
11
|
-
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|