class AttrValidator::Validators::UrlValidator

Constants

URL_REGEXP

Public Class Methods

validate(value, url_flag) click to toggle source

Validates that string is a valid url @param value [String] string to validate @param url [Boolean] should given string be url or not @return [Array] empty array if number is valid, array of error messages otherwise

# File lib/attr_validator/validators/url_validator.rb, line 8
def self.validate(value, url_flag)
  return [] if value.nil?

  errors = []
  if url_flag
    errors << AttrValidator::I18n.t('errors.invalid_url') unless !!URL_REGEXP.match(value)
  else
    errors << AttrValidator::I18n.t('errors.can_not_be_url') if !!URL_REGEXP.match(value)
  end

  errors
end
validate_options(url_flag) click to toggle source
# File lib/attr_validator/validators/url_validator.rb, line 21
def self.validate_options(url_flag)
  AttrValidator::ArgsValidator.is_boolean!(url_flag, :validation_rule)
end