class Traject::TranslationMap::Cache
Public Class Methods
new()
click to toggle source
# File lib/traject/translation_map.rb, line 108 def initialize @cached = Hash.new end
Public Instance Methods
_lookup!(path)
click to toggle source
force lookup, without using cache. used by cache. Returns the actual hash. Returns nil if none found. May raise on syntax error in file being loaded.
# File lib/traject/translation_map.rb, line 124 def _lookup!(path) found = nil $LOAD_PATH.each do |base| rb_file = File.join( base, "translation_maps", "#{path}.rb" ) yaml_file = File.join( base, "translation_maps", "#{path}.yaml" ) prop_file = File.join(base, "translation_maps", "#{path}.properties" ) if File.exist? rb_file found = eval( File.open(rb_file).read , binding, rb_file ) break elsif File.exist? yaml_file found = YAML.load_file(yaml_file) break elsif File.exist? prop_file found = Traject::TranslationMap.read_properties(prop_file) break end end # Cached hash can't be mutated without weird consequences, let's # freeze it! found.freeze if found return found end
lookup(path)
click to toggle source
Returns an actual Hash – or nil if none found.
# File lib/traject/translation_map.rb, line 113 def lookup(path) unless @cached.has_key?(path) @cached[path] = _lookup!(path) end return @cached[path] end
reset_cache!()
click to toggle source
# File lib/traject/translation_map.rb, line 151 def reset_cache! @cached.clear end