Sha256: 70fe9cb108dc8af554eac16f21364515f25a6063149bdc4e98fd31696daeebe9

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

# Make Wgit::Urls look like Strings when inspected.
class Wgit::Url
  def inspect
    to_s.inspect
  end
end

# Define a method on each doc for recording unparsable links.
# Unparsable links are recorded as broken links by Finder.
class Wgit::Document
  def unparsable_links
    @unparsable_links ||= []
  end
end

# Returns a Wgit::Url or nil (if link is unparsable).
# A proc is preferrable to a function to avoid polluting the global namespace.
parse_link = lambda do |doc, link|
  Wgit::Url.new(link)
rescue StandardError
  doc.unparsable_links << link
  nil
end

# Define a custom extractor for all page links we're interested in checking.
Wgit::Document.define_extractor(
  :all_links,
  lambda { BrokenLinkFinder::link_xpath },
  singleton: false,
  text_content_only: true
) do |links, doc|
  links
    .uniq
    .map { |link| parse_link.call(doc, link) }
    .compact
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
broken_link_finder-0.12.3 lib/broken_link_finder/wgit_extensions.rb