Sha256: d03bfb72b3b7fb6243e87dc5777378f44e9d05b13b1d02b4d5f05574a6bce6d9

Contents?: true

Size: 354 Bytes

Versions: 54

Compression:

Stored size: 354 Bytes

Contents

class UrlValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    if value =~ /\Ahttps?:\/\/[^\n]+\z/i
      url = ::Addressable::URI.parse(value)
      unless ['http', 'https'].include?(url.scheme)
        record.errors.add(attribute.to_sym)
      end
    else
      record.errors.add(attribute.to_sym)
    end
  end
end

Version data entries

54 entries across 52 versions & 2 rubygems

Version Path
enju_library-0.3.11 app/models/url_validator.rb
enju_library-0.3.10 app/models/url_validator.rb
enju_library-0.3.9 app/models/url_validator.rb
enju_library-0.3.8 app/models/url_validator.rb
enju_library-0.3.8.rc.2 app/models/url_validator.rb
enju_library-0.3.8.rc.1 app/models/url_validator.rb
enju_library-0.4.0.rc.1 app/models/url_validator.rb
enju_library-0.3.7 app/models/url_validator.rb
enju_library-0.3.6 app/models/url_validator.rb
enju_library-0.4.0.beta.4 app/models/url_validator.rb
enju_library-0.4.0.beta.3 app/models/url_validator.rb
enju_library-0.4.0.beta.2 app/models/url_validator.rb
enju_library-0.4.0.beta.1 app/models/url_validator.rb
enju_library-0.3.5 app/models/url_validator.rb
enju_library-0.3.4 app/models/url_validator.rb
enju_library-0.3.3 app/models/url_validator.rb
enju_library-0.3.2 app/models/url_validator.rb
enju_library-0.3.1 app/models/url_validator.rb
enju_library-0.3.0 app/models/url_validator.rb
enju_library-0.3.0.rc.1 app/models/url_validator.rb