Class: RecursiveValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/vexile/validators/recursive_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/vexile/validators/recursive_validator.rb', line 2

def validate_each(record, attribute, value)
  param_proxy = record.__send__(attribute)
  if param_proxy
    if param_proxy.respond_to? :each
      param_proxy.each do |sub_proxy|
        record.errors.add attribute, "is invalid in #{sub_proxy} : #{sub_proxy.errors.messages}" if !sub_proxy.valid?
      end
    else
      record.errors.add attribute, "is invalid in #{param_proxy} : #{param_proxy.errors.messages}" if !param_proxy.valid?
    end
  end
end