Class: Loca::URL::Validator
- Inherits:
-
Object
- Object
- Loca::URL::Validator
- Includes:
- Loca::Utils
- Defined in:
- lib/loca/url/validator.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ Validator
constructor
A new instance of Validator.
- #validate ⇒ Object
Methods included from Loca::Utils
Constructor Details
#initialize(url) ⇒ Validator
Returns a new instance of Validator.
6 7 8 9 10 |
# File 'lib/loca/url/validator.rb', line 6 def initialize(url) @url = url @uri = Addressable::URI.parse(@url) @segments = @uri.path.split("/").reject(&:empty?) end |
Instance Method Details
#validate ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/loca/url/validator.rb', line 12 def validate return if valid_host? && valid_user_and_repo_segments? && valid_pull_segment? && valid_pull_number? fail Loca::Error::InvalidURL, <<-MSG Not a GitHub PR URL: #{@url} Examples of valid URLs: - https://github.com/smoll/loca/pull/1337 - https://github.com/smoll/loca/pull/1337/commits - https://github.com/smoll/loca/pull/1337/files MSG end |