Class: Hydra::PCDM::Validators::AncestorValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/pcdm/validators/ancestor_validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, record) ⇒ AncestorValidator

Returns a new instance of AncestorValidator.



8
9
10
11
# File 'lib/hydra/pcdm/validators/ancestor_validator.rb', line 8

def initialize(owner, record)
  @owner = owner
  @record = record
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



7
8
9
# File 'lib/hydra/pcdm/validators/ancestor_validator.rb', line 7

def owner
  @owner
end

#recordObject (readonly)

Returns the value of attribute record.



7
8
9
# File 'lib/hydra/pcdm/validators/ancestor_validator.rb', line 7

def record
  @record
end

Class Method Details

.validate!(association, record) ⇒ Object



3
4
5
# File 'lib/hydra/pcdm/validators/ancestor_validator.rb', line 3

def self.validate!(association, record)
  new(association.owner, record).validate!
end

Instance Method Details

#validate!Object

Raises:

  • (ArgumentError)


13
14
15
16
# File 'lib/hydra/pcdm/validators/ancestor_validator.rb', line 13

def validate!
  return unless owner.ancestor?(record)
  raise ArgumentError, "#{record.class} with ID: #{record.id} failed to pass AncestorChecker validation"
end