Class: Kithe::Validators::ModelParent

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/kithe/validators/model_parent.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/models/kithe/validators/model_parent.rb', line 2

def validate(record)
  # don't load the parent just to validate it if it hasn't even changed.
  return unless record.parent_id_changed?

  if record.parent.present? && (record.parent.class <= Kithe::Asset)
    record.errors.add(:parent, 'can not be an Asset instance')
  end

  if record.parent.present? && record.class <= Kithe::Collection
    record.errors.add(:parent, 'is invalid for Collection instances')
  end
end