Class: PublicUrlValidator

Inherits:
AddressableUrlValidator show all
Defined in:
app/validators/public_url_validator.rb

Overview

PublicUrlValidator

Custom validator for URLs. This validator works like AddressableUrlValidator but it blocks by default urls pointing to localhost or the local network.

This validator accepts the same params UrlValidator does.

Example:

class User < ActiveRecord::Base
  validates :personal_url, public_url: true

  validates :ftp_url, public_url: { schemes: %w(ftp) }

  validates :git_url, public_url: { allow_localhost: true, allow_local_network: true}
end

Direct Known Subclasses

SystemHookUrlValidator

Constant Summary collapse

DEFAULT_OPTIONS =
{
  allow_localhost: false,
  allow_local_network: false
}.freeze

Constants inherited from AddressableUrlValidator

AddressableUrlValidator::BLOCKER_VALIDATE_OPTIONS

Instance Attribute Summary

Attributes inherited from AddressableUrlValidator

#record

Instance Method Summary collapse

Methods inherited from AddressableUrlValidator

#validate_each

Constructor Details

#initialize(options) ⇒ PublicUrlValidator

Returns a new instance of PublicUrlValidator.



26
27
28
29
30
# File 'app/validators/public_url_validator.rb', line 26

def initialize(options)
  options.reverse_merge!(DEFAULT_OPTIONS)

  super(options)
end