Class: Marko::Validators::LostLinks

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

Overview

Lost links validator

Instance Method Summary collapse

Instance Method Details

#call(tree) ⇒ Object

Parameters:

  • tree (Enumerable)


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

def call(tree)
  lost_links = tree.inject([]) do |memo, topic|
    lost = topic.links.reject{ topic.find_by_id(it) }
    memo << [topic, lost] if lost.any?
    memo
  end

  lost_links.map do |e, lost|
    message = "lost link #{lost.join(', ')} in #{e.markup}"  
    Marko::ValidatorError.new(message)
  end
end