Sha256: 1e3fc60a39b4c28bf8cba8f7bfd0935158ad78db6b03803819f2e727154183ab

Contents?: true

Size: 423 Bytes

Versions: 1

Compression:

Stored size: 423 Bytes

Contents

class UrlFormatValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless URI.parse(record).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.1 lib/url_format/url_format_validator.rb