Class: HTML::Proofer::Checks::Check
- Inherits:
-
Object
- Object
- HTML::Proofer::Checks::Check
- Defined in:
- lib/html/proofer/check.rb
Instance Attribute Summary collapse
-
#additional_href_ignores ⇒ Object
readonly
Returns the value of attribute additional_href_ignores.
-
#hydra ⇒ Object
readonly
Returns the value of attribute hydra.
-
#issues ⇒ Object
readonly
Returns the value of attribute issues.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Class Method Summary collapse
Instance Method Summary collapse
- #add_issue(desc) ⇒ Object
-
#initialize(src, path, html, opts = {}) ⇒ Check
constructor
A new instance of Check.
- #output_filenames ⇒ Object
- #request_url(url) ⇒ Object
- #run ⇒ Object
- #validate_url(href, issue_text) ⇒ Object
Constructor Details
#initialize(src, path, html, opts = {}) ⇒ Check
Returns a new instance of Check.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/html/proofer/check.rb', line 15 def initialize(src, path, html, opts={}) @src = src @path = path @html = html = opts @issues = [] @hydra = Typhoeus::Hydra.hydra @additional_href_ignores = [:href_ignore] || [] end |
Instance Attribute Details
#additional_href_ignores ⇒ Object (readonly)
Returns the value of attribute additional_href_ignores.
13 14 15 |
# File 'lib/html/proofer/check.rb', line 13 def additional_href_ignores @additional_href_ignores end |
#hydra ⇒ Object (readonly)
Returns the value of attribute hydra.
13 14 15 |
# File 'lib/html/proofer/check.rb', line 13 def hydra @hydra end |
#issues ⇒ Object (readonly)
Returns the value of attribute issues.
13 14 15 |
# File 'lib/html/proofer/check.rb', line 13 def issues @issues end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/html/proofer/check.rb', line 13 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/html/proofer/check.rb', line 13 def path @path end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
13 14 15 |
# File 'lib/html/proofer/check.rb', line 13 def src @src end |
Class Method Details
.subclasses ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/html/proofer/check.rb', line 67 def self.subclasses classes = [] ObjectSpace.each_object(Class) do |c| next unless c.superclass == self classes << c end classes end |
Instance Method Details
#add_issue(desc) ⇒ Object
30 31 32 |
# File 'lib/html/proofer/check.rb', line 30 def add_issue(desc) @issues << "#{@path.blue}: #{desc}" end |
#output_filenames ⇒ Object
34 35 36 |
# File 'lib/html/proofer/check.rb', line 34 def output_filenames Dir[@site.config[:output_dir] + '/**/*'].select{ |f| File.file?(f) } end |
#request_url(url) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/html/proofer/check.rb', line 56 def request_url(url) path = (url.path.nil? || url.path.empty? ? '/' : url.path) req = Net::HTTP::Head.new(path) http = Net::HTTP.new(url.host, url.port) if url.instance_of? URI::HTTPS http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end res = http.request(req) end |
#run ⇒ Object
26 27 28 |
# File 'lib/html/proofer/check.rb', line 26 def run raise NotImplementedError.new("HTML::Proofer::Check subclasses must implement #run") end |
#validate_url(href, issue_text) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/html/proofer/check.rb', line 38 def validate_url(href, issue_text) request = Typhoeus::Request.new(href, {:followlocation => true}) request.on_complete do |response| if response.success? # no op elsif response.timed_out? self.add_issue(issue_text + " got a time out") elsif response.code == 0 # Could not get an http response, something's wrong. self.add_issue(issue_text + " #{response}") else # Received a non-successful http response. self.add_issue(issue_text + " HTTP request failed: " + response.code.to_s) unless response.code.to_s == "420" end end hydra.queue(request) end |