Sha256: 1ac3688da51dd0a21876bb7a463f91e4dc1095f854716e24abd8cd75ce95cd2e

Contents?: true

Size: 463 Bytes

Versions: 14

Compression:

Stored size: 463 Bytes

Contents

class Kithe::Validators::ModelParent < ActiveModel::Validator
  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
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kithe-2.0.3 app/models/kithe/validators/model_parent.rb
kithe-2.0.2 app/models/kithe/validators/model_parent.rb
kithe-2.0.1 app/models/kithe/validators/model_parent.rb
kithe-2.0.0 app/models/kithe/validators/model_parent.rb
kithe-2.0.0.pre.rc1 app/models/kithe/validators/model_parent.rb
kithe-2.0.0.pre.beta1 app/models/kithe/validators/model_parent.rb
kithe-2.0.0.pre.alpha2 app/models/kithe/validators/model_parent.rb
kithe-2.0.0.pre.alpha1 app/models/kithe/validators/model_parent.rb
kithe-1.1.2 app/models/kithe/validators/model_parent.rb
kithe-1.1.1 app/models/kithe/validators/model_parent.rb
kithe-1.1.0 app/models/kithe/validators/model_parent.rb
kithe-1.0.0 app/models/kithe/validators/model_parent.rb
kithe-0.3.0 app/models/kithe/validators/model_parent.rb
kithe-0.2.0 app/models/kithe/validators/model_parent.rb