Module: ActiveRecord::Validations::ClassMethods
- Defined in:
- lib/gettext/active_record.rb
Overview
:nodoc:
Constant Summary collapse
- @@custom_error_messages_d =
{}
Instance Method Summary collapse
-
#_validates_parse_custom_messages(*attrs) ⇒ Object
:nodoc:.
-
#custom_error_messages_d ⇒ Object
:nodoc:.
-
#validates_exclusion_of_with_gettext(*attrs) ⇒ Object
:nodoc:.
-
#validates_format_of_with_gettext(*attrs) ⇒ Object
:nodoc:.
-
#validates_inclusion_of_with_gettext(*attrs) ⇒ Object
:nodoc:.
-
#validates_length_of_with_gettext(*attrs) ⇒ Object
Very ugly but…
Instance Method Details
#_validates_parse_custom_messages(*attrs) ⇒ Object
:nodoc:
110 111 112 113 114 115 116 117 118 |
# File 'lib/gettext/active_record.rb', line 110 def (*attrs) #:nodoc: if attrs.last.is_a?(Hash) and attrs.last[:message] msg = attrs.last[:message] key = msg.dup msg.sub!(/%\{val\}/, '%s') @@custom_error_messages_d[key] = /\A#{Regexp.escape(msg).sub('%s', '(.*)')}\Z/ end attrs end |
#custom_error_messages_d ⇒ Object
:nodoc:
138 139 140 |
# File 'lib/gettext/active_record.rb', line 138 def #:nodoc: @@custom_error_messages_d end |
#validates_exclusion_of_with_gettext(*attrs) ⇒ Object
:nodoc:
132 133 134 135 |
# File 'lib/gettext/active_record.rb', line 132 def validates_exclusion_of_with_gettext(*attrs) #:nodoc: attrs = (*attrs) validates_exclusion_of_without_gettext(*attrs) end |
#validates_format_of_with_gettext(*attrs) ⇒ Object
:nodoc:
120 121 122 123 |
# File 'lib/gettext/active_record.rb', line 120 def validates_format_of_with_gettext(*attrs) #:nodoc: attrs = (*attrs) validates_format_of_without_gettext(*attrs) end |
#validates_inclusion_of_with_gettext(*attrs) ⇒ Object
:nodoc:
126 127 128 129 |
# File 'lib/gettext/active_record.rb', line 126 def validates_inclusion_of_with_gettext(*attrs) #:nodoc: attrs = (*attrs) validates_inclusion_of_without_gettext(*attrs) end |
#validates_length_of_with_gettext(*attrs) ⇒ Object
Very ugly but…
99 100 101 102 103 104 105 106 107 |
# File 'lib/gettext/active_record.rb', line 99 def validates_length_of_with_gettext(*attrs) #:nodoc: if attrs.last.is_a?(Hash) [:message, :too_long, :too_short, :wrong_length].each do |msg_sym| msg = attrs.last[msg_sym] @@custom_error_messages_d[msg] = /\A#{Regexp.escape(msg).sub(/%d/, '(\d+)')}\Z/ if msg end end validates_size_of(*attrs) end |