class Recluse::Queue

Link checker

Public Class Methods

new(email, redirect: false) click to toggle source

Create an empty queue

# File lib/recluse/queue.rb, line 10
def initialize(email, redirect: false)
  @links = []
  @run_if = proc { true }
  @on_complete = proc { |link, response| }
  @redirect = redirect
  @email = email
  @agent = Mechanize.new do |a|
    a.ssl_version = 'TLSv1'
    a.verify_mode = OpenSSL::SSL::VERIFY_NONE
    a.max_history = nil
    a.follow_meta_refresh = true
    a.keep_alive = false
    a.redirect_ok = @redirect
    a.user_agent = "Mozilla/5.0 (compatible; recluse/#{Recluse::VERSION}; +#{Recluse::URL}) #{@email}"
  end
end

Public Instance Methods

add(link) click to toggle source

Add to queue.

# File lib/recluse/queue.rb, line 29
def add(link)
  @links += [*link]
end
on_complete(&block) click to toggle source

Run when a link has been checked. Procedure takes the link and response as inputs.

# File lib/recluse/queue.rb, line 41
def on_complete(&block)
  @on_complete = block
end
run() click to toggle source

Run queue

# File lib/recluse/queue.rb, line 67
def run
  until @links.empty?
    link = @links.shift
    run_link link
  end
end
run_if(&block) click to toggle source

If the test is true, run the link. Procedure takes the link as input.

# File lib/recluse/queue.rb, line 35
def run_if(&block)
  @run_if = block
end