Class: Magellan::BrokenLinkTracker
- Inherits:
-
Object
- Object
- Magellan::BrokenLinkTracker
- Includes:
- Observable
- Defined in:
- lib/magellan/broken_link_tracker.rb
Overview
The class that will track all broken links, urls that return 4** or 5** http status codes.
Instance Attribute Summary collapse
-
#broken_links ⇒ Object
readonly
All results containing 4** or 5** http status codes.
Instance Method Summary collapse
-
#broken_link_message(result) ⇒ Object
Generate the failure message for a Magellan::Result.
-
#failed? ⇒ Boolean
Are there any broken links?.
-
#failure_message ⇒ Object
A text message of all failures.
-
#initialize ⇒ BrokenLinkTracker
constructor
Create a new broken link tracker.
-
#update(time, result) ⇒ Object
The updates that come in via a observable subject, the time the result came at and the Magellan::Result itself.
Constructor Details
#initialize ⇒ BrokenLinkTracker
Create a new broken link tracker
10 11 12 13 |
# File 'lib/magellan/broken_link_tracker.rb', line 10 def initialize @broken_links = [] @first_linked_from = {} end |
Instance Attribute Details
#broken_links ⇒ Object (readonly)
All results containing 4** or 5** http status codes
7 8 9 |
# File 'lib/magellan/broken_link_tracker.rb', line 7 def broken_links @broken_links end |
Instance Method Details
#broken_link_message(result) ⇒ Object
Generate the failure message for a Magellan::Result
37 38 39 |
# File 'lib/magellan/broken_link_tracker.rb', line 37 def (result) "#{result.url} first linked from: #{@first_linked_from[result.url]} returned: #{result.status_code}" end |
#failed? ⇒ Boolean
Are there any broken links?
27 28 29 |
# File 'lib/magellan/broken_link_tracker.rb', line 27 def failed? !@broken_links.empty? end |
#failure_message ⇒ Object
A text message of all failures
32 33 34 |
# File 'lib/magellan/broken_link_tracker.rb', line 32 def @broken_links.map{|broken_link| (broken_link)}.join("\n") end |
#update(time, result) ⇒ Object
The updates that come in via a observable subject, the time the result came at and the Magellan::Result itself.
16 17 18 19 20 21 22 23 24 |
# File 'lib/magellan/broken_link_tracker.rb', line 16 def update(time,result) failed = result.status_code.starts_with?("5") || result.status_code.starts_with?("4") @broken_links << result if failed changed notify_observers(Time.now, !failed, (result)) result.absolute_linked_resources.each do |linked_resource| @first_linked_from[linked_resource] = result.url if !@first_linked_from.has_key?(linked_resource) end end |