Class: Druid::Filter::FieldValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/druid/filter.rb

Constant Summary collapse

TYPES =
%w(not)

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/druid/filter.rb', line 85

def validate_each(record, attribute, value)
  if TYPES.include?(record.type)
    if value
      value.valid? # trigger validation
      value.errors.messages.each do |k, v|
        record.errors.add(attribute, { k => v })
      end
    else
      record.errors.add(attribute, "may not be blank")
    end
  else
    record.errors.add(attribute, "is not supported by type=#{record.type}") if value
  end
end