Sha256: 8d0688b3407404bb752bd201e564129effd94d5750ec25908b82be3d886cb6fe

Contents?: true

Size: 538 Bytes

Versions: 3

Compression:

Stored size: 538 Bytes

Contents

# frozen_string_literal: true

module Wayfarer
  module Networking
    RedirectsExhaustedError = Class.new(StandardError)

    Follow = Struct.new(:context) do
      extend Forwardable

      delegate %i[live renew instance] => :context

      def fetch(url, follow: 3)
        raise RedirectsExhaustedError if follow.negative?

        case result = context.fetch(url)
        when Result::Success then result.page
        when Result::Redirect then fetch(result.redirect_url, follow: follow - 1)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wayfarer-0.4.6 lib/wayfarer/networking/follow.rb
wayfarer-0.4.5 lib/wayfarer/networking/follow.rb
wayfarer-0.4.4 lib/wayfarer/networking/follow.rb