Sha256: 01db836dd5ccd0fb9ac30b3c4dbce83154751fe08d490c7fb7d6369dfe420f8d

Contents?: true

Size: 507 Bytes

Versions: 18

Compression:

Stored size: 507 Bytes

Contents

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
kithe-2.16.0 app/models/kithe/validators/model_parent.rb
kithe-2.15.1 app/models/kithe/validators/model_parent.rb
kithe-2.15.0 app/models/kithe/validators/model_parent.rb
kithe-2.14.0 app/models/kithe/validators/model_parent.rb
kithe-2.13.0 app/models/kithe/validators/model_parent.rb
kithe-2.12.0 app/models/kithe/validators/model_parent.rb
kithe-2.11.0 app/models/kithe/validators/model_parent.rb
kithe-2.10.0 app/models/kithe/validators/model_parent.rb
kithe-2.9.1 app/models/kithe/validators/model_parent.rb
kithe-2.9.0 app/models/kithe/validators/model_parent.rb
kithe-2.8.0 app/models/kithe/validators/model_parent.rb
kithe-2.7.1 app/models/kithe/validators/model_parent.rb
kithe-2.7.0 app/models/kithe/validators/model_parent.rb
kithe-2.6.1 app/models/kithe/validators/model_parent.rb
kithe-2.6.0 app/models/kithe/validators/model_parent.rb
kithe-2.5.0 app/models/kithe/validators/model_parent.rb
kithe-2.4.0 app/models/kithe/validators/model_parent.rb
kithe-2.3.0 app/models/kithe/validators/model_parent.rb