Module: FormInput::Parameter::LocaleMethods
- Included in:
- FormInput::Parameter
- Defined in:
- lib/form_input/core.rb
Overview
Methods affected by localization, put in separate module for easier overloading.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Get value of arbitrary option.
-
#format_error_message(msg, count = nil, singular = nil, plural = "#{singular}s") ⇒ Object
Format the error report message.
-
#report(msg, *args) ⇒ Object
Report an error concerning this parameter.
Instance Method Details
#[](name) ⇒ Object
Get value of arbitrary option. Automatically resolves call blocks.
321 322 323 324 325 |
# File 'lib/form_input/core.rb', line 321 def []( name ) o = opts[ name ] o = instance_exec( &o ) if o.is_a?( Proc ) o end |
#format_error_message(msg, count = nil, singular = nil, plural = "#{singular}s") ⇒ Object
Format the error report message. Default implementation includes simple pluralizer. String %p in the message is automatically replaced with error title. Can be redefined to provide correctly localized error messages.
330 331 332 333 334 335 |
# File 'lib/form_input/core.rb', line 330 def ( msg, count = nil, singular = nil, plural = "#{singular}s" ) msg = DEFAULT_ERROR_MESSAGES[ msg ] || msg.to_s msg += " #{count}" if count msg += " #{ count == 1 ? singular : plural }" if singular msg.gsub( '%p', error_title ) end |
#report(msg, *args) ⇒ Object
Report an error concerning this parameter. String %p in the message is automatically replaced with error title. Returns self for chaining.
340 341 342 343 |
# File 'lib/form_input/core.rb', line 340 def report( msg, *args ) form.report( name, ( msg, *args ) ) if form self end |