Class: NDD::UrlChecker::Status
- Inherits:
-
Object
- Object
- NDD::UrlChecker::Status
- Defined in:
- lib/ndd/url_checker/status.rb
Overview
The result of a URI test.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
the state.
-
#error ⇒ String, StandardError
readonly
the last error if any.
-
#uris ⇒ Array<String>
readonly
the list of requested URI.
Instance Method Summary collapse
-
#direct ⇒ self
When the URI is valid without any redirect.
-
#failed(error) ⇒ self
When a generic error is raised.
-
#initialize(uri) ⇒ Status
constructor
Creates a new instance in the :unknown state.
-
#invalid? ⇒ Boolean
Note that the :unknown code is neither valid nor invalid.
-
#redirected(uri) ⇒ self
Adds a new URI to the redirected URI list.
-
#redirected? ⇒ Boolean
True if redirected, false otherwise.
-
#to_s ⇒ Object
Returns the status representation.
-
#too_many_redirects ⇒ self
When there are too many redirects.
-
#unknown_host ⇒ self
When the host cannot be resolved.
-
#uri ⇒ String
The first requested URI.
-
#valid? ⇒ Boolean
Note that the :unknown code is neither valid nor invalid.
Constructor Details
#initialize(uri) ⇒ Status
Creates a new instance in the :unknown state.
17 18 19 20 |
# File 'lib/ndd/url_checker/status.rb', line 17 def initialize(uri) @uris = [uri.to_s] @code = :unknown end |
Instance Attribute Details
#code ⇒ String (readonly)
the state
9 10 11 |
# File 'lib/ndd/url_checker/status.rb', line 9 def code @code end |
#error ⇒ String, StandardError (readonly)
the last error if any
9 10 11 |
# File 'lib/ndd/url_checker/status.rb', line 9 def error @error end |
#uris ⇒ Array<String> (readonly)
the list of requested URI
9 10 11 |
# File 'lib/ndd/url_checker/status.rb', line 9 def uris @uris end |
Instance Method Details
#direct ⇒ self
When the URI is valid without any redirect.
47 48 49 |
# File 'lib/ndd/url_checker/status.rb', line 47 def direct update_code(:direct, %i(unknown)) end |
#failed(error) ⇒ self
When a generic error is raised.
54 55 56 57 |
# File 'lib/ndd/url_checker/status.rb', line 54 def failed(error) @error = error update_code(:failed, %i(unknown redirected)) end |
#invalid? ⇒ Boolean
Note that the :unknown code is neither valid nor invalid.
35 36 37 |
# File 'lib/ndd/url_checker/status.rb', line 35 def invalid? INVALID_CODES.include? @code end |
#redirected(uri) ⇒ self
Adds a new URI to the redirected URI list.
62 63 64 65 |
# File 'lib/ndd/url_checker/status.rb', line 62 def redirected(uri) @uris << uri.to_s update_code(:redirected, %i(unknown redirected)) end |
#redirected? ⇒ Boolean
Returns true if redirected, false otherwise.
40 41 42 |
# File 'lib/ndd/url_checker/status.rb', line 40 def redirected? @code == :redirected end |
#to_s ⇒ Object
Returns the status representation
80 81 82 |
# File 'lib/ndd/url_checker/status.rb', line 80 def to_s self.inspect end |
#too_many_redirects ⇒ self
When there are too many redirects.
69 70 71 |
# File 'lib/ndd/url_checker/status.rb', line 69 def too_many_redirects update_code(:too_many_redirects, %i(unknown redirected)) end |
#unknown_host ⇒ self
When the host cannot be resolved.
75 76 77 |
# File 'lib/ndd/url_checker/status.rb', line 75 def unknown_host update_code(:unknown_host, %i(unknown redirected)) end |
#uri ⇒ String
Returns the first requested URI.
23 24 25 |
# File 'lib/ndd/url_checker/status.rb', line 23 def uri uris.first end |
#valid? ⇒ Boolean
Note that the :unknown code is neither valid nor invalid.
29 30 31 |
# File 'lib/ndd/url_checker/status.rb', line 29 def valid? VALID_CODES.include? @code end |