validation_hints 0.1.1 → 0.1.2
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
CHANGED
@@ -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
|
-
|
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
|
-
|
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:
|