Class: ConvenientService::Examples::Standard::V1::RequestParams::Utils::URL::Valid
- Inherits:
-
Command
- Object
- ConvenientService::Examples::Standard::V1::RequestParams::Utils::URL::Valid
- Defined in:
- lib/convenient_service/examples/standard/v1/request_params/utils/url/valid.rb
Overview
TODO: Use to validate URLs.
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#call ⇒ Object
NOTE: How to validate URLs? - https://storck.io/posts/better-http-url-validation-in-ruby-on-rails - https://github.com/sporkmonger/addressable/issues/1452.
-
#initialize(url) ⇒ Valid
constructor
A new instance of Valid.
Constructor Details
#initialize(url) ⇒ Valid
Returns a new instance of Valid.
19 20 21 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/url/valid.rb', line 19 def initialize(url) @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
17 18 19 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/url/valid.rb', line 17 def url @url end |
Instance Method Details
#call ⇒ Object
NOTE: How to validate URLs?
- https://storck.io/posts/better-http-url-validation-in-ruby-on-rails
- https://github.com/sporkmonger/addressable/issues/1452
NOTE: URL is NOT URI.
NOTE: Why NOT to match URI::regexp
?
35 36 37 38 39 40 41 |
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/url/valid.rb', line 35 def call uri = ::URI.parse(url.to_s) uri.is_a?(::URI::HTTPS) || uri.is_a?(::URI::HTTP) rescue ::URI::InvalidURIError false end |