Class: LinkChecker::Checker

Inherits:
Object
  • Object
show all
Includes:
Callbacks, Config
Defined in:
lib/ruby-link-checker/checker.rb

Direct Known Subclasses

Net::HTTP::Checker, Typhoeus::Hydra::Checker

Constant Summary

Constants included from Config

LinkChecker::Config::ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/ruby-link-checker/checker.rb', line 11

def initialize(options = {})
  LinkChecker::Config::ATTRIBUTES.each do |key|
    send("#{key}=", options[key] || LinkChecker.config.send(key))
  end
  raise ArgumentError, "Missing methods." if methods&.none?
  @logger ||= options[:logger] || LinkChecker::Config.logger || LinkChecker::Logger.default
  @results = { error: [], failure: [], success: [] } unless options.key?(:results) && !options[:results]
end

Dynamic Method Handling

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

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



8
9
10
# File 'lib/ruby-link-checker/checker.rb', line 8

def results
  @results
end

Instance Method Details

#check(uri, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby-link-checker/checker.rb', line 27

def check(uri, options = {})
  tasks = Tasks.new(
    self,
    task_klass,
    uri,
    methods,
    options
  )
  tasks.on do |event, *args|
    results[event] << args.first if @results && %i[error failure success].include?(event)
    callback event, *args
  end
  tasks.execute!
end

#task_klassObject



20
21
22
23
24
25
# File 'lib/ruby-link-checker/checker.rb', line 20

def task_klass
  @task_klass ||= begin
    module_name = self.class.name.split("::")[...-1].join('::')
    Object.const_get("#{module_name}::Task")
  end
end