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
14
15
16
17
18
19
# 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|
        if !sub_proxy.valid?
          message = I18n.translate('errors.messages.recursively_invalid', :in => sub_proxy, :messages => sub_proxy.errors.messages)
          record.errors.add attribute, message
        end
      end
    else
      if !param_proxy.valid?
        message = I18n.translate('errors.messages.recursively_invalid', :in => param_proxy, :messages => param_proxy.errors.messages)
        record.errors.add attribute, message
      end
    end
  end
end