lib/i18n/js/middleware.rb in i18n-js-3.0.0.rc5 vs lib/i18n/js/middleware.rb in i18n-js-3.0.0.rc6
- old
+ new
@@ -11,23 +11,34 @@
@app.call(env)
end
private
def cache_path
- @cache_path ||= Rails.root.join("tmp/cache/i18n-js.yml")
+ @cache_path ||= cache_dir.join("i18n-js.yml")
end
+ def cache_dir
+ @cache_dir ||= Rails.root.join("tmp/cache")
+ end
+
def cache
@cache ||= begin
if cache_path.exist?
YAML.load_file(cache_path) || {}
else
{}
end
end
end
+ def save_cache(new_cache)
+ FileUtils.mkdir_p(cache_dir)
+ File.open(cache_path, "w+") do |file|
+ file << new_cache.to_yaml
+ end
+ end
+
# Check if translations should be regenerated.
# ONLY REGENERATE when these conditions are met:
#
# # Cache file doesn't exist
# # Translations and cache size are different (files were removed/added)
@@ -46,12 +57,10 @@
new_cache[path] = changed_at
end
return if valid_cache.all?
- File.open(cache_path, "w+") do |file|
- file << new_cache.to_yaml
- end
+ save_cache(new_cache)
::I18n::JS.export
end
end
end