heartcombo--simple_form/lib/simple_form/i18n_cache.rb

18 lines
500 B
Ruby
Raw Normal View History

2009-12-09 18:03:04 +00:00
module SimpleForm
# A lot of configuration valeus are retrived from I18n,
# like boolean collection, required string. This module provides
# caching facility to speed up form construciton.
module I18nCache
def i18n_cache(key)
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
end
def get_i18n_cache(key)
instance_variable_get(:"@#{key}") || reset_i18n_cache(key)
end
def reset_i18n_cache(key)
instance_variable_set(:"@#{key}", {})
end
end
end