Skip to content

Commit

Permalink
Merge pull request #18 from gjtorikian/cache-matched-urls
Browse files Browse the repository at this point in the history
Cache successful paths internally
  • Loading branch information
gjtorikian committed Dec 4, 2013
2 parents f549893 + 0e299e1 commit c652254
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GEM
ethon (0.6.1)
ffi (>= 1.3.0)
mime-types (~> 1.18)
ffi (1.9.0)
ffi (1.9.3)
gemoji (1.4.0)
github-markdown (0.5.5)
html-pipeline (0.0.14)
Expand All @@ -34,7 +34,7 @@ GEM
rinku (~> 1.7)
sanitize (~> 2.0)
i18n (0.6.5)
mime-types (1.25)
mime-types (1.25.1)
mini_portile (0.5.1)
minitest (4.7.5)
multi_json (1.8.1)
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task :default => :spec
2 changes: 1 addition & 1 deletion lib/html/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run
end

def self.create_nokogiri(path)
path << "/index.html" if File.directory? path #support for Jekyll-style links
path << "/index.html" if File.directory? path # support for Jekyll-style links
Nokogiri::HTML(File.read(path))
end

Expand Down
6 changes: 5 additions & 1 deletion lib/html/proofer/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(src, path, html, opts={})
@html = html
@options = opts
@issues = []
@checked_urls = {}

@hydra = Typhoeus::Hydra.hydra
@additional_href_ignores = @options[:href_ignore] || []
Expand All @@ -36,10 +37,11 @@ def output_filenames
end

def validate_url(href, issue_text)
return @checked_urls[href] if @checked_urls.has_key? href
request = Typhoeus::Request.new(href, {:followlocation => true})
request.on_complete do |response|
if response.success?
# no op
@checked_urls[href] = true
elsif response.timed_out?
self.add_issue(issue_text + " got a time out")
elsif response.code == 0
Expand All @@ -57,6 +59,8 @@ def validate_url(href, issue_text)
self.add_issue("#{issue_text} HTTP request failed: #{response_code}")
end
end

@checked_urls[href] = false unless response.success?
end
hydra.queue(request)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/html/proofer/checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(obj, check)
@id = obj['id']
@data_ignore_proofer = obj['data-proofer-ignore']
@check = check
@checked_paths = {}

if @href && @check.options[:href_swap]
@check.options[:href_swap].each do |link, replace|
Expand Down Expand Up @@ -73,7 +74,6 @@ def internal?
end

def file_path

return if path.nil?

if path =~ /^\// #path relative to root
Expand All @@ -94,7 +94,8 @@ def file_path

# checks if a file exists relative to the current pwd
def exists?
File.exist? absolute_path
return @checked_paths[absolute_path] if @checked_paths.has_key? absolute_path
@checked_paths[absolute_path] = File.exist? absolute_path
end

def absolute_path
Expand Down

0 comments on commit c652254

Please sign in to comment.