Class: UriFormatValidator::Validators::UriValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UriFormatValidator::Validators::UriValidator
- Defined in:
- lib/uri_format_validator/validators/uri_validator.rb
Overview
TODO: documentation
Constant Summary collapse
- SCHEMES =
%w[ aaa aaas about acap acct cap cid coap coaps crid data dav dict dns example file ftp geo go gopher h323 http https iax icap im imap info ipp ipps iris iris.beep iris.lwz iris.xpc iris.xpcs jabber ldap mailto mid msrp msrps mtqp mupdate news nfs ni nih nntp opaquelocktoken pkcs11 pop pres reload rtsp rtsps rtspu service session shttp sieve sip sips sms snmp soap.beep soap.beeps stun stuns tag tel telnet tftp thismessage tip tn3270 turn turns tv urn vemmi vnc ws wss xcon xcon-userid xmlrpc.beep xmlrpc.beeps xmpp z39.50r z39.50s ].freeze
- RESERVED_DOMAINS =
Examples: www.rubular.com/r/Xy4iNY2ztf
%r{ (\.(test|example|invalid|localhost)$)| ((^|\.)example\.(...?)(\...)?$) }x
Instance Method Summary collapse
-
#initialize(options) ⇒ UriValidator
constructor
A new instance of UriValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ UriValidator
Returns a new instance of UriValidator.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/uri_format_validator/validators/uri_validator.rb', line 33 def initialize() @schemes = case [:scheme] when :all then SCHEMES when nil then %w[http https] else [:scheme] end [:message] ||= I18n.t("errors.messages.invalid_uri") super() end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/uri_format_validator/validators/uri_validator.rb', line 45 def validate_each(record, attribute, value) success = catch(STOP_VALIDATION) do do_checks(value.to_s) true end success || (record, attribute) end |