Class: Pageflow::Chart::RefreshTagFollowingDownloader

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/pageflow/chart/refresh_tag_following_downloader.rb

Defined Under Namespace

Classes: NoUrlInRefreshMetaTag, TooManyRedirects

Constant Summary collapse

MAX_REDIRECT_COUNT =
3

Instance Method Summary collapse

Instance Method Details

#load_following_refresh_tags(url, options = {}, redirect_count = 0, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pageflow/chart/refresh_tag_following_downloader.rb', line 12

def load_following_refresh_tags(url, options = {}, redirect_count = 0, &block)
  load(url, options) do |file|
    if (redirect_url = find_refresh_meta_tag_url(file.read))
      if redirect_count >= MAX_REDIRECT_COUNT
        raise TooManyRedirects, 'Too many redirects via refresh meta tags.'
      end

      redirect_url = ensure_absolute(redirect_url, url)
      return load_following_refresh_tags(redirect_url, options, redirect_count + 1, &block)
    end

    file.rewind
    yield file if block_given?
  end
end