Class: Hyrax::CollectionMembershipValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Hyrax::CollectionMembershipValidator
- 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
-
#initialize(options = {}) ⇒ CollectionMembershipValidator
constructor
A new instance of CollectionMembershipValidator.
- #validate(record) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CollectionMembershipValidator
Returns a new instance of CollectionMembershipValidator.
8 9 10 11 |
# File 'app/validators/hyrax/collection_membership_validator.rb', line 8 def initialize( = {}) @multiple_membership_checker = [:multiple_membership_checker] || Hyrax::MultipleMembershipChecker super() 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 |