tml 4.3.10 → 4.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd726ec4d8e669b5260eeef038dc0329e6806bd9
4
- data.tar.gz: fbf200f5e07562a46cf3430f0b88776beef69d19
3
+ metadata.gz: 543c3402b5a22496ef6c01bddae3e2d9a88e1b96
4
+ data.tar.gz: 9ac59ac29ad476a0d3908b8230fabef85178ab81
5
5
  SHA512:
6
- metadata.gz: 6af904753661a742074b7a0a0e8965029a259c4544d6c7dc7e92d1f916e99ca897672b3b311ec3216a4f6cfc38fabf9b94c27819540a019bf2068e6d270f5d38
7
- data.tar.gz: c0cb5917de547073873dd50e78360c660face599c1ff19aeb6de362e44edd7c427d62f9580a0da5492795e9c47df32c24dc04eabbcb0dba4eb22e23612d437d0
6
+ metadata.gz: 5c3f93c9a88c7be4007b75c9ac871f0ffb61ac207f2dce5ef8036a920e848a10277b9d2900efc30475e2ba977a78bc39f147fa8cad188d94f867f55d83fb5a28
7
+ data.tar.gz: 275ea0ced9791048f00f12df818e902aa73f508a8cd769825f22770eabd6b673f148f9de1f1fbe108de397b4985317679ba5258ee608b6d3d57c20080a40d06f
@@ -0,0 +1,101 @@
1
+ # encoding: UTF-8
2
+ #--
3
+ # Copyright (c) 2015 Translation Exchange, Inc
4
+ #
5
+ # _______ _ _ _ ______ _
6
+ # |__ __| | | | | (_) | ____| | |
7
+ # | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
8
+ # | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
9
+ # | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
10
+ # |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
11
+ # __/ |
12
+ # |___/
13
+ # Permission is hereby granted, free of charge, to any person obtaining
14
+ # a copy of this software and associated documentation files (the
15
+ # "Software"), to deal in the Software without restriction, including
16
+ # without limitation the rights to use, copy, modify, merge, publish,
17
+ # distribute, sublicense, and/or sell copies of the Software, and to
18
+ # permit persons to whom the Software is furnished to do so, subject to
19
+ # the following conditions:
20
+ #
21
+ # The above copyright notice and this permission notice shall be
22
+ # included in all copies or substantial portions of the Software.
23
+ #
24
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
+ #++
32
+
33
+ class Tml::CacheAdapters::Cdn < Tml::Cache
34
+
35
+ def self.cache
36
+ @cache ||= {}
37
+ end
38
+
39
+ def self.cache_path
40
+ "#{Tml.config.cache[:base_url]}/#{Tml.config.cache[:version]}"
41
+ end
42
+
43
+ def self.cdn_path(key)
44
+ File.join(cache_path, "#{key}.json")
45
+ end
46
+
47
+ def cache_name
48
+ 'cdn'
49
+ end
50
+
51
+ def segmented?
52
+ return true if Tml.config.cache[:segmented].nil?
53
+ Tml.config.cache[:segmented]
54
+ end
55
+
56
+ def fetch(key, opts = {})
57
+ if self.class.cache[key]
58
+ info("Memory hit: #{key}")
59
+ return self.class.cache[key]
60
+ end
61
+
62
+ path = self.class.cdn_path(key)
63
+
64
+
65
+ # load data from cdn
66
+
67
+
68
+ if File.exists?(path)
69
+ info("Cache hit: #{key}")
70
+ self.class.cache[key] = JSON.parse(File.read(path))
71
+ return self.class.cache[key]
72
+ end
73
+
74
+ info("Cache miss: #{key}")
75
+
76
+ return nil unless block_given?
77
+
78
+ yield
79
+ end
80
+
81
+ def store(key, data, opts = {})
82
+ warn('This is a readonly cache')
83
+ end
84
+
85
+ def delete(key, opts = {})
86
+ warn('This is a readonly cache')
87
+ end
88
+
89
+ def exist?(key, opts = {})
90
+ File.exists?(self.class.file_path(key))
91
+ end
92
+
93
+ def clear(opts = {})
94
+ warn('This is a readonly cache')
95
+ end
96
+
97
+ def read_only?
98
+ true
99
+ end
100
+
101
+ end
@@ -36,16 +36,18 @@ module Tml
36
36
 
