Class: Dag::CreateCorrectnessValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/dag/validators.rb

Overview

Validations on model instance creation. Ensures no duplicate links, no cycles, and correct count and direct attributes

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/dag/validators.rb', line 6

def validate(record)
  record.errors[:base] << 'Link already exists between these points' if has_duplicates(record)
  record.errors[:base] << 'Link already exists in the opposite direction' if has_long_cycles(record)
  record.errors[:base] << 'Link must start and end in different places' if has_short_cycles(record)
  cnt = check_possible(record)
  record.errors[:base] << 'Cannot create a direct link with a count other than 0' if cnt == 1
  record.errors[:base] << 'Cannot create an indirect link with a count less than 1' if cnt == 2
end