tp_common 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b250665eba9abc1bfee17f6baf598a706d947b4b8f53087d4193b1d207669d4
4
- data.tar.gz: 5524aa1316006cf8bf7d553400c30bf7c0d9c30fea33b6f7261585b167554e64
3
+ metadata.gz: 3c82f0ce642dc1cd99e759a8afa0fd7ef2ab84dfb63ee3e4907c27f28130ecf0
4
+ data.tar.gz: 2af83acd05b645bc50f37808f6d8dbcb046da87f211b55bbec2c3bd4d69be9f3
5
5
  SHA512:
6
- metadata.gz: 20b4549420d10cb358e55354d77115c87de39da01efa8dc7eac83383d4bf3279f460e2465d3340f7a852bfdd481d0087f29e1c6f15644a7c63ea126f387eab29
7
- data.tar.gz: 619014359a6498ce2846be4b35083186d861992272393acec0cb6e05c571d689a6ae8ae1bbcba1170494abd6b993bb4165e5b640af4ff0b17331190127f8a001
6
+ metadata.gz: e79880322a5417851ad894fb64e44fe64a65de46da4d89253d6be0ba092fead386cbed9655ada94bcd246decfe456bea4ad78f9d78e007ff52ccceb8d9390391
7
+ data.tar.gz: 502054409c6606ced1ce284b798326451642505154bb329eb42f573682eb66a2d08036a0633e8c9825794e0154cba734046fc9f68c7064b582f9f3feff4f4b6d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- tp_common (0.4.1)
4
+ tp_common (0.4.2)
5
5
  activesupport (>= 4.2.0, <= 5.2.1)
6
6
  aws-sdk-s3 (~> 1.19)
7
7
  fog-aws (~> 2.0)
@@ -51,16 +51,16 @@ GEM
51
51
  thor (>= 0.14.0)
52
52
  arel (6.0.4)
53
53
  aws-eventstream (1.0.1)
54
- aws-partitions (1.115.0)
55
- aws-sdk-core (3.39.0)
54
+ aws-partitions (1.136.0)
55
+ aws-sdk-core (3.46.0)
56
56
  aws-eventstream (~> 1.0)
57
57
  aws-partitions (~> 1.0)
58
58
  aws-sigv4 (~> 1.0)
59
59
  jmespath (~> 1.0)
60
- aws-sdk-kms (1.12.0)
60
+ aws-sdk-kms (1.13.0)
61
61
  aws-sdk-core (~> 3, >= 3.39.0)
62
62
  aws-sigv4 (~> 1.0)
63
- aws-sdk-s3 (1.25.0)
63
+ aws-sdk-s3 (1.30.1)
64
64
  aws-sdk-core (~> 3, >= 3.39.0)
65
65
  aws-sdk-kms (~> 1)
