Sha256: 9a1f1790d0476673e62aafdd2bd03663d17bd70c8a65fee5a1ccea5742f81792

Contents?: true

Size: 700 Bytes

Versions: 2

Compression:

Stored size: 700 Bytes

Contents

module FastGettext
  module Storage
    [:text_domain,:available_locales,:text_domains].each do |method|
      define_method method do
        thread_store(method)
      end
      define_method "#{method}=" do |value|
        write_thread_store(method,value)
      end
    end

    def locale
      thread_store(:locale) || (available_locales||[]).first || 'en'
    end

    def locale=(value)
      write_thread_store(:locale,value) if not available_locales or available_locales.include?(value)
    end

    private

    def thread_store(key)
      Thread.current["FastGettext.#{key}"]
    end

    def write_thread_store(key,value)
      Thread.current["FastGettext.#{key}"]=value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grosser-fast_gettext-0.2.0 lib/fast_gettext/storage.rb
grosser-fast_gettext-0.2.1 lib/fast_gettext/storage.rb