Module: Riddick::Backends

Defined in:
lib/riddick/backends.rb,
lib/riddick/backends/redis.rb,
lib/riddick/backends/simple.rb,
lib/riddick/backends/key_value.rb,
lib/riddick/backends/redis/value.rb,
lib/riddick/backends/key_value/value.rb

Overview

Main interface for the server to interoperate with I18n the backends.

Defined Under Namespace

Classes: KeyValue, Redis, Simple

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.chainObject

Returns the chain. By default it’s I18n.backend (which is assumed to be a I18n::Backend::Chain).



22
23
24
# File 'lib/riddick/backends.rb', line 22

def chain
  @chain ||= I18n.backend
end

.key_valueObject

Return a Riddick::Backends::Redis wrapped around a I18n::Backend::KeyValue. It iterates over the backends in the chain and takes the first one found of required type.



16
17
18
19
# File 'lib/riddick/backends.rb', line 16

def key_value
  @key_value ||= Riddick::Backends::Redis.new(
      chain.backends.find { |be| be.kind_of? I18n::Backend::KeyValue })
end

.simpleObject

Return a Riddick::Backends::Simple wrapped around a I18n::Backend::Simple. It iterates over the backends in the chain and takes the first one found of required type.



9
10
11
12
# File 'lib/riddick/backends.rb', line 9

def simple
  @simple ||= Riddick::Backends::Simple.new(
      chain.backends.find { |be| be.kind_of? I18n::Backend::Simple })
end

Class Method Details

.delete_translation(key) ⇒ Object

Deletes a translation from the key-value backend.



33
34
35
# File 'lib/riddick/backends.rb', line 33

def delete_translation(key)
  key_value.delete_translation key
end

.store_translation(key, value) ⇒ Object

Stores a translation in the chain.



27
28
29
30
# File 'lib/riddick/backends.rb', line 27

def store_translation(key, value)
  locale, *parts = key.split '.'
  chain.store_translations locale, {parts.join('.') => value}, escape: false
end