Class: Vldt::Join
- Inherits:
-
Validation
- Object
- Validation
- Vldt::Join
- Defined in:
- lib/vldt/join.rb
Overview
Join multiple validations together and merge all of their errors.
Instance Method Summary collapse
- #call(object) ⇒ Object
-
#initialize(*validations) ⇒ Join
constructor
A new instance of Join.
Constructor Details
#initialize(*validations) ⇒ Join
Returns a new instance of Join.
4 5 6 |
# File 'lib/vldt/join.rb', line 4 def initialize (*validations) @validations = validations end |
Instance Method Details
#call(object) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vldt/join.rb', line 8 def call (object) errors = @validations.map { |v| v.call(object) } if errors.any? errors.compact.inject(Hash.new([])) do |es, e| e.each do |k, v| es[k] += v end es end end end |