Class: Dsl::Polymorphs::PolymorphValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/dsl/polymorphs.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, data) ⇒ Object



11
12
13
14
15
16
# File 'lib/dsl/polymorphs.rb', line 11

def validate_each(record, attribute, data)
  return unless record.try(attribute).try(:id).nil? &&
                record.try("#{attribute}_id".to_sym).nil? &&
                !options[:keys].include?(data['type'].try(:to_sym))
  record.errors.add(attribute, 'type must be included in the list')
end