Module: Tml

Defined in:
lib/tml.rb,
lib/tml/cache.rb,
lib/tml/utils.rb,
lib/tml/config.rb,
lib/tml/logger.rb,
lib/tml/session.rb,
lib/tml/version.rb,
lib/tml/tokens/data.rb,
lib/tml/tokenizers/dom.rb,
lib/tml/tokenizers/data.rb,
lib/tml/rules_engine/parser.rb,
lib/tml/tokenizers/decoration.rb,
lib/tml/rules_engine/evaluator.rb

Overview

– Copyright © 2015 Translation Exchange, Inc

_______                  _       _   _             ______          _

|__ __| | | | | (_) | __| | |

| |_ __ __ _ _ __  ___| | __ _| |_ _  ___  _ __ | |__  __  _____| |__   __ _ _ __   __ _  ___
| | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \|  __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
| | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ >  < (__| | | | (_| | | | | (_| |  __/
|_|_|  \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
                                                                                    __/ |
                                                                                   |___/

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: Api, CacheAdapters, Decorators, Generators, Rules, RulesEngine, Tokenizers, Tokens Classes: Application, Base, Cache, Config, Exception, Language, LanguageCase, LanguageCaseRule, LanguageContext, LanguageContextRule, Logger, Session, Source, Translation, TranslationKey, Translator, Utils

Constant Summary collapse

CACHE_VERSION_KEY =
'__tml_version__'
VERSION =
'4.3.7'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Initializes default config



41
42
43
# File 'lib/tml/config.rb', line 41

def config
  @config
end

Class Method Details

.cacheObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tml/cache.rb', line 41

def self.cache
  @cache ||= begin
    if Tml.config.cache_enabled?
      klass = Tml::CacheAdapters.const_get(Tml.config.cache[:adapter].to_s.camelcase)
      klass.new
    else
      # blank implementation
      Tml::Cache.new
    end
  end
end

.configure {|self.config| ... } ⇒ Object

Allows you to configure Tml

Tml.configure do |config|

config.application = {:key => "", :secret => ""}

end

Yields:



53
54
55
# File 'lib/tml/config.rb', line 53

def self.configure
  yield(self.config)
end

.loggerObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tml/logger.rb', line 37

def self.logger
  @logger ||= begin
    if Tml.config.logger[:type].to_s == 'rails'
      Rails.logger
    else
      logfile_path = File.expand_path(Tml.config.logger[:path] || './log/tml.log')
      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
      Tml::Logger.new(logfile)
    end
  end
end

.logger=(logger) ⇒ Object



52
53
54
# File 'lib/tml/logger.rb', line 52

def self.logger=(logger)
  @logger = logger
end

.memoryObject



37
38
39
# File 'lib/tml/cache.rb', line 37

def self.memory
  @memory ||= Tml::CacheAdapters::Memory.new
end

.sessionObject



35
36
37
# File 'lib/tml/session.rb', line 35

def self.session
  Thread.current[:session] ||= Tml::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:

Tml.with_config_settings do |config|
   config.format = :text

   Do something....

end

Yields:



68
69
70
71
72
# File 'lib/tml/config.rb', line 68

def self.with_config_settings
  old_config = @config.dup
  yield(@config)
  @config = old_config
end