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.
@@ -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
- message = I18n.t("activerecord.errors.models.#{name.underscore}.attributes.#{attr_name}.invalid",
13
- :default => [:"activerecord.errors.models.#{name.underscore}.invalid",
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
- item_name = I18n.t("activerecord.models.attributes.#{name.underscore}.#{attribute}",
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.#{name.underscore}.#{attr_name}.all_caps",
25
+ message = I18n.t("activerecord.errors.models.attributes.#{model_name.underscore}.#{attribute}.all_caps",
24
26
  :item => item_name,
25
- :default => [:"activerecord.errors.models.#{name.underscore}.all_caps",
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.#{name.underscore}.#{attr_name}.all_lowercase",
31
+ message = I18n.t("activerecord.errors.models.attributes.#{model_name.underscore}.#{attributes}.all_lowercase",
30
32
  :item => item_name,
31
- :default => [:"activerecord.errors.models.#{name.underscore}.all_lowercase",
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
- message = I18n.t("activerecord.errors.models.#{name.underscore}.attributes.#{attr_name}.invalid",
34
- :default => [:"activerecord.errors.models.#{name.underscore}.invalid",
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(attr_name.to_s + '=', formatted_phone)
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.#{name.underscore}.attributes.#{attribute}.invalid",
49
- :default => [:"activerecord.errors.models.#{name.underscore}.invalid",
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(attr_name.to_s + '=',
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
@@ -1,3 +1,3 @@
1
1
  module ValidationKit
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  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.1
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-12 00:00:00.000000000 Z
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: