Module: SimpleForm::I18nCache

Included in:
SimpleForm::Inputs::Base
Defined in:
lib/simple_form/i18n_cache.rb

Overview

A lot of configuration values are retrived from I18n, like boolean collection, required string. This module provides caching facility to speed up form construction.

Instance Method Summary (collapse)

Instance Method Details

- (Object) get_i18n_cache(key)



10
11
12
13
14
15
16
# File 'lib/simple_form/i18n_cache.rb', line 10

def get_i18n_cache(key)
  if class_variable_defined?(:@@#{key}")
    class_variable_get(:@@#{key}")
  else
    reset_i18n_cache(key)
  end
end

- (Object) i18n_cache(key)



6
7
8
# File 'lib/simple_form/i18n_cache.rb', line 6

def i18n_cache(key)
  get_i18n_cache(key)[I18n.locale] ||= yield.freeze
end

- (Object) reset_i18n_cache(key)



18
19
20
# File 'lib/simple_form/i18n_cache.rb', line 18

def reset_i18n_cache(key)
  class_variable_set(:@@#{key}", {})
end