class Mova::Storage::Memory
Thin wrapper around Hash.
@note This class was designed to be not thread-safe for the sake of
speed. However, if you store translations in static YAML files and do not write to the storage during application runtime, this is not a big deal. If you need thread-safe in-memory implemenation, use {http://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html ActiveSupport::Cache::MemoryStore}. Also note that with any in-memory implementation you'll have a copy of all translations data in each spawned worker. Depending on number of your locales, translation keys and workers, it may take up a lot of memory. This is the fastest storage though.
@since 0.1.0
Public Class Methods
new()
click to toggle source
# File lib/mova/storage/memory.rb, line 20 def initialize @storage = {} end
Public Instance Methods
clear()
click to toggle source
@return [void]
# File lib/mova/storage/memory.rb, line 57 def clear @storage.clear end
exist?(key)
click to toggle source
@return [Boolean] @param key [String]
# File lib/mova/storage/memory.rb, line 52 def exist?(key) @storage.key?(key) end
inspect()
click to toggle source
@private
# File lib/mova/storage/memory.rb, line 62 def inspect "<##{self.class.name}>" end
read(key)
click to toggle source
@return [String, nil] @param key [String]
# File lib/mova/storage/memory.rb, line 26 def read(key) @storage[key] end
read_multi(*keys)
click to toggle source
@return [Hash] @param keys [*Array<String>] @example
storage.write("foo", "bar") storage.write("baz", "qux") storage.read_multi("foo", "baz") #=> {"foo" => "bar", "baz" => "qux"}
# File lib/mova/storage/memory.rb, line 36 def read_multi(*keys) keys.each_with_object({}) do |key, memo| result = read(key) memo[key] = result if result end end
write(key, value)
click to toggle source
@return [void] @param key [String] @param value [String, nil]
# File lib/mova/storage/memory.rb, line 46 def write(key, value) @storage[key] = value end