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.
-
#report!(msg, *args) ⇒ Object
Report an error concerning this parameter.
Instance Method Details
#[](name) ⇒ Object
Get value of arbitrary option. Automatically resolves call blocks.
334 335 336 337 338 |
# File 'lib/form_input/core.rb', line 334 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.
343 344 345 346 347 348 |
# File 'lib/form_input/core.rb', line 343 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. In case of multiple errors, the message is added to the end of the list, making it less important than the other errors. Returns self for chaining.
354 355 356 357 |
# File 'lib/form_input/core.rb', line 354 def report( msg, *args ) form.report( name, ( msg, *args ) ) if form self end |
#report!(msg, *args) ⇒ Object
Report an error concerning this parameter. String %p in the message is automatically replaced with error title. In case of multiple errors, the message is added to the beginning of the list, making it more important than the other errors. Returns self for chaining.
363 364 365 366 |
# File 'lib/form_input/core.rb', line 363 def report!( msg, *args ) form.report!( name, ( msg, *args ) ) if form self end |