validation_hints 0.1.0 → 0.1.1

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.
@@ -11,8 +11,18 @@ module ActiveModel
11
11
  include Enumerable
12
12
 
13
13
  CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank, :strict]
14
- MESSAGES_FOR_VALIDATORS = %w(confirmation acceptance presence uniqueness format inclusion exclusion associated numericality)
15
- MESSAGES_FOR_OPTIONS = %w(within in is minimum maximum greater_than greater_than_or_equal_to equal_to less_than less_than_or_equal_to odd even)
14
+ MESSAGES_FOR_VALIDATORS = %w(confirmation acceptance presence uniqueness format associated numericality)
15
+ MESSAGES_FOR_OPTIONS = %w(within in is minimum maximum greater_than greater_than_or_equal_to equal_to less_than less_than_or_equal_to odd even only_integer)
16
+ OPTIONS_THAT_WE_DONT_USE_YET = {
17
+ :acceptance => :acceptance
18
+
19
+ }
20
+ VALIDATORS_THAT_WE_DONT_KNOW_WHAT_TO_DO_WITH = %w(validates_associated)
21
+
22
+ # Should virtual element for
23
+ # validates :email, :confirmation => true
24
+ # validates :email_confirmation, :presence => true
25
+ # also have a hint?
16
26
 
17
27
  attr_reader :messages
18
28
 
@@ -36,12 +46,19 @@ module ActiveModel
36
46
  @base.class.validators_on(attribute).map do |v|
37
47
  # check for validators that have no options
38
48
  validator = v.class.to_s.split('::').last.downcase.gsub('validator','')
39
- if MESSAGES_FOR_VALIDATORS.include?(validator)
40
- result << generate_message(attribute, validator)
41
- end
42
- v.options.each do |o|
43
- if MESSAGES_FOR_OPTIONS.include?(o.first.to_s)
44
- result << generate_message(attribute, [ validator, o.first.to_s ].join('.'), { :count => o.last } )
49
+ message_key = validator
50
+ message_key = [validator, ".must_be_a_number"].join('.') if validator == 'numericality' # create an option for numericality; the way YAML works a key (numericality) with subkeys (greater_than, etc etc) can not have a string itself. So we create a subkey for numericality
51
+ message_key = [validator, v.options[:message]].join('.') if v.options[:message].is_a?(Symbol) # if a message was supplied as a symbol, we use it instead
52
+ if v.options[:message].is_a?(Symbol)
53
+ result << generate_message(attribute, message_key, v.options)
54
+ else
55
+ result << generate_message(attribute, message_key, v.options) if MESSAGES_FOR_VALIDATORS.include?(validator)
56
+ v.options.each do |o|
57
+ if MESSAGES_FOR_OPTIONS.include?(o.first.to_s)
58
+ count = o.last
59
+ count = o.last.to_sentence if %w(inclusion exclusion).include?(validator)
60
+ result << generate_message(attribute, [ validator, o.first.to_s ].join('.'), { :count => count } )
61
+ end
45
62
  end
46
63
  end
47
64
  end
@@ -264,6 +281,7 @@ module ActiveModel
264
281
  end
265
282
 
266
283
  def generate_message(attribute, type, options = {})
284
+ #options.delete(:message) if options[:message].is_a?(Symbol)
267
285
  if @base.class.respond_to?(:i18n_scope)
268
286
  defaults = @base.class.lookup_ancestors.map do |klass|
269
287
  [ :"#{@base.class.i18n_scope}.hints.models.#{klass.model_name.i18n_key}.attributes.#{attribute}.#{type}",
@@ -273,6 +291,7 @@ module ActiveModel
273
291
  defaults = []
274
292
  end
275
293
 
294
+ defaults << options[:message] # defaults << options.delete(:message)
276
295
  defaults << :"#{@base.class.i18n_scope}.hints.messages.#{type}" if @base.class.respond_to?(:i18n_scope)
277
296
  defaults << :"hints.attributes.#{attribute}.#{type}"
278
297
  defaults << :"hints.messages.#{type}"
@@ -10,21 +10,24 @@ en:
10
10
  # The values :model, :attribute and :value are always available for interpolation
11
11
  # The value :count is available when applicable. Can be used for pluralization.
12
12
  messages:
13
- inclusion: "is not included in the list"
14
- exclusion: "is reserved"
13
+ inclusion:
14
+ in: "must be one of %{count}"
15
+ exclusion:
16
+ in: "must not be one of %{count}"
15
17
  format: "what's this"
16
18
  associated: "is invalid"
17
19
  uniqueness: "must be unique"
18
20
  confirmation: "doesn't match confirmation"
19
- acceptence: "must be accepted"
21
+ acceptance: "must be accepted"
20
22
  presence: "can't be blank"
21
23
  length:
22
24
  maximum: "must not be longer than %{count} characters"
23
25
  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"
26
+ is: "must be exactly %{count} characters"
27
+ radiolaria: "must be between %{minimum} and %{maximum} characters"
28
+ numericality:
29
+ must_be_a_number: "must be a number"
30
+ only_integer: "must be an integer"
28
31
  greater_than: "must be greater than %{count}"
29
32
  greater_than_or_equal_to: "must be greater than or equal to %{count}"
30
33
  equal_to: "must be equal to %{count}"
@@ -32,3 +35,4 @@ en:
32
35
  less_than_or_equal_to: "must be less than or equal to %{count}"
33
36
  odd: "must be odd"
34
37
  even: "must be even"
38
+
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ValidationHints
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
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.1.0
4
+ version: 0.1.1
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-19 00:00:00.000000000 Z
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rvm