Class: Wayfarer::Middleware::Fetch

Inherits:
Object
  • Object
show all
Includes:
Stage::API
Defined in:
lib/wayfarer/middleware/fetch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Stage::API

#stage

Constructor Details

#initializeFetch

Returns a new instance of Fetch.



11
12
13
# File 'lib/wayfarer/middleware/fetch.rb', line 11

def initialize
  @pool = Wayfarer::Networking::Pool.instance
end

Instance Attribute Details

#poolObject (readonly)

Returns the value of attribute pool.



8
9
10
# File 'lib/wayfarer/middleware/fetch.rb', line 8

def pool
  @pool
end

#taskObject

Returns the value of attribute task.



9
10
11
# File 'lib/wayfarer/middleware/fetch.rb', line 9

def task
  @task
end

Instance Method Details

#call(task) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wayfarer/middleware/fetch.rb', line 15

def call(task)
  self.task = task

  pool.with do |adapter|
    task..adapter = adapter

    case result = adapter.fetch(task.url)
    when Networking::Result::Redirect
      stage(result.redirect_url)
    when Networking::Result::Success
      task..page = result.page
      yield if block_given?
    end
  end
end