rubypitaya 2.1.0 → 2.3.1

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: 2cc4718b7cd0df9727cfc2758ee744825bc1a9eeac93e9f34ca42cb3d9b42031
4
- data.tar.gz: 4cc801f3f64c975ed2be0b8a842d7ff028e7546f175a36f6f5006095ee686d88
3
+ metadata.gz: 5291558f9dd5aa593ad105ae1569c7e0cbe7f50cd09f0ed3787b6138df16a984
4
+ data.tar.gz: 149b44e5cb086bc0e2a065c49f7cd94a030ca46bfe5f81c215c4587f5e97862d
5
5
  SHA512:
6
- metadata.gz: a1dca87bab6d093dcc46a2941134964beacba1ded24898bd7445aec2e0fce1d1081a0404e7ba4ccb05fb5ecbfeb0e1995b964086ce16ad63376d4280f20ff302
7
- data.tar.gz: '0885d2711fab0a98dbd2dfd0aff6ae6cd0452e5fc705b73cac3aecdc203b8f12bcbaa92c634b92f2fd8193ee813e542fa2f70f97646da1f84585fbad9f9de895'
6
+ metadata.gz: 9d10ac3a7ec3eab79ef031c2c59c2be72c5641933a341cfe14ec95f3369e5f5d2d60152de0f6cb7272dc413186ed33aea8788669ef3f5fd8bf00f75155624154
7
+ data.tar.gz: 699f5d3570899fe31085bd5b902470f1f3d47a4bb42d48034d4627d2258fc01b00e59dde6bd4f8af1a845ffdc840a116bedcbc8165cba17d9c29fda71bee87aa
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.1.0'
3
+ gem 'rubypitaya', '2.3.1'
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.1.0)
65
+ rubypitaya (2.3.1)
66
66
  activerecord (= 6.0.2)
67
67
  etcdv3 (= 0.10.2)
68
68
  eventmachine (= 1.2.7)
@@ -85,7 +85,7 @@ DEPENDENCIES
85
85
  pry (= 0.12.2)
86
86
  rake (= 10.0)
87
87
  rspec (= 3.8.0)
88
- rubypitaya (= 2.1.0)
88
+ rubypitaya (= 2.2.2)
89
89
 
90
90
  BUNDLED WITH
91
91
  1.17.2
@@ -4,7 +4,8 @@ class AppInitializer < RubyPitaya::InitializerBase
4
4
  # parameter: initializer_content
5
5
  # attributes:
6
6
  # - bll
7
- # - class: InstanceHolder
7
+ # - class: RubyPitaya::InstanceHolder
8
+ # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/instance_holder.rb
8
9
  # - methods:
9
10
  # - add_instance(key, instance)
10
11
  # - add any instance to any key
@@ -12,6 +13,12 @@ class AppInitializer < RubyPitaya::InitializerBase
12
13
  # - get instance by key
13
14
  # - redis
14
15
  # - link: https://github.com/redis/redis-rb/
16
+ # - config
17
+ # - class: RubyPitaya::Config
18
+ # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
19
+ # - methods:
20
+ # - [](key)
21
+ # - get config file by config path
15
22
 
16
23
  def run(initializer_content)
17
24
  bll = initializer_content.bll
@@ -17,14 +17,16 @@ module RubyPitaya
17
17
  def auto_reload
18
18
  require 'listen'
19
19
 
20
- @app_folder_paths.each do |app_folder_path|
21
- @app_files_listener = Listen.to(app_folder_path, only: /\.rb$/) do |modified, added, removed|
22
- import_added_files(added)
23
- reload_modified_files(modified)
24
- end
25
-
26
- @app_files_listener.start
20
+ @app_files_listener = Listen.to(*@app_folder_paths,
21
+ only: /\.rb$/,
22
+ force_polling: true,
23
+ latency: 0.25,
24
+ wait_for_delay: 0.1) do |modified, added, removed|
25
+ import_added_files(added)
26
+ reload_modified_files(modified)
27
27
  end
28
+
29
+ @app_files_listener.start
28
30
  end
29
31
 
30
32
  private
@@ -1,87 +1,24 @@
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
7
+ attr_writer :config_core_override
18
8
 
19
- def get
20
- @config
9
+ def initialize
10
+ @config_core = ConfigCore.new
11
+ @config_core_override = nil
21
12
  end
22
13
 
23
14
  def [](key)
24
- @config[key]
15
+ result = @config_core_override[key] unless @config_core_override.nil?
16
+ result = @config_core[key] if result.nil?
25
17
  end
26
18
 
27
19
  def auto_reload
28
- require 'listen'
29
-
30
- @configs_folder_paths.each do |configs_folder_path|
31
- config_files_listener = Listen.to(configs_folder_path, only: /\.json$/) do |modified, added, removed|
32
- import_added_files(configs_folder_path, added)
33
- reload_modified_files(configs_folder_path, modified)
34
- end
35
-
36
- config_files_listener.start
37
- end
38
- end
39
-
40
- private
41
-
42
- def load_config_file(configs_folder_path, file_path)
43
- config_text = File.open(file_path, &:read)
44
- config_hash = JSON.parse(config_text)
45
-
46
- path_array = file_path.sub(/^#{configs_folder_path}/, '')[0..-6]
47
- .split('/')
48
-
49
- set_config_value(path_array, config_hash)
50
-
51
- rescue Exception => error
52
- puts "ERROR: #{error}"
53
- puts error.backtrace
54
- end
55
-
56
- def import_added_files(configs_folder_path, files_path)
57
- files_path.each do |path|
58
- load_config_file(configs_folder_path, path)
59
-
60
- puts "ADDED config: #{path}"
61
- end
62
- end
63
-
64
- def reload_modified_files(configs_folder_path, files_path)
65
- files_path.each do |path|
66
- load_config_file(configs_folder_path, path)
67
-
68
- puts "MODIFIED @config: #{path}"
69
- end
70
- end
71
-
72
- def set_config_value(keys, value)
73
- config = @config
74
-
75
- keys.each_with_index do |key, index|
76
- is_last_index = index == keys.size - 1
77
-
78
- if is_last_index
79
- config[key] = value
80
- else
81
- config[key] = {} unless config.key?(key)
82
- config = config[key]
83
- end
84
- end
20
+ @config_core.auto_reload
21
+ @config_core_override.auto_reload unless @config_core_override.nil?
85
22
  end
86
23
  end
87
24
  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
@@ -2,11 +2,12 @@ module RubyPitaya
2
2
 
3
3
  class InitializerContent
4
4
 
5
- attr_reader :bll, :redis
5
+ attr_reader :bll, :redis, :config
6
6
 
7
- def initialize(bll, redis)
7
+ def initialize(bll, redis, config)
8
8
  @bll = bll
9
9
  @redis = redis
10
+ @config = config
10
11
  end
11
12
  end
12
13
  end
@@ -62,12 +62,14 @@ 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
69
69
 
70
- @initializer_content = InitializerContent.new(@bll, @redis_connector.redis)
70
+ @initializer_content = InitializerContent.new(@bll,
71
+ @redis_connector.redis,
72
+ @config)
71
73
  @initializer_broadcast = InitializerBroadcast.new
72
74
  @initializer_broadcast.run(@initializer_content)
73
75
 
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.1.0'
2
+ VERSION = '2.3.1'
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.1.0
4
+ version: 2.3.1
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-16 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"