Class: UrlValidator

Inherits:
Validaty::AllowBlankBase show all
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 options[:domain].present? && URI.parse(value).host != options[:domain]
    resource.errors.add(attribute, :domain, domain: options[:domain])
  end

  if options[:starts_with].present? && !value.to_s.starts_with?(options[:starts_with])
    resource.errors.add(attribute, :starts_with, start: options[:starts_with])
  end

  super
end