module Lit
A middleware that ensures the lit thread value is cleared after the last part of the body is rendered. This is useful when using streaming.j
Uses Rack::BodyProxy, adapted from Rack::Lock's usage of the same pattern.
Constants
- VERSION
Attributes
loader[RW]
Public Class Methods
check_if_table_exists()
click to toggle source
# File lib/lit.rb, line 53 def self.check_if_table_exists Lit::Locale.table_exists? rescue ActiveRecord::ActiveRecordError => e log_txt = "An #{e.class} error has been raised during Lit initialization. " \ "Lit assumes that database tables do not exist.\n\n" \ "Error: #{e.message}\n\n" \ "Backtrace:\n" \ "#{e.backtrace.join("\n")}" Logger.new(STDOUT).error(log_txt) if ::Rails.env.test? # ensure this is logged to stdout in test ::Rails.logger.error(log_txt) false end
fallback=(_value)
click to toggle source
# File lib/lit.rb, line 78 def self.fallback=(_value) ::Rails.logger.error "[DEPRECATION] Lit.fallback= has been deprecated, please use `config.i18n.fallbacks` instead" end
get_key_value_engine()
click to toggle source
# File lib/lit.rb, line 67 def self.get_key_value_engine case Lit.key_value_engine when 'redis' require 'lit/adapters/redis_storage' return RedisStorage.new else require 'lit/adapters/hash_storage' return HashStorage.new end end
init()
click to toggle source
# File lib/lit.rb, line 27 def self.init @@table_exists ||= check_if_table_exists if loader.nil? && @@table_exists self.loader ||= Loader.new Lit.humanize_key = false if Lit.humanize_key.nil? Lit.humanize_key_ignored_keys = [] if Lit.humanize_key_ignored_keys.nil? Lit.humanize_key_ignored = %w[i18n date datetime number time support ] Lit.humanize_key_ignored |= Lit.humanize_key_ignored_keys Lit.humanize_key_ignored = Regexp.new("(#{Lit.humanize_key_ignored.join('|')}).*") Lit.ignore_yaml_on_startup = true if Lit.ignore_yaml_on_startup.nil? Lit.ignored_keys = Lit.ignored_keys.split(',').map(&:strip) if Lit.ignored_keys.is_a?(String) Lit.ignored_keys = [] unless Lit.ignored_keys.is_a?(Array) Lit.ignored_keys = Lit.ignored_keys.map(&:freeze).freeze Lit.hits_counter_enabled = false if Lit.hits_counter_enabled.nil? Lit.store_request_info = false if Lit.store_request_info.nil? Lit.store_request_keys = false if Lit.store_request_keys.nil? # if loading all translations on start, migrations have to be already # performed, fails on first deploy # self.loader.cache.load_all_translations Lit.storage_options ||= {} end self.loader end
Public Instance Methods
determine_redis_provider()
click to toggle source
# File lib/lit/adapters/redis_storage.rb, line 12 def determine_redis_provider Lit.redis_url || ENV[ENV['REDIS_PROVIDER'] || 'REDIS_URL'] end
redis()
click to toggle source
# File lib/lit/adapters/redis_storage.rb, line 6 def redis $redis ||= nil $redis = Redis.new(url: determine_redis_provider) unless $redis $redis end