validation_hints 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,8 @@ module ActiveModel
12
12
 
13
13
  CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank, :strict]
14
14
  MESSAGES_FOR_VALIDATORS = %w(confirmation acceptance presence uniqueness format associated numericality)
15
+ VALIDATORS_WITHOUT_MAIN_KEYS = %w(exclusion format inclusion length numericality)
16
+ # and these? validates_with validates_each
15
17
  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
18
  OPTIONS_THAT_WE_DONT_USE_YET = {
17
19
  :acceptance => :acceptance
@@ -44,15 +46,14 @@ module ActiveModel
44
46
  def hints_for(attribute)
45
47
  result = Array.new
46
48
  @base.class.validators_on(attribute).map do |v|
47
- # check for validators that have no options
48
- validator = v.class.to_s.split('::').last.downcase.gsub('validator','')
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
49
+ validator = v.class.to_s.split('::').last.underscore.gsub('_validator','')
52
50
  if v.options[:message].is_a?(Symbol)
51
+ message_key = [validator, v.options[:message]].join('.') # if a message was supplied as a symbol, we use it instead
53
52
  result << generate_message(attribute, message_key, v.options)
54
53
  else
55
- result << generate_message(attribute, message_key, v.options) if MESSAGES_FOR_VALIDATORS.include?(validator)
54
+ message_key = validator
55
+ 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
56
+ result << generate_message(attribute, message_key, v.options) unless VALIDATORS_WITHOUT_MAIN_KEYS.include?(validator)
56
57
  v.options.each do |o|
57
58
  if MESSAGES_FOR_OPTIONS.include?(o.first.to_s)
58
59
  count = o.last
@@ -10,6 +10,7 @@ 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
+ is_a_curacao_id_number: 'hello world!'
13
14
  inclusion:
14
15
  in: "must be one of %{count}"
15
16
  exclusion:
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module ValidationHints
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: