Sha256: 28e07dec17bb345530735e43fe5bb40ac9b3e28099276a89ee333759bb38fc2f

Contents?: true

Size: 587 Bytes

Versions: 2

Compression:

Stored size: 587 Bytes

Contents

module SimpleFormWithClientValidation
  # A lot of configuration values are retrived from I18n,
  # like boolean collection, required string. This module provides
  # caching facility to speed up form construction.
  module I18nCache
    def i18n_cache(key)
      get_i18n_cache(key)[I18n.locale] ||= yield.freeze
    end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_form_with_client_validation-0.0.2 lib/simple_form_with_client_validation/i18n_cache.rb
simple_form_with_client_validation-0.0.0 lib/simple_form_with_client_validation/i18n_cache.rb