Class: Chemicalml::Convention::Dictionary::Constraints::EntryIdsUniqueWithinDictionary

Inherits:
Constraint::NodeConstraint show all
Defined in:
lib/chemicalml/convention/dictionary/constraints/entry_ids_unique_within_dictionary.rb

Overview

Entry ids MUST be unique within the parent dictionary per the dictionary convention.

Instance Method Summary collapse

Methods inherited from Constraint::NodeConstraint

#check

Instance Method Details

#check_node(node, path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chemicalml/convention/dictionary/constraints/entry_ids_unique_within_dictionary.rb', line 10

def check_node(node, path)
  return [] unless dictionary?(node)

  entries = node.entries || []
  ids = entries.map { |e| e.id }.compact
  duplicates = ids.group_by { |x| x }.select { |_, v| v.length > 1 }.keys
  return [] if duplicates.empty?

  duplicates.map do |dup|
    violation(path: path.join("/"),
              message: "duplicate entry id #{dup.inspect} within dictionary")
  end
end