Class: Hyrax::CollectionMembershipValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/hyrax/collection_membership_validator.rb

Overview

Validates that the record passes the multiple membership requirements for collections.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CollectionMembershipValidator

Returns a new instance of CollectionMembershipValidator.

Parameters:

  • multiple_membership_checker


8
9
10
11
# File 'app/validators/hyrax/collection_membership_validator.rb', line 8

def initialize(options = {})
  @multiple_membership_checker = options[:multiple_membership_checker] || Hyrax::MultipleMembershipChecker
  super(options)
end

Instance Method Details

#validate(record) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'app/validators/hyrax/collection_membership_validator.rb', line 13

def validate(record)
  # collections-in-collections do not have multi-membership restrictions
  return true if record.is_a? Hyrax::Forms::PcdmCollectionForm
  checker = @multiple_membership_checker.new(item: nil)
  ids = collections_ids(record)

  error = checker.check(collection_ids: ids)
  record.errors.add(:member_of_collection_ids, error) if error
end