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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e4c71fbfec915c2b341d8507a97403dd0390fe0
4
- data.tar.gz: 80d10cdc28ed21110da952d3c956ac0b5ba74360
3
+ metadata.gz: 7ecee8baed33039c0722b3130cf3c941e6234329
4
+ data.tar.gz: 2c6c36bf834751781320111537bc091b469ba340
5
5
  SHA512:
6
- metadata.gz: 7717b19760fb477779c9c3c0bce4f3b32b686a8ea41cabea4aeee0531f7f278dff44c23723a8242e4f3ab1fb5d35f3c460dd0654ab9dd010e31550c9115ad9ff
7
- data.tar.gz: 66d3e24dbaa64f71bb0ba8c07e03ef65532bcee5c5303689f31e6e52b4eed37acb473c6979b3b7c4614249481ffcaf2948f95999bd01defd7fbada8447f3d82e
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
@@ -94,6 +94,11 @@ module FluentValidation
94
94
  self
95
95
  end
96
96
 
97
+ def with_error_code(error_code)
98
+ @attribute_rule.error_code = error_code
99
+ self
100
+ end
101
+
97
102
  def when(&expression)
98
103
  @attribute_rule.condition = expression
99
104
  self
@@ -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
@@ -1,3 +1,3 @@
1
1
  module FluentValidation
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Yu