tp_common 0.1.1 → 0.1.2
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 +4 -4
- data/lib/tp_common/railtie.rb +7 -0
- data/lib/tp_common/timezones/config.rb +38 -0
- data/lib/tp_common/timezones/zone.rb +2 -5
- data/lib/tp_common/timezones.rb +3 -1
- data/lib/tp_common/version.rb +1 -1
- data/lib/tp_common.rb +5 -16
- metadata +5 -3
- /data/lib/{config → tp_common/timezones/config}/timezones.yml +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b356520bfa9dafe1b9d9faf0085ab4036e1e5dca
|
4
|
+
data.tar.gz: a015f6bd07598ffe465aa90e51730670e73ca2b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb409e4a85367d909016d000374132818be6ea00c9f18b5dfa9c2ce554ead08144ecdd9d8d7255a2775f28ffcdb3c86fca45a9a3701c2850afb67b05c6738d7
|
7
|
+
data.tar.gz: c7dbe6e37ca7f854a9883f2550fa7c4b3b992b95820cb20e965f0728157e398b519386e3afa61cc7edc273be672b4682ce001d2335a2593d59b6aebb16477858
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module TpCommon
|
2
|
+
module Timezones
|
3
|
+
class Config
|
4
|
+
def self.config
|
5
|
+
return if TpCommon::Timezones.const_defined?("LIST_ZONES")
|
6
|
+
if defined?(::Rails::Railtie)
|
7
|
+
begin
|
8
|
+
TpCommon::Timezones.const_set("LIST_ZONES", Rails.application.config_for(:timezones))
|
9
|
+
return
|
10
|
+
rescue NameError, NoMethodError
|
11
|
+
puts "Couldn't load Rails or config methods. Use default."
|
12
|
+
rescue StandardError
|
13
|
+
puts "Couldn't load file config/timezones.yml. Use default."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
TpCommon::Timezones.const_set("LIST_ZONES", load_default_timezones)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load_default_timezones
|
21
|
+
file_path = File.join(File.dirname(__FILE__),"config/timezones.yml")
|
22
|
+
yaml = Pathname.new(file_path)
|
23
|
+
|
24
|
+
if yaml.exist?
|
25
|
+
require "erb"
|
26
|
+
(YAML.load(ERB.new(yaml.read).result) || {})["all_zones"] || {}
|
27
|
+
else
|
28
|
+
raise "Could not load configuration. No such file - #{yaml}"
|
29
|
+
end
|
30
|
+
rescue Psych::SyntaxError => e
|
31
|
+
raise "YAML syntax error occurred while parsing #{yaml}. ",
|
32
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. ",
|
33
|
+
"Error: #{e.message}"
|
34
|
+
end
|
35
|
+
private_class_method :load_default_timezones
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -2,7 +2,6 @@ module TpCommon
|
|
2
2
|
module Timezones
|
3
3
|
class Zone
|
4
4
|
SECONDS_IN_AN_HOUR = 3600
|
5
|
-
DAY_LIGHT_SAVING_ZONES = ['Etc/GMT+9', 'Etc/GMT+8', 'Etc/GMT+7', 'Etc/GMT+6', 'Etc/GMT+5'].freeze
|
6
5
|
|
7
6
|
attr_reader :key
|
8
7
|
|
@@ -30,14 +29,12 @@ module TpCommon
|
|
30
29
|
|
31
30
|
private
|
32
31
|
|
33
|
-
attr_reader :time, :name
|
34
|
-
|
35
32
|
def gmt_12
|
36
|
-
time.in_time_zone('Etc/GMT-12')
|
33
|
+
@time.in_time_zone('Etc/GMT-12')
|
37
34
|
end
|
38
35
|
|
39
36
|
def organization_time
|
40
|
-
time.in_time_zone(name)
|
37
|
+
@time.in_time_zone(@name)
|
41
38
|
end
|
42
39
|
|
43
40
|
def time_difference_in_seconds
|
data/lib/tp_common/timezones.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'tp_common/timezones/config'
|
2
|
+
|
1
3
|
module TpCommon
|
2
4
|
module Timezones
|
3
|
-
LIST_ZONES = TpCommon
|
5
|
+
# LIST_ZONES = # Dynamic defined in TpCommon::Timezones::Config
|
4
6
|
|
5
7
|
def self.current_date_in_time_zone(time_zone_key)
|
6
8
|
self.converted_time(Time.now, time_zone_key).strftime('%Y-%m-%d %H:%M:%S').to_date
|
data/lib/tp_common/version.rb
CHANGED
data/lib/tp_common.rb
CHANGED
@@ -3,24 +3,13 @@ require 'active_support/all'
|
|
3
3
|
require 'psych'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
|
6
|
+
require 'pry-byebug'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
yaml = Pathname.new(file_path)
|
8
|
+
if defined?(::Rails::Railtie)
|
9
|
+
require 'tp_common/railtie'
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
require "erb"
|
15
|
-
(YAML.load(ERB.new(yaml.read).result) || {})["all_zones"] || {}
|
16
|
-
else
|
17
|
-
raise "Could not load configuration. No such file - #{yaml}"
|
18
|
-
end
|
19
|
-
rescue Psych::SyntaxError => e
|
20
|
-
raise "YAML syntax error occurred while parsing #{yaml}. ",
|
21
|
-
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. ",
|
22
|
-
"Error: #{e.message}"
|
23
|
-
end
|
12
|
+
module TpCommon
|
24
13
|
end
|
25
14
|
|
26
15
|
require "tp_common/timezones"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tp_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- An Vo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -153,9 +153,11 @@ files:
|
|
153
153
|
- Rakefile
|
154
154
|
- bin/console
|
155
155
|
- bin/setup
|
156
|
-
- lib/config/timezones.yml
|
157
156
|
- lib/tp_common.rb
|
157
|
+
- lib/tp_common/railtie.rb
|
158
158
|
- lib/tp_common/timezones.rb
|
159
|
+
- lib/tp_common/timezones/config.rb
|
160
|
+
- lib/tp_common/timezones/config/timezones.yml
|
159
161
|
- lib/tp_common/timezones/zone.rb
|
160
162
|
- lib/tp_common/version.rb
|
161
163
|
- tp_common.gemspec
|
File without changes
|