66
66
  aws-sigv4 (~> 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- tp_common (0.4.1)
4
+ tp_common (0.4.2)
5
5
  activesupport (>= 4.2.0, <= 5.2.1)
6
6
  aws-sdk-s3 (~> 1.19)
7
7
  fog-aws (~> 2.0)
@@ -54,16 +54,16 @@ GEM
54
54
  thor (>= 0.14.0)
55
55
  arel (7.1.4)
56
56
  aws-eventstream (1.0.1)
57
- aws-partitions (1.115.0)
58
- aws-sdk-core (3.39.0)
57
+ aws-partitions (1.136.0)
58
+ aws-sdk-core (3.46.0)
59
59
  aws-eventstream (~> 1.0)
60
60
  aws-partitions (~> 1.0)
61
61
  aws-sigv4 (~> 1.0)
62
62
  jmespath (~> 1.0)
63
- aws-sdk-kms (1.12.0)
63
+ aws-sdk-kms (1.13.0)
64
64
  aws-sdk-core (~> 3, >= 3.39.0)
65
65
  aws-sigv4 (~> 1.0)
66
- aws-sdk-s3 (1.25.0)
66
+ aws-sdk-s3 (1.30.1)
67
67
  aws-sdk-core (~> 3, >= 3.39.0)
68
68
  aws-sdk-kms (~> 1)
69
69
  aws-sigv4 (~> 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- tp_common (0.4.1)
4
+ tp_common (0.4.2)
5
5
  activesupport (>= 4.2.0, <= 5.2.1)
6
6
  aws-sdk-s3 (~> 1.19)
7
7
  fog-aws (~> 2.0)
@@ -58,16 +58,16 @@ GEM
58
58
  thor (>= 0.14.0)
59
59
  arel (9.0.0)
60
60
  aws-eventstream (1.0.1)
61
- aws-partitions (1.115.0)
62
- aws-sdk-core (3.39.0)
61
+ aws-partitions (1.136.0)
62
+ aws-sdk-core (3.46.0)
63
63
  aws-eventstream (~> 1.0)
64
64
  aws-partitions (~> 1.0)
65
65
  aws-sigv4 (~> 1.0)
66
66
  jmespath (~> 1.0)
67
- aws-sdk-kms (1.12.0)
67
+ aws-sdk-kms (1.13.0)
68
68
  aws-sdk-core (~> 3, >= 3.39.0)
69
69
  aws-sigv4 (~> 1.0)
70
- aws-sdk-s3 (1.25.0)
70
+ aws-sdk-s3 (1.30.1)
71
71
  aws-sdk-core (~> 3, >= 3.39.0)
72
72
  aws-sdk-kms (~> 1)
73
73
  aws-sigv4 (~> 1.0)
data/lib/tp_common.rb CHANGED
@@ -18,3 +18,4 @@ require "tp_common/timezones"
18
18
  require "tp_common/timezones/zone"
19
19
  require "tp_common/assets_loader"
20
20
  require "tp_common/file_storage"
21
+ require "tp_common/app_config"
@@ -0,0 +1 @@
1
+ require "tp_common/app_config/environment"
@@ -0,0 +1,94 @@
1
+ require 'psych'
2
+ require 'yaml'
3
+
4
+ module TpCommon
5
+ module AppConfig
6
+ module Environment
7
+ class << self
8
+ # 2 levels of configuration:
9
+ #
10
+ # config/app_config.yml
11
+ # ```
12
+ # app:
13
+ # name:
14
+ # detail:
15
+ # db:
16
+ # readonly: true
17
+ # ```
18
+ #
19
+ # Environment variables. Variable name will be downcase and replace `__` by `.`
20
+ # ```
21
+ # APP__NAME__DETAIL=octopus
22
+ # APP__NAME2=octopus2
23
+ # ```
24
+ # Value in environment variable will overwrite value in `config/app_config.yml`
25
+ # BUT key will be ignore if doesn't exists in `config/app_config.yml`
26
+ # So in case above,
27
+ # ```
28
+ # TpCommon::AppConfig::Environment.fetch(:'app.name.detail') # => "octopus"
29
+ # TpCommon::AppConfig::Environment.fetch(:'app.name2') # => nil
30
+ # ```
31
+ # We could mixed both to use, but we recommend:
32
+ # use `config/app_config.yml` which committed to repo to know
33
+ # how many, what are config we use in app
34
+ # with default value (optional)
35
+ # use environment variables for differences config between stages (producion, staging, pre-production, ...)
36
+ #
37
+ def fetch(key)
38
+ @app_config ||= load_config
39
+ @app_config[key]
40
+ end
41
+
42
+ private
43
+
44
+ def load_config
45
+ default_config = Hash[*flatten_hash(load_yaml_config)].inject({}) do |carry, (key, value)|
46
+ carry[key.to_sym] = value
47
+ carry
48
+ end
49
+
50
+ ENV.each do |env_name, value|
51
+ key = env_name.downcase.gsub('__', '.').to_sym
52
+
53
+ if default_config.key?(key)
54
+ default_config[key] = value
55
+ end
56
+ end
57
+
58
+ default_config.freeze
59
+ end
60
+
61
+ def load_yaml_config
62
+ file_path = if defined?(Rails)
63
+ File.join(Rails.root,'config/app_config.yml')
64
+ else
65
+ File.join(File.dirname(__FILE__),'app_config.yml')
66
+ end
67
+
68
+ yaml = Pathname.new(file_path)
69
+ if yaml.exist?
70
+ require 'erb'
71
+ (YAML.safe_load(ERB.new(yaml.read).result) || {}) || {}
72
+ else
73
+ raise "Could not load configuration. No such file - #{yaml}"
74
+ end
75
+ rescue Psych::SyntaxError => exception
76
+ raise "YAML syntax error occurred while parsing #{yaml}. ",
77
+ 'Please note that YAML must be consistently indented using spaces. Tabs are not allowed. ',
78
+ "Error: #{exception.message}"
79
+ end
80
+
81
+ def flatten_hash(my_hash, parent = [])
82
+ my_hash.flat_map do |key, value|
83
+ case value
84
+ when Hash then
85
+ flatten_hash(value, parent + [key])
86
+ else
87
+ [(parent + [key]).join('.'), value]
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module TpCommon
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TINYpulse Devops
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -210,6 +210,8 @@ files:
210
210
  - gemfiles/rails_latest.gemfile
211
211
  - gemfiles/rails_latest.gemfile.lock
212
212
  - lib/tp_common.rb
213
+ - lib/tp_common/app_config.rb
214
+ - lib/tp_common/app_config/environment.rb
213
215
  - lib/tp_common/assets_loader.rb
214
216
  - lib/tp_common/file_storage.rb
215
217
  - lib/tp_common/file_storage/base.rb
@@ -249,8 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
251
  - !ruby/object:Gem::Version
250
252
  version: '0'
251
253
  requirements: []
252
- rubyforge_project:
253
- rubygems_version: 2.7.8
254
+ rubygems_version: 3.0.2
254
255
  signing_key:
255
256
  specification_version: 4
256
257
  summary: Common libraries used for TINYpulse apps