Sha256: 3305fd4e77a94600d2f12494698b2d9122930d10864dd76dcd1ea47af907bd83

Contents?: true

Size: 432 Bytes

Versions: 7

Compression:

Stored size: 432 Bytes

Contents

# frozen_string_literal: true

require 'addressable'

module EacRailsUtils
  class UriValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      r = ::Addressable::URI.parse(value)
      raise ::Addressable::URI::InvalidURIError, 'No scheme' if r.scheme.blank?
    rescue ::Addressable::URI::InvalidURIError => e
      record.errors.add(attribute, options[:message] || e.message)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/validators/eac_rails_utils/uri_validator.rb
eac_rails_utils-0.24.0 app/validators/eac_rails_utils/uri_validator.rb
eac_rails_utils-0.23.4 app/validators/eac_rails_utils/uri_validator.rb
eac_rails_utils-0.23.3 app/validators/eac_rails_utils/uri_validator.rb
eac_rails_utils-0.23.2 app/validators/eac_rails_utils/uri_validator.rb
eac_rails_utils-0.23.1 app/validators/eac_rails_utils/uri_validator.rb
eac_rails_utils-0.23.0 app/validators/eac_rails_utils/uri_validator.rb