Module: Tr8n
- Defined in:
- lib/tr8n/cache.rb,
lib/tr8n_core.rb,
lib/tr8n/utils.rb,
lib/tr8n/config.rb,
lib/tr8n/logger.rb,
lib/tr8n/session.rb,
lib/tr8n/tokens/data.rb,
lib/tr8n/tokenizers/dom.rb,
lib/tr8n/tokenizers/data.rb,
lib/tr8n/rules_engine/parser.rb,
lib/tr8n/tokenizers/decoration.rb,
lib/tr8n/rules_engine/evaluator.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. ++
Defined Under Namespace
Modules: CacheAdapters, Decorators, Rules, RulesEngine, Tokenizers, Tokens Classes: ApiClient, Application, Base, Cache, Component, Config, Exception, Language, LanguageCase, LanguageCaseRule, LanguageContext, LanguageContextRule, Logger, Session, Source, Translation, TranslationKey, Translator, Utils
Constant Summary collapse
- CACHE_VERSION_KEY =
"__tr8n_version__"
Class Attribute Summary collapse
-
.config ⇒ Object
Initializes default config.
Class Method Summary collapse
- .cache ⇒ Object
-
.configure {|self.config| ... } ⇒ Object
Allows you to configure Tr8n.
- .logger ⇒ Object
- .session ⇒ Object
-
.with_config_settings {|@config| ... } ⇒ Object
Allows you to create a block to perform something on adjusted config settings Once the block exists, the config will be reset back to what it was before:.
Class Attribute Details
.config ⇒ Object
Initializes default config
41 42 43 |
# File 'lib/tr8n/config.rb', line 41 def config @config end |
Class Method Details
.cache ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tr8n/cache.rb', line 37 def self.cache @cache ||= begin if Tr8n.config.cache_enabled? klass = Tr8n::CacheAdapters.const_get(Tr8n.config.cache[:adapter].camelcase) klass.new else # blank implementation Tr8n::Cache.new end end end |
.configure {|self.config| ... } ⇒ Object
Allows you to configure Tr8n
Tr8n.configure do |config|
config.application = {:key => "", :secret => ""}
end
53 54 55 |
# File 'lib/tr8n/config.rb', line 53 def self.configure yield(self.config) end |
.logger ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tr8n/logger.rb', line 37 def self.logger @logger ||= begin logfile_path = File.(Tr8n.config.logger[:path]) logfile_dir = logfile_path.split("/")[0..-2].join("/") FileUtils.mkdir_p(logfile_dir) unless File.exist?(logfile_dir) logfile = File.open(logfile_path, 'a') logfile.sync = true Tr8n::Logger.new(logfile) end end |
.session ⇒ Object
35 36 37 |
# File 'lib/tr8n/session.rb', line 35 def self.session Thread.current[:session] ||= Tr8n::Session.new end |
.with_config_settings {|@config| ... } ⇒ Object
Allows you to create a block to perform something on adjusted config settings Once the block exists, the config will be reset back to what it was before:
Tr8n.with_config_settings do |config|
config.format = :text
Do something....
end
68 69 70 71 72 |
# File 'lib/tr8n/config.rb', line 68 def self.with_config_settings old_config = @config.dup yield(@config) @config = old_config end |