active_validation 2.6.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.travis.yml +1 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/active_validation.gemspec +14 -15
- data/bin/console +1 -1
- data/bin/rake +6 -6
- data/bin/setup +1 -1
- data/lib/active_validation/matchers/ensure_valid_alpha_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_alpha_numeric_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_base64_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_boolean_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_coordinate_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_credit_card_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_currency_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_cusip_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_email_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_equality_matcher_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_hex_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_imei_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_ip_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_isbn_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_isin_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_mac_address_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_name_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_password_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_phone_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_sedol_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_slug_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_ssn_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_tracking_number_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_type_format_of.rb +3 -3
- data/lib/active_validation/matchers/ensure_valid_url_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_username_format_of.rb +4 -4
- data/lib/active_validation/matchers/ensure_valid_uuid_format_of.rb +4 -4
- data/lib/active_validation/validators/alpha_numeric_validator.rb +3 -4
- data/lib/active_validation/validators/alpha_validator.rb +3 -4
- data/lib/active_validation/validators/base64_validator.rb +3 -4
- data/lib/active_validation/validators/boolean_validator.rb +4 -4
- data/lib/active_validation/validators/coordinate_validator.rb +11 -12
- data/lib/active_validation/validators/credit_card_validator.rb +31 -39
- data/lib/active_validation/validators/currency_validator.rb +3 -4
- data/lib/active_validation/validators/cusip_validator.rb +7 -9
- data/lib/active_validation/validators/email_validator.rb +5 -5
- data/lib/active_validation/validators/equality_validator.rb +9 -13
- data/lib/active_validation/validators/hex_validator.rb +3 -4
- data/lib/active_validation/validators/imei_validator.rb +6 -8
- data/lib/active_validation/validators/ip_validator.rb +3 -4
- data/lib/active_validation/validators/isbn_validator.rb +8 -8
- data/lib/active_validation/validators/isin_validator.rb +15 -13
- data/lib/active_validation/validators/mac_address_validator.rb +8 -12
- data/lib/active_validation/validators/name_validator.rb +4 -5
- data/lib/active_validation/validators/password_validator.rb +3 -4
- data/lib/active_validation/validators/phone_validator.rb +3 -4
- data/lib/active_validation/validators/sedol_validator.rb +6 -8
- data/lib/active_validation/validators/slug_validator.rb +3 -4
- data/lib/active_validation/validators/ssn_validator.rb +3 -4
- data/lib/active_validation/validators/tracking_number_validator.rb +39 -46
- data/lib/active_validation/validators/type_validator.rb +1 -1
- data/lib/active_validation/validators/url_validator.rb +6 -6
- data/lib/active_validation/validators/username_validator.rb +3 -4
- data/lib/active_validation/validators/uuid_validator.rb +3 -4
- data/lib/active_validation/version.rb +1 -1
- data/lib/active_validation.rb +60 -61
- metadata +3 -17
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require "uri"
|
2
2
|
class UrlValidator < ActiveModel::EachValidator
|
3
3
|
|
4
4
|
def validate_each(record, attribute, value)
|
5
5
|
uri = URI.parse(value.to_s)
|
6
6
|
raise URI::InvalidURIError unless valid?(uri, options)
|
7
7
|
rescue URI::InvalidURIError
|
8
|
-
record.errors[attribute] <<
|
8
|
+
record.errors[attribute] << options.fetch(:message, I18n.t("active_validation.errors.messages.url"))
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
DEFAULT_SCHEMES = [:http, :https]
|
13
|
+
DEFAULT_SCHEMES = [:http, :https]
|
14
14
|
|
15
15
|
def valid_domain?(value, options)
|
16
16
|
value_downcased = value.host.to_s.downcase
|
17
|
-
options.empty? || options.any? { |d| value_downcased.end_with?(".#{d.downcase}"
|
17
|
+
options.empty? || options.any? { |d| value_downcased.end_with?(".#{d.downcase}") }
|
18
18
|
end
|
19
19
|
|
20
20
|
def valid_length?(value)
|
@@ -27,7 +27,7 @@ class UrlValidator < ActiveModel::EachValidator
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def valid_root?(value)
|
30
|
-
[
|
30
|
+
["/", ""].include?(value.path) && value.query.blank? && value.fragment.blank?
|
31
31
|
end
|
32
32
|
|
33
33
|
def valid_uri?(value)
|
@@ -42,4 +42,4 @@ class UrlValidator < ActiveModel::EachValidator
|
|
42
42
|
(options.fetch(:root, false) ? valid_root?(value) : true)
|
43
43
|
end
|
44
44
|
|
45
|
-
end
|
45
|
+
end
|
@@ -2,7 +2,7 @@ class UsernameValidator < ActiveModel::EachValidator
|
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
4
|
unless valid?(value.to_s)
|
5
|
-
record.errors[attribute] <<
|
5
|
+
record.errors[attribute] << options.fetch(:message, I18n.t("active_validation.errors.messages.username"))
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -17,8 +17,7 @@ class UsernameValidator < ActiveModel::EachValidator
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def valid?(value)
|
20
|
-
valid_length?(value) &&
|
21
|
-
valid_format?(value)
|
20
|
+
valid_length?(value) && valid_format?(value)
|
22
21
|
end
|
23
22
|
|
24
|
-
end
|
23
|
+
end
|
@@ -2,7 +2,7 @@ class UuidValidator < ActiveModel::EachValidator
|
|
2
2
|
|
3
3
|
def validate_each(record, attribute, value)
|
4
4
|
unless valid?(value.to_s, options)
|
5
|
-
record.errors[attribute] <<
|
5
|
+
record.errors[attribute] << options.fetch(:message, I18n.t("active_validation.errors.messages.uuid"))
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -26,8 +26,7 @@ class UuidValidator < ActiveModel::EachValidator
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def valid?(value, options)
|
29
|
-
valid_length?(value) &&
|
30
|
-
valid_format?(value, options)
|
29
|
+
valid_length?(value) && valid_format?(value, options)
|
31
30
|
end
|
32
31
|
|
33
|
-
end
|
32
|
+
end
|
data/lib/active_validation.rb
CHANGED
@@ -1,74 +1,73 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require 'active_validation/version'
|
1
|
+
require "active_model"
|
2
|
+
require "active_support"
|
3
|
+
require "active_validation/version"
|
5
4
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
5
|
+
require "active_validation/validators/alpha_validator"
|
6
|
+
require "active_validation/validators/alpha_numeric_validator"
|
7
|
+
require "active_validation/validators/base64_validator"
|
8
|
+
require "active_validation/validators/boolean_validator"
|
9
|
+
require "active_validation/validators/coordinate_validator"
|
10
|
+
require "active_validation/validators/credit_card_validator"
|
11
|
+
require "active_validation/validators/currency_validator"
|
12
|
+
require "active_validation/validators/cusip_validator"
|
13
|
+
require "active_validation/validators/email_validator"
|
14
|
+
require "active_validation/validators/equality_validator"
|
15
|
+
require "active_validation/validators/hex_validator"
|
16
|
+
require "active_validation/validators/imei_validator"
|
17
|
+
require "active_validation/validators/ip_validator"
|
18
|
+
require "active_validation/validators/isbn_validator"
|
19
|
+
require "active_validation/validators/isin_validator"
|
20
|
+
require "active_validation/validators/mac_address_validator"
|
21
|
+
require "active_validation/validators/name_validator"
|
22
|
+
require "active_validation/validators/password_validator"
|
23
|
+
require "active_validation/validators/phone_validator"
|
24
|
+
require "active_validation/validators/sedol_validator"
|
25
|
+
require "active_validation/validators/slug_validator"
|
26
|
+
require "active_validation/validators/ssn_validator"
|
27
|
+
require "active_validation/validators/tracking_number_validator"
|
28
|
+
require "active_validation/validators/type_validator"
|
29
|
+
require "active_validation/validators/url_validator"
|
30
|
+
require "active_validation/validators/username_validator"
|
31
|
+
require "active_validation/validators/uuid_validator"
|
33
32
|
|
34
33
|
if defined?(RSpec)
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
58
|
-
require
|
59
|
-
require
|
60
|
-
require
|
61
|
-
require
|
62
|
-
require
|
34
|
+
require "rspec/matchers"
|
35
|
+
require "active_validation/matchers/ensure_valid_alpha_format_of"
|
36
|
+
require "active_validation/matchers/ensure_valid_alpha_numeric_format_of"
|
37
|
+
require "active_validation/matchers/ensure_valid_base64_format_of"
|
38
|
+
require "active_validation/matchers/ensure_valid_boolean_format_of"
|
39
|
+
require "active_validation/matchers/ensure_valid_coordinate_format_of"
|
40
|
+
require "active_validation/matchers/ensure_valid_credit_card_format_of"
|
41
|
+
require "active_validation/matchers/ensure_valid_currency_format_of"
|
42
|
+
require "active_validation/matchers/ensure_valid_cusip_format_of"
|
43
|
+
require "active_validation/matchers/ensure_valid_email_format_of"
|
44
|
+
require "active_validation/matchers/ensure_valid_equality_matcher_of"
|
45
|
+
require "active_validation/matchers/ensure_valid_hex_format_of"
|
46
|
+
require "active_validation/matchers/ensure_valid_imei_format_of"
|
47
|
+
require "active_validation/matchers/ensure_valid_ip_format_of"
|
48
|
+
require "active_validation/matchers/ensure_valid_isbn_format_of"
|
49
|
+
require "active_validation/matchers/ensure_valid_isin_format_of"
|
50
|
+
require "active_validation/matchers/ensure_valid_mac_address_format_of"
|
51
|
+
require "active_validation/matchers/ensure_valid_name_format_of"
|
52
|
+
require "active_validation/matchers/ensure_valid_password_format_of"
|
53
|
+
require "active_validation/matchers/ensure_valid_phone_format_of"
|
54
|
+
require "active_validation/matchers/ensure_valid_sedol_format_of"
|
55
|
+
require "active_validation/matchers/ensure_valid_slug_format_of"
|
56
|
+
require "active_validation/matchers/ensure_valid_ssn_format_of"
|
57
|
+
require "active_validation/matchers/ensure_valid_tracking_number_format_of"
|
58
|
+
require "active_validation/matchers/ensure_valid_type_format_of"
|
59
|
+
require "active_validation/matchers/ensure_valid_url_format_of"
|
60
|
+
require "active_validation/matchers/ensure_valid_username_format_of"
|
61
|
+
require "active_validation/matchers/ensure_valid_uuid_format_of"
|
63
62
|
end
|
64
63
|
|
65
64
|
if defined?(Rails)
|
66
|
-
require
|
65
|
+
require "rails"
|
67
66
|
|
68
67
|
module ActiveValidation
|
69
68
|
class Railtie < ::Rails::Railtie
|
70
69
|
|
71
|
-
initializer
|
70
|
+
initializer "active_validation" do |app|
|
72
71
|
ActiveValidation::Railtie.instance_eval do
|
73
72
|
[app.config.i18n.available_locales].flatten.each do |locale|
|
74
73
|
(I18n.load_path << path(locale)) if File.file?(path(locale))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: active_object
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,7 +185,7 @@ files:
|
|
199
185
|
- lib/active_validation/validators/username_validator.rb
|
200
186
|
- lib/active_validation/validators/uuid_validator.rb
|
201
187
|
- lib/active_validation/version.rb
|
202
|
-
homepage:
|
188
|
+
homepage: http://drexed.github.io/active_validation
|
203
189
|
licenses:
|
204
190
|
- MIT
|
205
191
|
metadata: {}
|