validation_kit 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/validation_kit/email_validator/email_validator.rb +3 -2
- data/lib/validation_kit/mixed_case_validator/mixed_case_validator.rb +7 -5
- data/lib/validation_kit/phone_validator/phone_validator.rb +5 -3
- data/lib/validation_kit/postal_code_validator/postal_code_validator.rb +5 -3
- data/lib/validation_kit/version.rb +1 -1
- metadata +2 -2
@@ -9,8 +9,9 @@ module ValidationKit
|
|
9
9
|
|
10
10
|
def validate_each(record, attribute, value)
|
11
11
|
unless EMAIL_ADDRESS_RE.match(value)
|
12
|
-
|
13
|
-
|
12
|
+
model_name = record.class.to_s
|
13
|
+
message = I18n.t("activerecord.errors.models.#{model_name.underscore}.attributes.#{attribute}.invalid",
|
14
|
+
:default => [:"activerecord.errors.models.#{model_name.underscore}.invalid",
|
14
15
|
options[:message],
|
15
16
|
:'activerecord.errors.messages.invalid'])
|
16
17
|
record.errors[attribute] << message
|
@@ -16,19 +16,21 @@ module ValidationKit
|
|
16
16
|
|
17
17
|
return if error.nil?
|
18
18
|
|
19
|
-
|
19
|
+
model_name = record.class.to_s
|
20
|
+
|
21
|
+
item_name = I18n.t("activerecord.models.attributes.#{model_name.underscore}.#{attribute}",
|
20
22
|
:default => nil) or options[:attribute_name] or attribute
|
21
23
|
|
22
24
|
if error == ALL_CAPS
|
23
|
-
message = I18n.t("activerecord.errors.models.attributes.#{
|
25
|
+
message = I18n.t("activerecord.errors.models.attributes.#{model_name.underscore}.#{attribute}.all_caps",
|
24
26
|
:item => item_name,
|
25
|
-
:default => [:"activerecord.errors.models.#{
|
27
|
+
:default => [:"activerecord.errors.models.#{model_name.underscore}.all_caps",
|
26
28
|
options[:all_caps],
|
27
29
|
:'activerecord.errors.messages.all_caps'])
|
28
30
|
elsif error == ALL_LOWERCASE
|
29
|
-
message = I18n.t("activerecord.errors.models.attributes.#{
|
31
|
+
message = I18n.t("activerecord.errors.models.attributes.#{model_name.underscore}.#{attributes}.all_lowercase",
|
30
32
|
:item => item_name,
|
31
|
-
:default => [:"activerecord.errors.models.#{
|
33
|
+
:default => [:"activerecord.errors.models.#{model_name.underscore}.all_lowercase",
|
32
34
|
options[:all_lowercase],
|
33
35
|
:'activerecord.errors.messages.all_lowercase'])
|
34
36
|
end
|
@@ -30,8 +30,10 @@ module ValidationKit
|
|
30
30
|
new_value = value.to_s.gsub(/[^0-9]/, '')
|
31
31
|
new_value ||= ''
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
model_name = record.class.to_s
|
34
|
+
|
35
|
+
message = I18n.t("activerecord.errors.models.#{model_name.underscore}.attributes.#{attribute}.invalid",
|
36
|
+
:default => [:"activerecord.errors.models.#{model_name.underscore}.invalid",
|
35
37
|
options[:message], :'activerecord.errors.messages.invalid'])
|
36
38
|
|
37
39
|
unless (options[:allow_blank] && new_value.blank?) || new_value =~ current_regex
|
@@ -42,7 +44,7 @@ module ValidationKit
|
|
42
44
|
if formatted_phone.nil?
|
43
45
|
record.errors[attribute] << message
|
44
46
|
else
|
45
|
-
record.send(
|
47
|
+
record.send(attribute.to_s + '=', formatted_phone)
|
46
48
|
end
|
47
49
|
end # options
|
48
50
|
end # unless
|
@@ -44,14 +44,16 @@ module ValidationKit
|
|
44
44
|
|
45
45
|
new_value = value.nil? ? "" : value.upcase.gsub(disallowed_characters, '')
|
46
46
|
|
47
|
+
model_name = record.class.to_s
|
48
|
+
|
47
49
|
unless (options[:allow_blank] && new_value.blank?) || new_value =~ current_regex
|
48
|
-
message = I18n.t("activerecord.errors.models.#{
|
49
|
-
:default => [:"activerecord.errors.models.#{
|
50
|
+
message = I18n.t("activerecord.errors.models.#{model_name.underscore}.attributes.#{attribute}.invalid",
|
51
|
+
:default => [:"activerecord.errors.models.#{model_name.underscore}.invalid",
|
50
52
|
options[:message],
|
51
53
|
:'activerecord.errors.messages.invalid'])
|
52
54
|
record.errors[attribute] << message
|
53
55
|
else
|
54
|
-
record.send(
|
56
|
+
record.send(attribute.to_s + '=',
|
55
57
|
format_as_postal_code(new_value, country, disallowed_characters)
|
56
58
|
) if options[:set]
|
57
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: A collection of various validators for Rails forms
|
16
16
|
email:
|