Class: RedirectCheck
- Inherits:
-
Object
- Object
- RedirectCheck
- Defined in:
- lib/http_redirect_test/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.
Instance Method Summary collapse
- #gone? ⇒ Boolean
- #header(name) ⇒ Object
-
#initialize(domain, source_path, destination_path = nil) ⇒ RedirectCheck
constructor
A new instance of RedirectCheck.
- #not_found? ⇒ Boolean
- #permanent_redirect? ⇒ Boolean
- #redirected? ⇒ Boolean
- #redirected_path ⇒ Object
- #response ⇒ Object
- #source_uri ⇒ Object
- #success? ⇒ Boolean
- #uri ⇒ Object
Constructor Details
#initialize(domain, source_path, destination_path = nil) ⇒ RedirectCheck
Returns a new instance of RedirectCheck.
7 8 9 10 11 |
# File 'lib/http_redirect_test/redirect_check.rb', line 7 def initialize(domain, source_path, destination_path = nil) @domain = domain @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.
5 6 7 |
# File 'lib/http_redirect_test/redirect_check.rb', line 5 def destination_path @destination_path end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
5 6 7 |
# File 'lib/http_redirect_test/redirect_check.rb', line 5 def source_path @source_path end |
Instance Method Details
#gone? ⇒ Boolean
31 32 33 |
# File 'lib/http_redirect_test/redirect_check.rb', line 31 def gone? response.is_a?(Net::HTTPGone) end |
#header(name) ⇒ Object
51 52 53 |
# File 'lib/http_redirect_test/redirect_check.rb', line 51 def header(name) response[name] end |
#not_found? ⇒ Boolean
35 36 37 |
# File 'lib/http_redirect_test/redirect_check.rb', line 35 def not_found? response.is_a?(Net::HTTPNotFound) end |
#permanent_redirect? ⇒ Boolean
43 44 45 |
# File 'lib/http_redirect_test/redirect_check.rb', line 43 def permanent_redirect? redirected? && response.is_a?(Net::HTTPMovedPermanently) end |
#redirected? ⇒ Boolean
39 40 41 |
# File 'lib/http_redirect_test/redirect_check.rb', line 39 def redirected? response.is_a?(Net::HTTPRedirection) end |
#redirected_path ⇒ Object
47 48 49 |
# File 'lib/http_redirect_test/redirect_check.rb', line 47 def redirected_path response['location'].sub(/#{Regexp.escape("#{uri.scheme}://#{uri.host}")}:#{uri.port}/, '') if redirected? end |
#response ⇒ Object
21 22 23 24 25 |
# File 'lib/http_redirect_test/redirect_check.rb', line 21 def response @response ||= Net::HTTP.start(uri.host, uri.port, use_ssl: ssl?) do |http| return http.head(source_uri) end end |
#source_uri ⇒ Object
17 18 19 |
# File 'lib/http_redirect_test/redirect_check.rb', line 17 def source_uri @source_uri ||= (uri.query.nil?) ? uri.path : uri.path + "?" + uri.query end |
#success? ⇒ Boolean
27 28 29 |
# File 'lib/http_redirect_test/redirect_check.rb', line 27 def success? response.is_a?(Net::HTTPOK) end |
#uri ⇒ Object
13 14 15 |
# File 'lib/http_redirect_test/redirect_check.rb', line 13 def uri URI.parse("#{scheme}://#{raw_domain}#{source_path}") end |