rubypitaya 2.2.2 → 2.3.0

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
  SHA256:
3
- metadata.gz: e34b4f837db342c17e307255d3f45ead903794ab727e7de806674906019329c6
4
- data.tar.gz: 335696b1f6de405da7f7f7bf5426c8a86485c7b46e3675729847f6203224ee95
3
+ metadata.gz: 56eed6ff93a6e6e8bc76351c3c4d06584fcc247888ef05783040cc96dc2966e6
4
+ data.tar.gz: 408c3f0226b7c42604fe416362e4bac3d333f72e313f59a2da646c527eec568c
5
5
  SHA512:
6
- metadata.gz: 9a7c707616860f57845ccb552b593c1ef11b884918fc71eda11b1615e8e8aef335c4a91f44003cc4c74ee0d7446c1dc1db734f51878cd51203f1a285d06ede92
7
- data.tar.gz: 34bf38eea9e9d1986a8a3aad6f0bf4231149a1ced7f21c48f9ae6b4106f2d496e375adf829087f15c1ac7d4f8691cb24a7395c302dcb2f68b62f68e425c7d286
6
+ metadata.gz: f6c3ad1a9c338076f5dcee3000016b41f157f843b921015aa30eb6fcad6da0e6a49265ee39f9dc382dd8840e9e74ba71934a6aea70e8f00490aaef7e15c8a0fe
7
+ data.tar.gz: 71060870925f98450a9e17326ece14500bd0ff095399b50e33df9dec360fb105321e9fa33bb2b64f17d989d8588584ed983d0d660349cf1ad473cd5221df0b42
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.2.2'
3
+ gem 'rubypitaya', '2.3.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.12.2'
@@ -62,7 +62,7 @@ GEM
62
62
  diff-lcs (>= 1.2.0, < 2.0)
63
63
  rspec-support (~> 3.8.0)
64
64
  rspec-support (3.8.3)
65
- rubypitaya (2.2.2)
65
+ rubypitaya (2.3.0)
66
66
  activerecord (= 6.0.2)
67
67
  etcdv3 (= 0.10.2)
68
68
  eventmachine (= 1.2.7)
@@ -1,88 +1,22 @@
1
+ require 'rubypitaya/core/config_core'
2
+
1
3
  module RubyPitaya
2
4
 
3
5
  class Config
4
6
 
5
- def initialize()
6
- @config = {}
7
- @configs_folder_paths = [Path::APP_CONFIG_FOLDER_PATH] + Path::Plugins::APP_CONFIG_FOLDER_PATHS
8
-
9
- @configs_folder_paths.each do |configs_folder_path|
10
- path_to_all_files = File.join(configs_folder_path, '**/*.json')
11
- config_files = Dir.glob(path_to_all_files)
12
-
13
- config_files.each do |config_file|
14
- load_config_file(configs_folder_path, config_file)
15
- end
16
- end
17
- end
18
-
19
- def get
20
- @config
7
+ def initialize
8
+ @config_core = ConfigCore.new
9
+ @config_core_override = nil
21
10
  end
22
11
 
23
12
  def [](key)
24
- split_key = key.split('/')
25
- @config.dig(*split_key)
13
+ result = @config_core_override[key] unless @config_core_override.nil?
14
+ result = @config_core[key] if result.nil?
26
15
  end
27
16
 
28
17
  def auto_reload
