Class: Tr8nCore::Generators::Cache::Base
- Inherits:
-
Object
- Object
- Tr8nCore::Generators::Cache::Base
- Defined in:
- lib/tr8n_core/generators/cache/base.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 collapse
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
Instance Method Summary collapse
- #cache(key, data) ⇒ Object
- #cache_application ⇒ Object
- #cache_languages ⇒ Object
- #cache_path ⇒ Object
- #execute ⇒ Object
- #finalize ⇒ Object
- #generate_symlink ⇒ Object
- #log(msg) ⇒ Object
- #prepare ⇒ Object
- #run ⇒ Object
- #symlink_path ⇒ Object
Instance Attribute Details
#finished_at ⇒ Object
Returns the value of attribute finished_at.
34 35 36 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 34 def finished_at @finished_at end |
#started_at ⇒ Object
Returns the value of attribute started_at.
34 35 36 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 34 def started_at @started_at end |
Instance Method Details
#cache(key, data) ⇒ Object
44 45 46 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 44 def cache(key, data) raise Tr8n::Exception.new("Must be implemented by the subclass") end |
#cache_application ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 69 def cache_application log("Downloading application...") app = Tr8n.session.application.get("application", :definition => true) cache(Tr8n::Application.cache_key(app["key"]), app) log("Application has been cached.") app end |
#cache_languages ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 77 def cache_languages log("Downloading languages...") languages = Tr8n.session.application.get("application/languages", :definition => true) languages.each do |lang| cache(Tr8n::Language.cache_key(lang["locale"]), lang) end log("#{languages.count} languages have been cached.") languages end |
#cache_path ⇒ Object
40 41 42 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 40 def cache_path raise Tr8n::Exception.new("Must be implemented by the subclass") end |
#execute ⇒ Object
48 49 50 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 48 def execute raise Tr8n::Exception.new("Must be implemented by the subclass") end |
#finalize ⇒ Object
62 63 64 65 66 67 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 62 def finalize @finished_at = Time.now log("Cache has been stored in #{cache_path}") log("Cache generation took #{@finished_at - @started_at} mls.") log("Done.") end |
#generate_symlink ⇒ Object
91 92 93 94 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 91 def generate_symlink FileUtils.rm(symlink_path) if File.exist?(symlink_path) FileUtils.ln_s(cache_path, symlink_path) end |
#log(msg) ⇒ Object
36 37 38 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 36 def log(msg) Tr8n.logger.debug("#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}: #{msg}\n") end |
#prepare ⇒ Object
58 59 60 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 58 def prepare @started_at = Time.now end |
#run ⇒ Object
52 53 54 55 56 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 52 def run prepare execute finalize end |
#symlink_path ⇒ Object
87 88 89 |
# File 'lib/tr8n_core/generators/cache/base.rb', line 87 def symlink_path raise Tr8n::Exception.new("Must be implemented by the subclass") end |