Class: LinkChecker::Async::HTTP::Checker

Inherits:
Checker
  • Object
show all
Extended by:
Config
Defined in:
lib/ruby-link-checker/async/http/checker.rb

Constant Summary

Constants included from Config

LinkChecker::Async::HTTP::Config::ATTRIBUTES

Constants included from Config

Config::ATTRIBUTES

Instance Attribute Summary

Attributes inherited from Checker

#results

Instance Method Summary collapse

Methods included from Config

reset

Methods inherited from Checker

#check, #task_klass

Methods included from Callbacks

#callbacks, #delegates, #method_missing, #on

Methods included from Config

#reset, #retries=

Constructor Details

#initialize(options = {}) ⇒ Checker

Returns a new instance of Checker.



39
40
41
42
43
44
45
46
# File 'lib/ruby-link-checker/async/http/checker.rb', line 39

def initialize(options = {})
  LinkChecker::Async::HTTP::Config::ATTRIBUTES.each do |key|
    send("#{key}=", options[key] || LinkChecker::Async::HTTP::Config.send(key))
  end
  @queue = []
  @clients = {}
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LinkChecker::Callbacks

Instance Method Details

#_client_for(uri) ⇒ Object

Returns a client for the given URI's host/port/scheme, reusing (and pooling connections on) one client per endpoint across all checks.



69
70
71
72
73
74
75
# File 'lib/ruby-link-checker/async/http/checker.rb', line 69

def _client_for(uri)
  key = [uri.scheme, uri.host, uri.port]
  @clients[key] ||= begin
    endpoint = ::Async::HTTP::Endpoint.parse(uri.to_s, timeout: open_timeout)
    ::Async::HTTP::Client.new(endpoint)
  end
end

#_queue(&block) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ruby-link-checker/async/http/checker.rb', line 59

def _queue(&block)
  if @barrier
    @barrier.async(&block)
  else
    @queue << block
  end
end

#runObject

Runs all queued checks concurrently and blocks until they complete.



49
50
51
52
53
54
55
56
57
# File 'lib/ruby-link-checker/async/http/checker.rb', line 49

def run
  Barrier do |barrier|
    @barrier = barrier
    _flush!
  end
ensure
  @barrier = nil
  _close_clients!
end