validation_hints 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/active_model/hints.rb +24 -13
- data/lib/validation_hints/locale/en.yml +22 -17
- data/lib/validation_hints/version.rb +1 -1
- metadata +2 -2
data/lib/active_model/hints.rb
CHANGED
@@ -43,21 +43,32 @@ module ActiveModel
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def validation_hints_for(attribute)
|
46
|
+
result = Array.new
|
46
47
|
@base.class.validators_on(attribute).map do |v|
|
48
|
+
puts "** ** ** ** V " + v.class.to_s.split('::').last.downcase.gsub('validator','')
|
49
|
+
# check for validators that have no options
|
47
50
|
validator = v.class.to_s.split('::').last.downcase.gsub('validator','')
|
48
51
|
if MESSAGES_FOR_VALIDATORS.include?(validator)
|
49
|
-
|
52
|
+
result << generate_message(attribute, validator)
|
50
53
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
v.options.each do |o|
|
55
|
+
puts "** ** ** ** O " + o.inspect
|
56
|
+
if MESSAGES_FOR_OPTIONS.include?(o.first.to_s)
|
57
|
+
result << generate_message(attribute, [ validator, o.first.to_s ].join('.'), { :count => o.last } )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# key = v.class.to_s.underscore.gsub('/','.')
|
63
|
+
# puts "************#{v.inspect}"
|
64
|
+
# key = [v.qualifier, key].join('.') if v.respond_to?(:qualifier)
|
65
|
+
# [ key, v.options.except(*CALLBACKS_OPTIONS).keys.map do |o|
|
66
|
+
# key + "." + o.to_s
|
67
|
+
# end ].flatten
|
68
|
+
result
|
58
69
|
end
|
59
70
|
|
60
|
-
def
|
71
|
+
def generate_message(attribute, type, options = {})
|
61
72
|
|
62
73
|
if @base.class.respond_to?(:i18n_scope)
|
63
74
|
defaults = @base.class.lookup_ancestors.map do |klass|
|
@@ -75,16 +86,16 @@ module ActiveModel
|
|
75
86
|
defaults.compact!
|
76
87
|
defaults.flatten!
|
77
88
|
|
78
|
-
|
89
|
+
key = defaults.shift
|
79
90
|
|
80
91
|
options = {
|
81
92
|
:default => defaults,
|
82
93
|
:model => @base.class.model_name.human,
|
83
94
|
:attribute => @base.class.human_attribute_name(attribute),
|
84
|
-
}
|
95
|
+
}.merge(options)
|
85
96
|
puts "*" + File.basename(__FILE__) + ": " + "ATTR #{attribute}, OPTIONS #{options.inspect} "
|
86
|
-
|
87
|
-
|
97
|
+
# [ key, options ]
|
98
|
+
I18n.translate(key, options)
|
88
99
|
end
|
89
100
|
|
90
101
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
## YAML Template.
|
2
2
|
---
|
3
3
|
en:
|
4
|
-
|
4
|
+
activerecord:
|
5
|
+
less_than_or_equal_to: "must be less than or equal to %{count}"
|
6
|
+
hints:
|
5
7
|
# The default format to use in full error messages.
|
6
8
|
format: "%{attribute} %{message}"
|
7
9
|
|
@@ -10,20 +12,23 @@ en:
|
|
10
12
|
messages:
|
11
13
|
inclusion: "is not included in the list"
|
12
14
|
exclusion: "is reserved"
|
13
|
-
|
15
|
+
format: "what's this"
|
16
|
+
associated: "is invalid"
|
17
|
+
uniqueness: "must be unique"
|
14
18
|
confirmation: "doesn't match confirmation"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
acceptence: "must be accepted"
|
20
|
+
presence: "can't be blank"
|
21
|
+
length:
|
22
|
+
maximum: "must not be longer than %{count} characters"
|
23
|
+
minimum: "must not be shorter than %{count} characters"
|
24
|
+
wrong_length: "must be exactly %{count} characters"
|
25
|
+
numericality: "not a number"
|
26
|
+
numericality:
|
27
|
+
not_an_integer: "must be an integer"
|
28
|
+
greater_than: "must be greater than %{count}"
|
29
|
+
greater_than_or_equal_to: "must be greater than or equal to %{count}"
|
30
|
+
equal_to: "must be equal to %{count}"
|
31
|
+
less_than: "must be less than %{count}"
|
32
|
+
less_than_or_equal_to: "must be less than or equal to %{count}"
|
33
|
+
odd: "must be odd"
|
34
|
+
even: "must be even"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_hints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rvm
|