Class: UrlValidator
- Inherits:
-
Validaty::AllowBlankBase
- Object
- ActiveModel::EachValidator
- Validaty::Base
- Validaty::AllowBlankBase
- UrlValidator
- Defined in:
- lib/validators/url_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(resource, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/validators/url_validator.rb', line 4 def validate_each(resource, attribute, value) if [:domain].present? && URI.parse(value).host != [:domain] resource.errors.add(attribute, :domain, domain: [:domain]) end if [:starts_with].present? && !value.to_s.starts_with?([:starts_with]) resource.errors.add(attribute, :starts_with, start: [:starts_with]) end super end |