Class: Aitch::Redirect

Inherits:
Object show all
Defined in:
lib/aitch/redirect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Redirect

Returns a new instance of Redirect.



7
8
9
10
# File 'lib/aitch/redirect.rb', line 7

def initialize(options)
  @tries = 1
  @options = options
end

Instance Attribute Details

#triesObject (readonly)

Returns the value of attribute tries.



5
6
7
# File 'lib/aitch/redirect.rb', line 5

def tries
  @tries
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/aitch/redirect.rb', line 24

def enabled?
  @options[:follow_redirect]
end

#follow?(response) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/aitch/redirect.rb', line 16

def follow?(response)
  enabled? && response.redirect? && tries < max_tries
end

#followed!Object



12
13
14
# File 'lib/aitch/redirect.rb', line 12

def followed!
  @tries += 1
end

#max_triesObject



20
21
22
# File 'lib/aitch/redirect.rb', line 20

def max_tries
  @options[:redirect_limit]
end