Class: Recluse::Tasks::Status
Overview
Starting from the roots, goes through each runnable link and records the referrer, the status code, and any errors.
Instance Attribute Summary
Attributes inherited from Task
Instance Method Summary collapse
-
#initialize(profile, quiet: false, results: nil) ⇒ Status
constructor
Create new status task.
Methods inherited from Task
Constructor Details
#initialize(profile, quiet: false, results: nil) ⇒ Status
Create new status task.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/recluse/tasks/status.rb', line 14 def initialize(profile, quiet: false, results: nil) super(profile, queue_options: { redirect: profile.redirect }, results: results) addr_roots = profile.roots.map { |root| Addressable::URI.parse(root.url) } @queue.run_if do |link| next false unless link.run?(profile.blacklist, profile.whitelist) internal = link.internal?(addr_roots) next false if profile.internal_only && !internal if @results.child?(link.absolute) @results.add link.absolute, link.parent next false end @results.add link.absolute, link.parent if profile.scheme_squash alt = link.address alt.scheme = alt.scheme == 'http' ? 'https' : 'http' if @results.child?(alt.to_s) @results.set_child_value link.absolute, @results.get_child_value(alt.to_s) next false end end true end @queue.on_complete do |link, response| result = Recluse::Result.new response.code.to_s, response.errors if response.success internal = link.internal? addr_roots if profile.redirect result_link = Recluse::Link.new response.page.uri.to_s, link.parent internal = result_link.internal? addr_roots end queue.add(response.page.links.map { |new_link| Link.new(new_link.uri.to_s, link.absolute) }) if internal && (response.page.class != Mechanize::File) && (response.page.class != Mechanize::Image) end @results.set_child_value link.absolute, result unless quiet puts "[#{profile.name.colorize(mode: :bold)}][#{result.code.colorize(color: result.color, mode: :bold)}][#{(internal ? 'internal' : 'external').colorize(mode: :bold)}] #{link.absolute}" puts "\a^ #{'Error'.colorize(mode: :bold, color: :red)}: #{result.error}" unless result.error == false end end end |