lib/twitter_cldr/tokenizers/base.rb in twitter_cldr-2.0.2 vs lib/twitter_cldr/tokenizers/base.rb in twitter_cldr-2.1.0
- old
+ new
@@ -52,14 +52,13 @@
def tokens_for(path, additional_cache_key_params = [])
tokens_for_pattern(pattern_for(traverse(path)), path, additional_cache_key_params)
end
def tokens_for_pattern(pattern, path, additional_cache_key_params = [])
- @@token_cache ||= {}
cache_key = TwitterCldr::Utils.compute_cache_key(@locale, path.join('.'), type, format || "nil", *additional_cache_key_params)
- unless @@token_cache.include?(cache_key)
+ unless token_cache.include?(cache_key)
result = []
tokens = expand_pattern(pattern)
tokens.each do |token|
if token.is_a?(Token) || token.is_a?(CompositeToken)
@@ -67,36 +66,32 @@
else
result += tokenize_format(token[:value])
end
end
- @@token_cache[cache_key] = result
+ token_cache[cache_key] = result
end
- @@token_cache[cache_key]
+ token_cache[cache_key]
end
def tokens_with_placeholders_for(key)
- @@token_cache ||= {}
- cache_key = compute_cache_key(@locale, key, type)
+ cache_key = TwitterCldr::Utils.compute_cache_key(@locale, key, type)
- unless @@token_cache.include?(cache_key)
+ unless token_cache.include?(cache_key)
result = []
tokens = tokenize_pattern(pattern_for(traverse(key)))
tokens.each do |token|
result << token
end
- @@token_cache[cache_key] = result
+ token_cache[cache_key] = result
end
- @@token_cache[cache_key]
+
+ token_cache[cache_key]
end
- def compute_cache_key(*pieces)
- if pieces && pieces.size > 0
- pieces.join("|").hash
- else
- 0
- end
+ def token_cache
+ @@token_cache ||= {}
end
def init_placeholders
@placeholders = {}
end