Module: Fetch::Async

Included in:
Module
Defined in:
lib/fetch/async.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fetch/async.rb', line 3

def self.included(base)
  base.define_callback :request,
                       :defaults,
                       :before_process,
                       :after_process

  base.defaults do |req|
    req.before_process { before_process } if callback?(:before_process)
    req.after_process { after_process } if callback?(:after_process)
    req.failure { |code, url| failure(code, url) } if callback?(:failure)
    req.error { |e| error(e) } if callback?(:error)
  end
end

Instance Method Details

#requestsObject



17
18
19
20
21
22
23
24
# File 'lib/fetch/async.rb', line 17

def requests
  self.class.callbacks[:request].map do |callback|
    Request.new.tap do |req|
      defaults(req)
      instance_exec(req, &callback)
    end
  end.select(&:url)
end