Class: I18n::Backend::Http

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/i18n/backend/http.rb,
lib/i18n/backend/http/version.rb,
lib/i18n/backend/http/lru_cache.rb,
lib/i18n/backend/http/etag_http_client.rb

Defined Under Namespace

Classes: EtagHttpClient, LRUCache

Constant Summary collapse

FAILED_GET =
{}.freeze
STATS_NAMESPACE =
'i18n-backend-http'.freeze
ALLOWED_STATS =
Set[:download_fail, :open_retry, :read_retry].freeze
VERSION =
Version = "0.3.4"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Http

Returns a new instance of Http.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/i18n/backend/http.rb', line 17

def initialize(options)
  @options = {
    http_open_timeout: 1,
    http_read_timeout: 1,
    http_open_retries: 0,
    http_read_retries: 0,
    polling_interval: 10*60,
    cache: nil,
    poll: true,
    exception_handler: -> (e) { $stderr.puts e },
    memory_cache_size: 10,
  }.merge(options)

  @http_client = EtagHttpClient.new(@options)
  @translations = LRUCache.new(@options[:memory_cache_size])
  start_polling if @options[:poll]
end

Instance Method Details

#available_localesObject



35
36
37
# File 'lib/i18n/backend/http.rb', line 35

def available_locales
  @translations.keys.map(&:to_sym).select { |l| l != :i18n }
end

#stop_pollingObject



39
40
41
# File 'lib/i18n/backend/http.rb', line 39

def stop_polling
  @stop_polling = true
end