Class: Tr8nCore::Generators::Cache::File
- Defined in:
- lib/tr8n_core/generators/cache/file.rb
Overview
– Copyright © 2014 Michael Berkovich, TranslationExchange.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #cache(key, data) ⇒ Object
- #cache_path ⇒ Object
- #cache_translations ⇒ Object
- #execute ⇒ Object
- #file_path(key) ⇒ Object
- #symlink_path ⇒ Object
Methods inherited from Base
#cache_application, #cache_languages, #finalize, #generate_symlink, #log, #prepare, #run
Instance Method Details
#cache(key, data) ⇒ Object
40 41 42 |
# File 'lib/tr8n_core/generators/cache/file.rb', line 40 def cache(key, data) File.open(file_path(key), 'w') { |file| file.write(JSON.pretty_generate(data)) } end |
#cache_path ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/tr8n_core/generators/cache/file.rb', line 26 def cache_path @cache_path ||= begin path = "#{Tr8n.config.cache[:path]}/files/tr8n_#{Tr8n.session.application.key}_#{@started_at.strftime('%Y_%m_%d_%H_%M_%S')}" log("Cache will be stored in #{path}") FileUtils.mkdir_p(path) FileUtils.chmod(0777, path) path end end |
#cache_translations ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tr8n_core/generators/cache/file.rb', line 56 def cache_translations log("Downloading translations...") sources = Tr8n.config.application.get("application/sources") @languages.each do |language| log("--------------------------------------------------------------") log("Downloading #{language["locale"]} language...") log("--------------------------------------------------------------") sources.each do |source| log("Downloading #{source["source"]} in #{language["locale"]}...") translation_keys = Tr8n.session.application.get("source/translations", {:source => source["source"], :locale => language["locale"]}) data = {:source => source["source"], :translation_keys => translation_keys} cache(Tr8n::Source.cache_key(source["source"], language["locale"]), data) end end end |
#execute ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/tr8n_core/generators/cache/file.rb', line 48 def execute Tr8n.session.init_application cache_application @languages = cache_languages cache_translations generate_symlink end |
#file_path(key) ⇒ Object
36 37 38 |
# File 'lib/tr8n_core/generators/cache/file.rb', line 36 def file_path(key) "#{cache_path}/#{Tr8n::CacheAdapters::File.file_name(key)}" end |
#symlink_path ⇒ Object
44 45 46 |
# File 'lib/tr8n_core/generators/cache/file.rb', line 44 def symlink_path Tr8n::CacheAdapters::File.cache_path end |