Class: I18n::Inflector::InflectionOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n-inflector-rails/options.rb

Overview

This module adds options to InflectionOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auto_helperObject

When this is set to true then each time infleciton method is registered it becomes a helper method so it’s available in a view.

This switch is by default set to true.

Setting this switch locally, for the specified translation call, using :inflector_auto_helper option will have no effect.

Examples:

Globally disabling automatic setting of helpers

I18n.inflector.options.auto_helper = false


54
55
56
# File 'lib/i18n-inflector-rails/options.rb', line 54

def auto_helper
  @auto_helper
end

#lazy_methodsObject

When this is set to true then each time an infleciton method is used to obtain value for the associated kind it evaluates lazy. That means the method object is passed to the translation routines and it is evaluated when there is a need. If this is set to false then evaluation takes place before calling Inflector’s translation method and inflection options are passed as symbols, not as method objects.

This switch is by default set to true. By disabling it you may experience some negative performance impact when many inflection methods are registered. That is because the lazy evaluation causes calling only those methods that are needed by internal interpolation routines of the Inflector. For instance, if in some pattern only the kind “gender” is used then there is no need to call inflection methods for other kinds. When lazy evaluation is disabled then all inflection methods have to be called before passing control to translation routines, since this plug-in does not analyze contents of inflection patterns or keys.

Alternatively you can turn this off locally, for the specified translation call, by setting :inflector_lazy_methods option to false.

Examples:

Globally disabling lazy evaluation of kinds

I18n.inflector.options.lazy_methods = false

Locally disabling lazy evaluation of kinds

translate('welcome', :inflector_lazy_methods => false)


88
89
90
# File 'lib/i18n-inflector-rails/options.rb', line 88

def lazy_methods
  @lazy_methods
end

#verify_methodsObject

When this is set to true then inflection works a bit slower but checks whether any method exists before calling it.

This switch is by default set to false.

By turning this switch on you’re sure that there will be no NameError (no method) exception raised during translation.

Alternatively you can turn this on locally, for the specified translation call, by setting :inflector_verify_methods option to true.

Examples:

Globally enabling methods verification

I18n.inflector.options.verify_methods = true

Locally enabling methods verification

translate('welcome', :inflector_verify_methods => true)


37
38
39
# File 'lib/i18n-inflector-rails/options.rb', line 37

def verify_methods
  @verify_methods
end

Instance Method Details

#resetObject

This method resets inflector’s switches to default values.



95
96
97
98
99
100
# File 'lib/i18n-inflector-rails/options.rb', line 95

def reset
  @verify_methods = false
  @auto_helper    = true
  @lazy_methods   = true
  _rai_orig_reset
end