rubypitaya 2.2.0 → 2.3.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: daa040aaa44dd5fda0dd5e44f8f74f29c6f774c9233735147243fc261d98f59e
4
- data.tar.gz: 00f7d1a43a2d098356b090339fcf8db82f2a01520c674fb4df7e69c904deccc5
3
+ metadata.gz: 1a6fde2eae7ed9a98258d0032349d13a7c1c472630bba199e91b5d75a2999054
4
+ data.tar.gz: ce0f2c89d96cfb2368eb38b303251d696afe9022feda6baaf56f880d962464e7
5
5
  SHA512:
6
- metadata.gz: b2ca865cc8ccdd2450d1d117baccea88f3acda3ca50615d7d75086e3489aee3e6cbe0a79cf279ef1be90062d59de4bf26f915cba91afc8992a4261379cc4b629
7
- data.tar.gz: 17c1fe0d67e03065e12f0c6c2bc0f668314614a8eafd82e52fede90131e23da0b9fd0f8aa502a66c6fdc7a08c8e58db81c9cfef8a2d2ff9cee13468265c29010
6
+ metadata.gz: f70ae9bb4b1cfc53234a4e6f6c0d4680f10a923f6c563908b06d471eebda2e3b4a3e4bdcd85c13dec41e2f850d471b8a7fbf9c0cdd7d72f5c761a33f239de79a
7
+ data.tar.gz: a255dcfdcb71951a92fe57afb4b01f12adb576fb7fde1248a395ef62275c1f2560990f0618e6efb86b6938dd5b9472f116f3915f2bcf5efb519a158879f382a3
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.2.0'
3
+ gem 'rubypitaya', '2.3.2'
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.0)
65
+ rubypitaya (2.3.2)
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.2.0)
88
+ rubypitaya (= 2.3.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,88 +1,25 @@
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
- split_key = key.split('/')
25
- @config.dig(*split_key)
15
+ result = @config_core_override[key] unless @config_core_override.nil?
16
+ result = @config_core[key] if result.nil?
17
+ result
26
18
  end
27
19
 
28
20
  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
21
+ @config_core.auto_reload
22
+ @config_core_override.auto_reload unless @config_core_override.nil?
86
23
  end
87
24
  end
88
25
  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.2.0'
2
+ VERSION = '2.3.2'
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.0
4
+ version: 2.3.2
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"