29
- require 'listen'
30
-
31
- @configs_folder_paths.each do |configs_folder_path|
32
- config_files_listener = Listen.to(configs_folder_path, only: /\.json$/) do |modified, added, removed|
33
- import_added_files(configs_folder_path, added)
34
- reload_modified_files(configs_folder_path, modified)
35
- end
36
-
37
- config_files_listener.start
38
- end
39
- end
40
-
41
- private
42
-
43
- def load_config_file(configs_folder_path, file_path)
44
- config_text = File.open(file_path, &:read)
45
- config_hash = JSON.parse(config_text)
46
-
47
- path_array = file_path.sub(/^#{configs_folder_path}/, '')[0..-6]
48
- .split('/')
49
-
50
- set_config_value(path_array, config_hash)
51
-
52
- rescue Exception => error
53
- puts "ERROR: #{error}"
54
- puts error.backtrace
55
- end
56
-
57
- def import_added_files(configs_folder_path, files_path)
58
- files_path.each do |path|
59
- load_config_file(configs_folder_path, path)
60
-
61
- puts "ADDED config: #{path}"
62
- end
63
- end
64
-
65
- def reload_modified_files(configs_folder_path, files_path)
66
- files_path.each do |path|
67
- load_config_file(configs_folder_path, path)
68
-
69
- puts "MODIFIED @config: #{path}"
70
- end
71
- end
72
-
73
- def set_config_value(keys, value)
74
- config = @config
75
-
76
- keys.each_with_index do |key, index|
77
- is_last_index = index == keys.size - 1
78
-
79
- if is_last_index
80
- config[key] = value
81
- else
82
- config[key] = {} unless config.key?(key)
83
- config = config[key]
84
- end
85
- end
18
+ @config_core.auto_reload
19
+ @config_core_override.auto_reload unless @config_core_override.nil?
86
20
  end
87
21
  end
88
22
  end
@@ -0,0 +1,84 @@
1
+ module RubyPitaya
2
+
3
+ class ConfigCore
4
+
5
+ def initialize()
6
+ @config = {}
7
+ @configs_folder_paths = [Path::APP_CONFIG_FOLDER_PATH] + Path::Plugins::APP_CONFIG_FOLDER_PATHS
8
+
9
+ @configs_folder_paths.each do |configs_folder_path|
10
+ path_to_all_files = File.join(configs_folder_path, '**/*.json')
11
+ config_files = Dir.glob(path_to_all_files)
12
+
13
+ config_files.each do |config_file|
14
+ load_config_file(configs_folder_path, config_file)
15
+ end
16
+ end
17
+ end
18
+
19
+ def [](key)
20
+ split_key = key.split('/')
21
+ @config.dig(*split_key)
22
+ end
23
+
24
+ def auto_reload
25
+ require 'listen'
26
+
27
+ @configs_folder_paths.each do |configs_folder_path|
28
+ config_files_listener = Listen.to(configs_folder_path, only: /\.json$/) do |modified, added, removed|
29
+ import_added_files(configs_folder_path, added)
30
+ reload_modified_files(configs_folder_path, modified)
31
+ end
32
+
33
+ config_files_listener.start
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def load_config_file(configs_folder_path, file_path)
40
+ config_text = File.open(file_path, &:read)
41
+ config_hash = JSON.parse(config_text)
42
+
43
+ path_array = file_path.sub(/^#{configs_folder_path}/, '')[0..-6]
44
+ .split('/')
45
+
46
+ set_config_value(path_array, config_hash)
47
+
48
+ rescue Exception => error
49
+ puts "ERROR: #{error}"
50
+ puts error.backtrace
51
+ end
52
+
53
+ def import_added_files(configs_folder_path, files_path)
54
+ files_path.each do |path|
55
+ load_config_file(configs_folder_path, path)
56
+
57
+ puts "ADDED config: #{path}"
58
+ end
59
+ end
60
+
61
+ def reload_modified_files(configs_folder_path, files_path)
62
+ files_path.each do |path|
63
+ load_config_file(configs_folder_path, path)
64
+
65
+ puts "MODIFIED @config: #{path}"
66
+ end
67
+ end
68
+
69
+ def set_config_value(keys, value)
70
+ config = @config
71
+
72
+ keys.each_with_index do |key, index|
73
+ is_last_index = index == keys.size - 1
74
+
75
+ if is_last_index
76
+ config[key] = value
77
+ else
78
+ config[key] = {} unless config.key?(key)
79
+ config = config[key]
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -62,7 +62,7 @@ module RubyPitaya
62
62
 
63
63
  @session = Session.new
64
64
  @postman = Postman.new(@nats_connector)
65
- @config = Config.new()
65
+ @config = Config.new
66
66
  @config.auto_reload if @is_development_environment
67
67
 
68
68
  @bll = InstanceHolder.new
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.2.2'
2
+ VERSION = '2.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypitaya
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-31 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -227,6 +227,7 @@ files:
227
227
  - "./lib/rubypitaya/core/app/models/user.rb"
228
228
  - "./lib/rubypitaya/core/application_files_importer.rb"
229
229
  - "./lib/rubypitaya/core/config.rb"
230
+ - "./lib/rubypitaya/core/config_core.rb"
230
231
  - "./lib/rubypitaya/core/database_config.rb"
231
232
  - "./lib/rubypitaya/core/database_connector.rb"
232
233
  - "./lib/rubypitaya/core/db/migration/0000000001_create_user_migration.rb"