Class: Bookwatch::Postprocessing::LinkChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/bookwatch/postprocessing/link_checker.rb

Instance Method Summary collapse

Constructor Details

#initialize(fs, root_path, output_streams) ⇒ LinkChecker

Returns a new instance of LinkChecker.



8
9
10
11
12
13
14
15
16
17
# File 'lib/bookwatch/postprocessing/link_checker.rb', line 8

def initialize(fs, root_path, output_streams)
  @fs = fs
  @root_path = root_path
  @output_streams = output_streams
  @broken_link_count = 0

  @convert_to_relative = %r{\A.*#{root_path.to_s}/public}
  @default_link_exclusions = %r{\A(?:https?://|javascript:|mailto:)}
  @excluded_pages = %r{\A/(?:404\.html|subnavs|javascripts|stylesheets|style_guide)}
end

Instance Method Details

#check!(link_exclusions = /(?!.*)/) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bookwatch/postprocessing/link_checker.rb', line 19

def check!(link_exclusions = /(?!.*)/)
  @output_streams[:out].puts "\nChecking for broken links..."
  @redirects = Redirection.new(@fs, File.join(@root_path, 'redirects.rb'))
  load_page_links

  report_broken_links!(link_exclusions)
  report_orphaned_pages!

  if has_errors?
    err "\nFound #{@broken_link_count} broken links!"
  else
    out "\nNo broken links!"
  end
end

#has_errors?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/bookwatch/postprocessing/link_checker.rb', line 34

def has_errors?
  @broken_link_count > 0
end