Class: HitCounter::UrlValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- HitCounter::UrlValidator
- Defined in:
- lib/hit_counter.rb
Overview
Validates the HitCounter
‘s URL.
If the URI library can parse the value and the scheme is valid, then we assume the url is valid.
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/hit_counter.rb', line 27 def validate_each(record, attribute, value) uri = Addressable::URI.parse value raise Addressable::URI::InvalidURIError unless %w[http https].include?( uri.scheme ) rescue Addressable::URI::InvalidURIError record.errors.add attribute, 'Invalid URL' end |