validators 3.1.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/README.md +20 -5
  4. data/bin/sync-disposable-hostnames +208 -23
  5. data/bin/sync-tld +11 -8
  6. data/data/country_tlds.json +237 -0
  7. data/data/disposable.json +42 -60317
  8. data/data/disposable/10minutemail.json +3 -0
  9. data/data/disposable/1secmail.json +5 -0
  10. data/data/disposable/FGRibreau_mailchecker.json +33602 -0
  11. data/data/disposable/andreis_disposable_email_domains.json +48320 -0
  12. data/data/disposable/clipmails.json +27 -0
  13. data/data/disposable/cs.json +15 -0
  14. data/data/disposable/emailfake.json +128 -0
  15. data/data/disposable/fake_email_generator.json +11 -0
  16. data/data/disposable/fnando_dafe542cac13f831bbf5521a55248116.json +20 -0
  17. data/data/disposable/gmailnator.json +3 -0
  18. data/data/disposable/guerrillamail.json +13 -0
  19. data/data/disposable/ically.json +28 -0
  20. data/data/disposable/itemp.json +4 -0
  21. data/data/disposable/ivolo_disposable_email_domains.json +48177 -0
  22. data/data/disposable/jespernissen_disposable_maildomain_list.json +2372 -0
  23. data/data/disposable/maxmalysh_disposable_emails.json +21372 -0
  24. data/data/disposable/moakt.json +12 -0
  25. data/data/disposable/receivemail.json +9 -0
  26. data/data/disposable/sneakykiwi_LeagueCreatorPublic.json +2364 -0
  27. data/data/disposable/tempemail.json +7 -0
  28. data/data/disposable/tempemails.json +10 -0
  29. data/data/disposable/tempmail.json +31 -0
  30. data/data/disposable/tempmail_io.json +8 -0
  31. data/data/disposable/tempmailaddress.json +4 -0
  32. data/data/disposable/tempomail.json +3 -0
  33. data/data/disposable/tempr.json +97 -0
  34. data/data/disposable/tmail.json +3 -0
  35. data/data/disposable/wesbos_burner_email_providers.json +4711 -0
  36. data/data/disposable/willwhite_freemail.json +352 -0
  37. data/data/disposable/yepmail.json +12 -0
  38. data/data/disposable_emails.json +3 -0
  39. data/data/disposable_patterns.json +3 -0
  40. data/data/disposable_raw.json +128 -0
  41. data/data/{reserved_hostnames.json → reserved_subdomains.json} +2 -0
  42. data/data/sld.json +5564 -0
  43. data/data/tld.json +2 -0
  44. data/lib/validators.rb +3 -3
  45. data/lib/validators/locale/en.yml +3 -1
  46. data/lib/validators/{reserved_hostnames.rb → reserved_subdomains.rb} +2 -2
  47. data/lib/validators/validates_subdomain.rb +67 -0
  48. data/lib/validators/validates_username.rb +15 -0
  49. data/lib/validators/version.rb +2 -2
  50. data/test/validators/validates_subdomain_test.rb +63 -0
  51. data/test/validators/{validates_reserved_username_test.rb → validates_username_test.rb} +27 -4
  52. data/validators.gemspec +6 -1
  53. metadata +87 -10
  54. data/lib/validators/validates_reserved_hostname.rb +0 -45
  55. data/lib/validators/validates_reserved_username.rb +0 -29
  56. data/test/validators/validates_reserved_hostname_test.rb +0 -40
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveModel
4
- module Validations
5
- class ReservedHostnameValidator < EachValidator
6
- def validate_each(record, attribute, value)
7
- return if value.blank? && options[:allow_blank]
8
- return if value.nil? && options[:allow_nil]
9
- return unless reserved?(value.to_s)
10
-
11
- record.errors.add(
12
- attribute,
13
- :"reserved_#{options[:error_name]}",
14
- message: options[:message],
15
- value: value
16
- )
17
- end
18
-
19
- def reserved?(subdomain)
20
- ::Validators::ReservedHostnames.reserved?(subdomain, options[:in])
21
- end
22
- end
23
-
24
- module ClassMethods
25
- # Validates whether or not the specified hostname is valid.
26
- # The `in: array` can have strings and patterns. A pattern is everything
27
- # that starts with `/` and will be parsed as a regular expression.
28
- #
29
- # Notice that subdomains will be normalized; it'll be downcased and have
30
- # its underscores and hyphens stripped.
31
- #
32
- # class User < ActiveRecord::Base
33
- # validates_reserved_hostname :site
34
- #
35
- # # Validates against a custom list.
36
- # validates_reserved_hostname :site, in: %w[www]
37
- # end
38
- #
39
- def validates_reserved_hostname(*attr_names)
40
- options = _merge_attributes(attr_names).merge(error_name: :hostname)
41
- validates_with ReservedHostnameValidator, options
42
- end
43
- end
44
- end
45
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveModel
4
- module Validations
5
- class ReservedUsernameValidator < ReservedHostnameValidator
6
- end
7
-
8
- module ClassMethods
9
- # Validates whether or not the specified username is valid.
10
- # The `in: array` can have strings and patterns. A pattern is everything
11
- # that starts with `/` and will be parsed as a regular expression.
12
- #
13
- # Notice that subdomains will be normalized; it'll be downcased and have
14
- # its underscores and hyphens stripped.
15
- #
16
- # class User < ActiveRecord::Base
17
- # validates_reserved_hostname :site
18
- #
19
- # # Validates against a custom list.
20
- # validates_reserved_hostname :site, in: %w[www]
21
- # end
22
- #
23
- def validates_reserved_username(*attr_names)
24
- options = _merge_attributes(attr_names).merge(error_name: :username)
25
- validates_with ReservedHostnameValidator, options
26
- end
27
- end
28
- end
29
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ValidatesReservedHostnameTest < Minitest::Test
6
- test "rejects reserved hostname" do
7
- model = build_model do
8
- attr_accessor :hostname
9
- validates_reserved_hostname :hostname
10
- end
11
-
12
- instance = model.new(hostname: "www")
13
-
14
- refute instance.valid?
15
- assert_includes instance.errors[:hostname],
16
- "www is a reserved hostname"
17
- end
18
-
19
- test "rejects reserved hostname with pattern" do
20
- model = build_model do
21
- attr_accessor :hostname
22
- validates_reserved_hostname :hostname
23
- end
24
-
25
- instance = model.new(hostname: "www1234")
26
-
27
- refute instance.valid?
28
- end
29
-
30
- test "uses custom list" do
31
- model = build_model do
32
- attr_accessor :hostname
33
- validates_reserved_hostname :hostname, in: %w[nope]
34
- end
35
-
36
- instance = model.new(hostname: "nope")
37
-
38
- refute instance.valid?
39
- end
40
- end