37
37
  def self.logger
38
38
  @logger ||= begin
39
+ logfile_path = File.expand_path(Tml.config.logger[:path] || './log/tml.log')
40
+ logfile_dir = logfile_path.split("/")[0..-2].join("/")
41
+ FileUtils.mkdir_p(logfile_dir) unless File.exist?(logfile_dir)
42
+ logfile = File.open(logfile_path, 'a')
43
+ logfile.sync = true
44
+
45
+ logger = Tml::Logger.new(logfile)
39
46
  if Tml.config.logger[:type].to_s == 'rails'
40
- Rails.logger
41
- else
42
- logfile_path = File.expand_path(Tml.config.logger[:path] || './log/tml.log')
43
- logfile_dir = logfile_path.split("/")[0..-2].join("/")
44
- FileUtils.mkdir_p(logfile_dir) unless File.exist?(logfile_dir)
45
- logfile = File.open(logfile_path, 'a')
46
- logfile.sync = true
47
- Tml::Logger.new(logfile)
47
+ logger.external_logger = Rails.logger
48
48
  end
49
+
50
+ logger
49
51
  end
50
52
  end
51
53
 
@@ -54,11 +56,52 @@ module Tml
54
56
  end
55
57
 
56
58
  class Logger < ::Logger
59
+ attr_accessor :external_logger
60
+
61
+ def info(message)
62
+ if external_logger
63
+ return external_logger.info(format_message(Logger::Severity::INFO, Time.new, nil, message))
64
+ end
65
+
66
+ super
67
+ end
68
+
69
+ def debug(message)
70
+ if external_logger
71
+ return external_logger.debug(format_message(Logger::Severity::DEBUG, Time.new, nil, message))
72
+ end
73
+
74
+ super
75
+ end
76
+
77
+ def warn(message)
78
+ if external_logger
79
+ return external_logger.warn(format_message(Logger::Severity::WARN, Time.new, nil, message))
80
+ end
81
+
82
+ super
83
+ end
84
+
85
+ def error(message)
86
+ if external_logger
87
+ return external_logger.error(format_message(Logger::Severity::ERROR, Time.new, nil, message))
88
+ end
89
+
90
+ super
91
+ end
92
+
93
+ def fatal(message)
94
+ if external_logger
95
+ return external_logger.fatal(format_message(Logger::Severity::FATAL, Time.new, nil, message))
96
+ end
97
+
98
+ super
99
+ end
57
100
 
58
101
  def format_message(severity, timestamp, progname, msg)
59
102
  return "" unless Tml.config.logger[:enabled]
60
103
  # TODO: check for severity/level
61
- "[#{timestamp.strftime("%D %T")}]: #{" " * stack.size}#{msg}\n"
104
+ "[#{timestamp.strftime("%D %T")}]: tml: #{' ' * stack.size}#{msg}\n"
62
105
  end
63
106
 
64
107
  def add(severity, message = nil, progname = nil, &block)
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module Tml
33
- VERSION = '4.3.10'
33
+ VERSION = '4.3.11'
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tml
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.10
4
+ version: 4.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Berkovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-08 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -54,6 +54,7 @@ files:
54
54
  - lib/tml/application.rb
55
55
  - lib/tml/base.rb
56
56
  - lib/tml/cache.rb
57
+ - lib/tml/cache_adapters/cdn.rb
57
58
  - lib/tml/cache_adapters/file.rb
58
59
  - lib/tml/cache_adapters/memcache.rb
59
60
  - lib/tml/cache_adapters/redis.rb