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
# File 'app/models/kithe/validators/model_parent.rb', line 2

def validate(record)
  if record.parent.present? && (record.parent.class <= Kithe::Asset)
    record.errors[:parent] << 'can not be an Asset instance'
  end

  if record.parent.present? && record.class <= Kithe::Collection
    record.errors[:parent] << 'is invalid for Collection instances'
  end

  # TODO avoid recursive parents, maybe using a postgres CTE for efficiency?
end