Class: RedirectCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/traffic_cop/redirect_check.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path, destination_path = nil) ⇒ RedirectCheck

Returns a new instance of RedirectCheck.



16
17
18
19
# File 'lib/traffic_cop/redirect_check.rb', line 16

def initialize(source_path, destination_path = nil)
  @source_path      = source_path.to_s
  @destination_path = destination_path.to_s
end

Instance Attribute Details

#destination_pathObject (readonly)

Returns the value of attribute destination_path.



14
15
16
# File 'lib/traffic_cop/redirect_check.rb', line 14

def destination_path
  @destination_path
end

#source_pathObject (readonly)

Returns the value of attribute source_path.



14
15
16
# File 'lib/traffic_cop/redirect_check.rb', line 14

def source_path
  @source_path
end

Class Method Details

.domainObject



10
11
12
# File 'lib/traffic_cop/redirect_check.rb', line 10

def self.domain
  @domain
end

.domain=(domain) ⇒ Object



6
7
8
# File 'lib/traffic_cop/redirect_check.rb', line 6

def self.domain=(domain)
  @domain = domain
end

Instance Method Details

#permanent_redirect?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/traffic_cop/redirect_check.rb', line 37

def permanent_redirect?
  redirected? && response.is_a?(Net::HTTPMovedPermanently)
end

#redirected?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/traffic_cop/redirect_check.rb', line 33

def redirected?
  response.is_a?(Net::HTTPRedirection)
end

#redirected_pathObject



41
42
43
# File 'lib/traffic_cop/redirect_check.rb', line 41

def redirected_path
  response['location'].sub(/#{Regexp.escape("#{uri.scheme}://#{uri.host}")}/, '') if redirected?
end

#responseObject



25
26
27
# File 'lib/traffic_cop/redirect_check.rb', line 25

def response
  @response ||= Net::HTTP.start(uri.host, uri.port) {|http| http.head(uri.path) }
end

#success?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/traffic_cop/redirect_check.rb', line 29

def success?
  response.is_a?(Net::HTTPOK)
end

#uriObject



21
22
23
# File 'lib/traffic_cop/redirect_check.rb', line 21

def uri
  URI.parse("http://#{self.class.domain}#{source_path}")
end