validators 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a52bd8c6c0154e31767455e8a2e1037c6e6a8c2e
4
- data.tar.gz: 22b34fe94029f994f37a2d8165ec377567d16c3b
3
+ metadata.gz: c8b6da51895c47e9292d6a9f3e69e1344f048b9e
4
+ data.tar.gz: 00ce9db1e34727a6e1dd45d0c1664555a75de332
5
5
  SHA512:
6
- metadata.gz: 2468097e60de4e9296bbe3271ce78390f303b73252a5982e32e2af084fe34b9d49b63f2b0dacc19e6a5edd33870456efeb8730a1e3bed48ef30bdaa86646f7b1
7
- data.tar.gz: 1213ca2a3b9472dbf599d005de080dc62b158ec416e09a18bd46855063120541116d24ffa3d9abacf22f07715821527e8e2683c358f149a832808ced8d2c1a1f
6
+ metadata.gz: a95bfe1cd0d18157e457c349e47712b486980c75dfb31caf92e7a7ec7ee45bfe824807a35b0acdcc682c6bf3ad821153d4789cda1fe59224df9deba13528f3c2
7
+ data.tar.gz: d0d92d572381475e0c252bdafe45f3fc2f71c9cf98d5d553081ef9be9027ba8a251a14ca2298655d6584bca98afec13320ae574fc1ffee902fbceb424726c4c2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validators (2.4.1)
4
+ validators (2.4.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,6 +1,7 @@
1
1
  module Validators
2
2
  require "validators/constants"
3
3
  require "validators/ip"
4
+ require "validators/tld"
4
5
  require "validators/validates_datetime"
5
6
  require "validators/validates_ip_address"
6
7
  require "validators/validates_email_format_of"
@@ -0,0 +1,18 @@
1
+ module Validators
2
+ class TLD
3
+ TLD_FILE_PATH = File.expand_path('../../../data/tld.txt', __FILE__)
4
+
5
+ def self.all
6
+ @tld ||= File.read(TLD_FILE_PATH).lines.map(&:chomp)
7
+ end
8
+
9
+ def self.host_with_valid_tld?(host)
10
+ return false if host.split('.').size == 1
11
+ valid? host[/\.([^.]+)$/, 1].to_s.downcase
12
+ end
13
+
14
+ def self.valid?(tld)
15
+ all.include?(tld)
16
+ end
17
+ end
18
+ end
@@ -38,10 +38,7 @@ module ActiveModel
38
38
 
39
39
  def valid_tld?(host)
40
40
  return true unless options[:tld]
41
- return false if host.split('.').size == 1
42
-
43
- tld = host[/\.(.*?)$/, 1].to_s.downcase
44
- UrlValidator.tlds.include?(tld)
41
+ Validators::TLD.host_with_valid_tld?(host)
45
42
  end
46
43
  end
47
44
 
@@ -1,12 +1,6 @@
1
1
  module ActiveModel
2
2
  module Validations
3
3
  class UrlValidator < EachValidator
4
- TLD_FILE_PATH = File.expand_path('../../../data/tld.txt', __FILE__)
5
-
6
- def self.tlds
7
- @tld ||= File.read(TLD_FILE_PATH).lines.map(&:chomp)
8
- end
9
-
10
4
  def validate_each(record, attribute, value)
11
5
  return if value.blank? && options[:allow_blank]
12
6
  return if value.nil? && options[:allow_nil]
@@ -32,9 +26,7 @@ module ActiveModel
32
26
 
33
27
  def valid_tld?(host)
34
28
  return true unless options[:tld]
35
- tld = host[/\.(.*?)$/, 1].to_s.downcase
36
-
37
- self.class.tlds.include?(tld)
29
+ Validators::TLD.host_with_valid_tld?(host)
38
30
  end
39
31
  end
40
32
 
@@ -2,7 +2,7 @@ module Validators
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 4
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -7,7 +7,7 @@ require "validators"
7
7
  require "active_support/all"
8
8
 
9
9
  Time.zone = "America/Sao_Paulo"
10
- TLDs = ActiveModel::Validations::UrlValidator.tlds.sample(100)
10
+ TLDs = Validators::TLD.all.sample(100)
11
11
 
12
12
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
13
13
 
@@ -18,6 +18,11 @@ describe ".validates_hostname_format_of" do
18
18
  expect(server).to be_valid
19
19
  end
20
20
  end
21
+
22
+ it "accepts example.com.br" do
23
+ server = ServerWithTLD.new("example.com.br")
24
+ expect(server).to be_valid
25
+ end
21
26
  end
22
27
 
23
28
  context "without TLD validation" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -140,6 +140,7 @@ files:
140
140
  - lib/validators.rb
141
141
  - lib/validators/constants.rb
142
142
  - lib/validators/ip.rb
143
+ - lib/validators/tld.rb
143
144
  - lib/validators/validates_cnpj_format_of.rb
144
145
  - lib/validators/validates_cpf_format_of.rb
145
146
  - lib/validators/validates_datetime.rb