Class: Fetch::Base

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/fetch/base.rb

Instance Method Summary collapse

Methods included from Callbacks

included

Constructor Details

#initialize(fetchable = nil) ⇒ Base

Returns a new instance of Base.



28
29
30
# File 'lib/fetch/base.rb', line 28

def initialize(fetchable = nil)
  @fetchable = fetchable
end

Instance Method Details

#fetchObject

Begin fetching. Will run synchronous fetches first and async fetches afterwards. Updates progress when each module finishes its fetch.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fetch/base.rb', line 35

def fetch
  requests = instantiate_modules.select(&:fetch?).map(&:requests).flatten

  total, done = requests.size, 0
  update_progress(total, done)

  before_fetch

  backend.new(requests).run do
    update_progress(total, done += 1)
  end

  after_fetch

  true
rescue => e
  error(e)
  raise e
end