Class: Marko::Validators::NonUniqueId

Inherits:
Object
  • Object
show all
Defined in:
lib/marko/validators/non_unique_id.rb

Overview

Non unique id validator

Instance Method Summary collapse

Instance Method Details

#call(tree) ⇒ Object

Parameters:

  • tree (Enumerable)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/marko/validators/non_unique_id.rb', line 9

def call(tree)
  topics = tree
    .group_by(&:id)
    .select{|_, items| items.size > 1 }

  topics.map do |id, items|
    sources = items.map{"  #{it.markup}"}.join(?\n)
    message = "the same id [#{id}] found in\n#{sources}"
    Marko::ValidatorError.new(message)          
  end
end