Sha256: 1530cbf0c190d28bf11cee82511bb4e0d21e8a66f176857058f7ec9ccdd2307b

Contents?: true

Size: 426 Bytes

Versions: 1

Compression:

Stored size: 426 Bytes

Contents

class UrlFormatValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless URI.parse(attribute).kind_of?(URI::HTTP)
      url_format_invalid(record, attribute, value)
    end
  rescue URI::InvalidURIError
    url_format_invalid(record, attribute, value)
  end

  def url_format_invalid(record, attribute, value)
    record.errors[attribute] << (options[:message] || "is invalid")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
url_format-0.0.2 lib/url_format/url_format_validator.rb