validation_hints 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- generate_keys(attribute, validator)
52
+ result << generate_message(attribute, validator)
50
53
  end
51
- end.flatten.compact
52
- # key = v.class.to_s.underscore.gsub('/','.')
53
- # puts "************#{v.inspect}"
54
- # key = [v.qualifier, key].join('.') if v.respond_to?(:qualifier)
55
- # [ key, v.options.except(*CALLBACKS_OPTIONS).keys.map do |o|
56
- # key + "." + o.to_s
57
- # end ].flatten
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 generate_keys(attribute, type)
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
- #key = defaults.shift
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
- #I18n.translate(key, options)
87
- [ defaults, options ]
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
- errors:
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
- invalid: "is invalid"
15
+ format: "what's this"
16
+ associated: "is invalid"
17
+ uniqueness: "must be unique"
14
18
  confirmation: "doesn't match confirmation"
15
- accepted: "must be accepted"
16
- empty: "can't be empty"
17
- blank: "can't be blank"
18
- too_long: "is too long (maximum is %{count} characters)"
19
- too_short: "is too kort (minimum is %{count} characters)"
20
- wrong_length: "is the wrong length (should be %{count} characters)"
21
- not_a_number: "is not a number"
22
- not_an_integer: "must be an integer"
23
- greater_than: "must be greater than %{count}"
24
- greater_than_or_equal_to: "must be greater than or equal to %{count}"
25
- equal_to: "must be equal to %{count}"
26
- less_than: "must be less than %{count}"
27
- less_than_or_equal_to: "must be less than or equal to %{count}"
28
- odd: "must be odd"
29
- even: "must be even"
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"
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ValidationHints
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
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.5
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-18 00:00:00.000000000 Z
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rvm