Class: StandaloneValidator::ValidationResultBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/standalone_validator/validation_result_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#validated_object=(value) ⇒ Object

Sets the attribute validated_object

Parameters:

  • value

    the value to set the attribute validated_object to.



6
7
8
# File 'lib/standalone_validator/validation_result_builder.rb', line 6

def validated_object=(value)
  @validated_object = value
end

Instance Method Details

#add_violation(attribute_name, violation_type_or_message, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/standalone_validator/validation_result_builder.rb', line 13

def add_violation(attribute_name, violation_type_or_message, options = {})
  creation_attributes = {
    :attribute     => attribute_name.to_sym,
    :source_object => validated_object,
    :options       => options,
  }

  if violation_type_or_message.kind_of?(Symbol)
    creation_attributes[:type] = violation_type_or_message
  else
    creation_attributes[:message] = violation_type_or_message
  end

  push_violation(Violation.new(creation_attributes))
  self
end

#merge_result(result) ⇒ Object



8
9
10
11
# File 'lib/standalone_validator/validation_result_builder.rb', line 8

def merge_result(result)
  combined_results << result
  self
end

#resultObject



30
31
32
33
34
35
# File 'lib/standalone_validator/validation_result_builder.rb', line 30

def result
  ValidationResult.new(
    :validated_object => validated_object,
    :violations       => all_violations
  )
end