2009-12-09 13:03:04 -05:00
|
|
|
module SimpleForm
|
2009-12-09 13:20:17 -05:00
|
|
|
# A lot of configuration values are retrived from I18n,
|
2009-12-09 13:03:04 -05:00
|
|
|
# like boolean collection, required string. This module provides
|
2009-12-09 13:20:17 -05:00
|
|
|
# caching facility to speed up form construction.
|
2009-12-09 13:03:04 -05:00
|
|
|
module I18nCache
|
|
|
|
def i18n_cache(key)
|
|
|
|
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
|
|
|
end
|
2009-12-09 13:20:17 -05:00
|
|
|
|
2009-12-09 13:03:04 -05:00
|
|
|
def get_i18n_cache(key)
|
2010-01-09 08:34:52 -05:00
|
|
|
if class_variable_defined?(:"@@#{key}")
|
|
|
|
class_variable_get(:"@@#{key}")
|
|
|
|
else
|
|
|
|
reset_i18n_cache(key)
|
|
|
|
end
|
2009-12-09 13:03:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_i18n_cache(key)
|
2010-01-09 08:34:52 -05:00
|
|
|
class_variable_set(:"@@#{key}", {})
|
2009-12-09 13:03:04 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-09 13:20:17 -05:00
|
|
|
end
|