Class: RedirectCheck
- Inherits:
-
Object
- Object
- RedirectCheck
- Defined in:
- lib/traffic_cop/redirect_check.rb
Instance Attribute Summary collapse
-
#destination_path ⇒ Object
readonly
Returns the value of attribute destination_path.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source_path, destination_path = nil) ⇒ RedirectCheck
constructor
A new instance of RedirectCheck.
- #permanent_redirect? ⇒ Boolean
- #redirected? ⇒ Boolean
- #redirected_path ⇒ Object
- #response ⇒ Object
- #success? ⇒ Boolean
- #uri ⇒ Object
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_path ⇒ Object (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_path ⇒ Object (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
.domain ⇒ Object
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
37 38 39 |
# File 'lib/traffic_cop/redirect_check.rb', line 37 def permanent_redirect? redirected? && response.is_a?(Net::HTTPMovedPermanently) end |
#redirected? ⇒ Boolean
33 34 35 |
# File 'lib/traffic_cop/redirect_check.rb', line 33 def redirected? response.is_a?(Net::HTTPRedirection) end |
#redirected_path ⇒ Object
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 |
#response ⇒ Object
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
29 30 31 |
# File 'lib/traffic_cop/redirect_check.rb', line 29 def success? response.is_a?(Net::HTTPOK) end |
#uri ⇒ Object
21 22 23 |
# File 'lib/traffic_cop/redirect_check.rb', line 21 def uri URI.parse("http://#{self.class.domain}#{source_path}") end |