Class: LinkChecker::Tasks

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#callbacks, #delegates, #method_missing, #on

Constructor Details

#initialize(checker, task_klass, uri, methods, options = {}) ⇒ Tasks

Returns a new instance of Tasks.

Raises:

  • (ArgumentError)


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

def initialize(checker, task_klass, uri, methods, options = {})
  @uri = uri
  @retries_left = checker.retries
  @methods_left = methods.dup
  @methods = methods.dup
  @task_klass = task_klass
  @checker = checker
  @logger = checker.logger
  @redirects = [uri]
  @options = options
  raise ArgumentError, :tasks_klass unless @task_klass && @task_klass < ::LinkChecker::Task
end

Dynamic Method Handling

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

Instance Attribute Details

#original_uriObject (readonly)

Returns the value of attribute original_uri.



5
6
7
# File 'lib/ruby-link-checker/tasks.rb', line 5

def original_uri
  @original_uri
end

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/ruby-link-checker/tasks.rb', line 5

def result
  @result
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/ruby-link-checker/tasks.rb', line 5

def uri
  @uri
end

Instance Method Details

#execute!Object



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

def execute!
  if retry?
    @retries_left -= 1
    retry! @result
    _queue_task(uri, method, original_uri || uri, options)
  elsif methods_left.any?
    @method = methods_left.shift
    @uri = URI(@uri) unless @uri.is_a?(URI)
    _queue_task(uri, method, original_uri || uri, options)
  elsif @result && result.error?
    error! @result
  else
    failure! @result
  end
rescue StandardError => e
  logger.error("#{self}##{__method__}") { e }
  _handle_result ResultError.new(uri, method, original_uri || uri, e, options)
end

#new_task(uri, method, original_uri, options) ⇒ Object



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

def new_task(uri, method, original_uri, options)
  task_klass.new(checker, uri, method, original_uri, options)
end