validators 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +9 -17
- data/bin/sync-disposable-hostnames +1 -1
- data/data/disposable.json +2975 -68
- data/data/tld.json +16 -6
- data/lib/validators.rb +1 -1
- data/lib/validators/constants.rb +1 -1
- data/lib/validators/hostname.rb +26 -0
- data/lib/validators/tld.rb +1 -1
- data/lib/validators/validates_email_format_of.rb +18 -2
- data/lib/validators/validates_hostname_format_of.rb +6 -32
- data/lib/validators/version.rb +1 -1
- data/test/support/emails.rb +1 -2
- data/test/support/models.rb +5 -5
- data/test/support/translations.yml +1 -0
- data/test/validators/validates_email_format_of_test.rb +12 -5
- data/validators.gemspec +2 -2
- metadata +7 -11
- data/lib/validators/validates_subdomain_format_of.rb +0 -38
- data/test/support/subdomains.rb +0 -18
- data/test/validators/validates_subdomain_test.rb +0 -17
@@ -1,38 +0,0 @@
|
|
1
|
-
module ActiveModel
|
2
|
-
module Validations
|
3
|
-
class SubdomainValidator < EachValidator
|
4
|
-
# Rules taken from http://www.zytrax.com/books/dns/apa/names.html
|
5
|
-
def validate_each(record, attribute, value)
|
6
|
-
return if value.blank? && options[:allow_blank]
|
7
|
-
return if value.nil? && options[:allow_nil]
|
8
|
-
return if valid_label?(value.to_s)
|
9
|
-
|
10
|
-
record.errors.add(attribute, :invalid_subdomain,
|
11
|
-
message: options[:message],
|
12
|
-
value: value
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
def valid_label?(label)
|
17
|
-
!label.start_with?("-") &&
|
18
|
-
!label.match(/\A\d+\z/) &&
|
19
|
-
label.match(/\A[a-z0-9-]{1,63}\z/i)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module ClassMethods
|
24
|
-
# Validates whether or not the specified URL is valid.
|
25
|
-
#
|
26
|
-
# class User < ActiveRecord::Base
|
27
|
-
# validates_subdomain_format_of :subdomain
|
28
|
-
# validates_subdomain :subdomain
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
def validates_subdomain_format_of(*attr_names)
|
32
|
-
validates_with SubdomainValidator, _merge_attributes(attr_names)
|
33
|
-
end
|
34
|
-
|
35
|
-
alias_method :validates_subdomain, :validates_subdomain_format_of
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/test/support/subdomains.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ValidatesSubdomainTest < Minitest::Test
|
4
|
-
VALID_SUBDOMAINS.each do |subdomain|
|
5
|
-
test "accepts #{subdomain}" do
|
6
|
-
site = Site.new(subdomain)
|
7
|
-
assert site.valid?
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
INVALID_SUBDOMAINS.each do |subdomain|
|
12
|
-
test "rejects #{subdomain}" do
|
13
|
-
site = Site.new(subdomain)
|
14
|
-
refute site.valid?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|