Class: PublicUrlValidator
- Inherits:
-
AddressableUrlValidator
- Object
- ActiveModel::EachValidator
- AddressableUrlValidator
- PublicUrlValidator
- 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
Constant Summary collapse
- DEFAULT_OPTIONS =
{ allow_localhost: false, allow_local_network: false }.freeze
Constants inherited from AddressableUrlValidator
AddressableUrlValidator::BLOCKER_VALIDATE_OPTIONS, AddressableUrlValidator::DENY_ALL_REQUESTS_EXCEPT_ALLOWED_DEFAULT
Instance Attribute Summary
Attributes inherited from AddressableUrlValidator
Instance Method Summary collapse
-
#initialize(options) ⇒ PublicUrlValidator
constructor
A new instance of PublicUrlValidator.
Methods inherited from AddressableUrlValidator
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() .reverse_merge!(DEFAULT_OPTIONS) super() end |