rubypitaya 1.7.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubypitaya/app-template/Gemfile +1 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
- data/lib/rubypitaya/app-template/Makefile +4 -0
- data/lib/rubypitaya/app-template/Rakefile +25 -2
- data/lib/rubypitaya/app-template/app/constants/status_codes.rb +18 -11
- data/lib/rubypitaya/app-template/db/{migrate → migration}/001_create_user_migration.rb +0 -0
- data/lib/rubypitaya/app-template/db/{migrate → migration}/002_create_player_migration.rb +0 -0
- data/lib/rubypitaya/app-template/docker-compose.yml +1 -1
- data/lib/rubypitaya/core/application_files_importer.rb +13 -7
- data/lib/rubypitaya/core/config.rb +23 -20
- data/lib/rubypitaya/core/handler_router.rb +8 -2
- data/lib/rubypitaya/core/main.rb +3 -3
- data/lib/rubypitaya/core/path.rb +9 -1
- data/lib/rubypitaya/core/redis_connector.rb +7 -8
- data/lib/rubypitaya/core/status_codes.rb +18 -0
- data/lib/rubypitaya/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d3c8209b6441874334ea9dca6d209ff79ff63e5a5cbb4273125ac94bad12e7
|
4
|
+
data.tar.gz: 2d50b5319e1c113a92b5e67f76835a9be9706f4c60fc91185bdfa984cc576e25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95b1cc17e073849eea4aa13fb9f00f99f016768be5aaaeb00e93571829d036fbc4abc3407b165001858cfae0e23473f3f91ffdb52f8d14f3339599e82209f998
|
7
|
+
data.tar.gz: 1918c5bbda757ef6566acf6f32c269d6aaa08dae329316651d9ac417f7774fe1d0c1ac2f685d498f1b15e891d4b2f72f4fe15e4a6d8ef6b1975c0d1a323903b3
|
@@ -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 (
|
65
|
+
rubypitaya (2.0.0)
|
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 (=
|
88
|
+
rubypitaya (= 2.0.0)
|
89
89
|
|
90
90
|
BUNDLED WITH
|
91
91
|
1.17.2
|
@@ -30,6 +30,10 @@ db-create:
|
|
30
30
|
db-migrate:
|
31
31
|
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
|
32
32
|
|
33
|
+
## Rollback migrations STEP=1
|
34
|
+
db-rollback:
|
35
|
+
@docker-compose run --service-ports --rm -e STEP="$(STEP)" rubypitaya bundle exec rake db:rollback
|
36
|
+
|
33
37
|
## Drop database
|
34
38
|
db-drop:
|
35
39
|
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:drop
|
@@ -24,15 +24,38 @@ namespace :db do
|
|
24
24
|
environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
|
25
25
|
database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
|
26
26
|
connection_data = database_config.connection_data
|
27
|
-
|
27
|
+
migrations_paths = [RubyPitaya::Path::MIGRATIONS_FOLDER_PATH]
|
28
|
+
migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
|
28
29
|
|
29
30
|
ActiveRecord::Base.establish_connection(connection_data)
|
30
|
-
ActiveRecord::Migrator.migrations_paths =
|
31
|
+
ActiveRecord::Migrator.migrations_paths = migrations_paths
|
31
32
|
ActiveRecord::Tasks::DatabaseTasks.migrate
|
32
33
|
ActiveRecord::Base.connection.close
|
33
34
|
puts 'Database migrated.'
|
34
35
|
end
|
35
36
|
|
37
|
+
desc 'Rollback migrations'
|
38
|
+
task :rollback do
|
39
|
+
environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
|
40
|
+
database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
|
41
|
+
connection_data = database_config.connection_data
|
42
|
+
|
43
|
+
step = ENV["STEP"] ? ENV["STEP"].to_i : 1
|
44
|
+
|
45
|
+
if step == 0
|
46
|
+
puts ''
|
47
|
+
puts 'Error: No rollback to STEP=0'
|
48
|
+
puts ''
|
49
|
+
return
|
50
|
+
end
|
51
|
+
|
52
|
+
ActiveRecord::Base.establish_connection(connection_data)
|
53
|
+
ActiveRecord::Base.connection.migration_context.rollback(step)
|
54
|
+
ActiveRecord::Base.connection.close
|
55
|
+
|
56
|
+
puts 'Rollback done.'
|
57
|
+
end
|
58
|
+
|
36
59
|
desc 'Drop the database'
|
37
60
|
task :drop do
|
38
61
|
environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
|
@@ -1,15 +1,22 @@
|
|
1
1
|
class StatusCodes
|
2
|
-
# Success codes
|
3
|
-
CODE_OK = 'RP-200'
|
4
2
|
|
5
|
-
|
6
|
-
CODE_UNKNOWN = 'RP-000'
|
7
|
-
CODE_HANDLER_NOT_FOUNDED = 'RP-001'
|
8
|
-
CODE_ACTION_NOT_FOUNDED = 'RP-002'
|
9
|
-
CODE_NOT_AUTHENTICATED = 'RP-003'
|
10
|
-
CODE_AUTHENTICATION_ERROR = 'RP-004'
|
3
|
+
CODE_OK = RubyPitaya::StatusCodes::CODE_OK
|
11
4
|
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
################
|
6
|
+
## Existent Codes
|
7
|
+
################
|
8
|
+
## Success codes
|
9
|
+
#
|
10
|
+
# RubyPitaya::StatusCodes::CODE_OK = 'RP-200'
|
11
|
+
#
|
12
|
+
#
|
13
|
+
## Error codes
|
14
|
+
# RubyPitaya::StatusCodes::CODE_UNKNOWN = 'RP-000'
|
15
|
+
# RubyPitaya::StatusCodes::CODE_HANDLER_NOT_FOUNDED = 'RP-001'
|
16
|
+
# RubyPitaya::StatusCodes::CODE_ACTION_NOT_FOUNDED = 'RP-002'
|
17
|
+
# RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED = 'RP-003'
|
18
|
+
# RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR = 'RP-004'
|
19
|
+
#
|
20
|
+
# RubyPitaya::StatusCodes::Connector::CODE_UNKNOWN = 'PIT-000'
|
21
|
+
################
|
15
22
|
end
|
File without changes
|
File without changes
|
@@ -5,20 +5,26 @@ module RubyPitaya
|
|
5
5
|
class ApplicationFilesImporter
|
6
6
|
|
7
7
|
def import
|
8
|
-
|
8
|
+
@app_folder_paths = [Path::APP_FOLDER_PATH] + Path::Plugins::APP_FOLDER_PATHS
|
9
9
|
|
10
|
-
|
10
|
+
@app_folder_paths.each do |app_folder_path|
|
11
|
+
app_files_path = "#{app_folder_path}/**/*.rb"
|
12
|
+
|
13
|
+
Gem.find_files(app_files_path).each { |path| require path }
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
def auto_reload
|
14
18
|
require 'listen'
|
15
19
|
|
16
|
-
@
|
17
|
-
|
18
|
-
|
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
|
20
25
|
|
21
|
-
|
26
|
+
@app_files_listener.start
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
private
|
@@ -2,16 +2,17 @@ module RubyPitaya
|
|
2
2
|
|
3
3
|
class Config
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@configs_folder_path = configs_folder_path
|
7
|
-
|
8
|
-
path_to_all_files = File.join(@configs_folder_path, '**/*.json')
|
9
|
-
config_files = Dir.glob(path_to_all_files)
|
10
|
-
|
5
|
+
def initialize()
|
11
6
|
@config = {}
|
7
|
+
@configs_folder_paths = [Path::APP_CONFIG_FOLDER_PATH] + Path::Plugins::APP_CONFIG_FOLDER_PATHS
|
12
8
|
|
13
|
-
|
14
|
-
|
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
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -26,21 +27,23 @@ module RubyPitaya
|
|
26
27
|
def auto_reload
|
27
28
|
require 'listen'
|
28
29
|
|
29
|
-
@
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
35
|
|
34
|
-
|
36
|
+
config_files_listener.start
|
37
|
+
end
|
35
38
|
end
|
36
39
|
|
37
40
|
private
|
38
41
|
|
39
|
-
def load_config_file(file_path)
|
42
|
+
def load_config_file(configs_folder_path, file_path)
|
40
43
|
config_text = File.open(file_path, &:read)
|
41
44
|
config_hash = JSON.parse(config_text)
|
42
45
|
|
43
|
-
path_array = file_path.sub(/^#{
|
46
|
+
path_array = file_path.sub(/^#{configs_folder_path}/, '')[0..-6]
|
44
47
|
.split('/')
|
45
48
|
|
46
49
|
set_config_value(path_array, config_hash)
|
@@ -50,17 +53,17 @@ module RubyPitaya
|
|
50
53
|
puts error.backtrace
|
51
54
|
end
|
52
55
|
|
53
|
-
def import_added_files(files_path)
|
56
|
+
def import_added_files(configs_folder_path, files_path)
|
54
57
|
files_path.each do |path|
|
55
|
-
load_config_file(path)
|
58
|
+
load_config_file(configs_folder_path, path)
|
56
59
|
|
57
60
|
puts "ADDED config: #{path}"
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
61
|
-
def reload_modified_files(files_path)
|
64
|
+
def reload_modified_files(configs_folder_path, files_path)
|
62
65
|
files_path.each do |path|
|
63
|
-
load_config_file(path)
|
66
|
+
load_config_file(configs_folder_path, path)
|
64
67
|
|
65
68
|
puts "MODIFIED @config: #{path}"
|
66
69
|
end
|
@@ -75,7 +78,7 @@ module RubyPitaya
|
|
75
78
|
if is_last_index
|
76
79
|
config[key] = value
|
77
80
|
else
|
78
|
-
config[key] = {}
|
81
|
+
config[key] = {} unless config.key?(key)
|
79
82
|
config = config[key]
|
80
83
|
end
|
81
84
|
end
|
@@ -4,9 +4,15 @@ module RubyPitaya
|
|
4
4
|
|
5
5
|
class HandlerRouter
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize()
|
8
|
+
routes_path = Path::ROUTES_FILE_PATH
|
9
|
+
handler_folder_paths = [Path::HANDLERS_FOLDER_PATH] + Path::Plugins::HANDLERS_FOLDER_PATHS
|
10
|
+
|
8
11
|
import_routes_file(routes_path)
|
9
|
-
|
12
|
+
|
13
|
+
handler_folder_paths.each do |handler_folder_path|
|
14
|
+
import_handler_files(handler_folder_path)
|
15
|
+
end
|
10
16
|
|
11
17
|
import_routes_class
|
12
18
|
import_handler_classes
|
data/lib/rubypitaya/core/main.rb
CHANGED
@@ -8,6 +8,7 @@ require 'rubypitaya/core/session'
|
|
8
8
|
require 'rubypitaya/core/postman'
|
9
9
|
require 'rubypitaya/core/parameters'
|
10
10
|
require 'rubypitaya/core/routes_base'
|
11
|
+
require 'rubypitaya/core/status_codes'
|
11
12
|
require 'rubypitaya/core/handler_router'
|
12
13
|
require 'rubypitaya/core/etcd_connector'
|
13
14
|
require 'rubypitaya/core/nats_connector'
|
@@ -61,7 +62,7 @@ module RubyPitaya
|
|
61
62
|
|
62
63
|
@session = Session.new
|
63
64
|
@postman = Postman.new(@nats_connector)
|
64
|
-
@config = Config.new(
|
65
|
+
@config = Config.new()
|
65
66
|
@config.auto_reload if @is_development_environment
|
66
67
|
|
67
68
|
@bll = InstanceHolder.new
|
@@ -70,8 +71,7 @@ module RubyPitaya
|
|
70
71
|
@initializer_broadcast = InitializerBroadcast.new
|
71
72
|
@initializer_broadcast.run(@initializer_content)
|
72
73
|
|
73
|
-
@handler_router = HandlerRouter.new(
|
74
|
-
Path::ROUTES_FILE_PATH)
|
74
|
+
@handler_router = HandlerRouter.new()
|
75
75
|
|
76
76
|
run_server
|
77
77
|
end
|
data/lib/rubypitaya/core/path.rb
CHANGED
@@ -8,8 +8,16 @@ module RubyPitaya
|
|
8
8
|
APP_FOLDER_PATH = File.join(Dir.pwd, 'app/')
|
9
9
|
HANDLERS_FOLDER_PATH = File.join(Dir.pwd, 'app/handlers/')
|
10
10
|
APP_CONFIG_FOLDER_PATH = File.join(Dir.pwd, 'app/config/')
|
11
|
-
MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/
|
11
|
+
MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/migration/')
|
12
12
|
|
13
13
|
ROUTES_FILE_PATH = File.join(Dir.pwd, 'config/routes.rb')
|
14
|
+
|
15
|
+
|
16
|
+
class Plugins
|
17
|
+
APP_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/'))
|
18
|
+
HANDLERS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/handlers'))
|
19
|
+
APP_CONFIG_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/config/'))
|
20
|
+
MIGRATIONS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/db/migration'))
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
@@ -12,15 +12,14 @@ module RubyPitaya
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def connect
|
15
|
-
@redis = Redis.new(
|
15
|
+
@redis = Redis.new(
|
16
|
+
url: @redis_address,
|
17
|
+
:reconnect_attempts => 10,
|
18
|
+
:reconnect_delay => 1.5,
|
19
|
+
:reconnect_delay_max => 2.0,
|
20
|
+
)
|
16
21
|
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_connection
|
21
|
-
@redis.set('tmp', 'value')
|
22
|
-
@redis.get('tmp')
|
23
|
-
@redis.del('tmp')
|
22
|
+
@redis.ping
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RubyPitaya
|
2
|
+
|
3
|
+
class StatusCodes
|
4
|
+
# Success codes
|
5
|
+
CODE_OK = 'RP-200'
|
6
|
+
|
7
|
+
# Error codes
|
8
|
+
CODE_UNKNOWN = 'RP-000'
|
9
|
+
CODE_HANDLER_NOT_FOUNDED = 'RP-001'
|
10
|
+
CODE_ACTION_NOT_FOUNDED = 'RP-002'
|
11
|
+
CODE_NOT_AUTHENTICATED = 'RP-003'
|
12
|
+
CODE_AUTHENTICATION_ERROR = 'RP-004'
|
13
|
+
|
14
|
+
class Connector
|
15
|
+
CODE_UNKNOWN = 'PIT-000'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/rubypitaya/version.rb
CHANGED
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:
|
4
|
+
version: 2.0.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-
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -204,8 +204,8 @@ files:
|
|
204
204
|
- "./lib/rubypitaya/app-template/bin/console"
|
205
205
|
- "./lib/rubypitaya/app-template/config/database.yml"
|
206
206
|
- "./lib/rubypitaya/app-template/config/routes.rb"
|
207
|
-
- "./lib/rubypitaya/app-template/db/
|
208
|
-
- "./lib/rubypitaya/app-template/db/
|
207
|
+
- "./lib/rubypitaya/app-template/db/migration/001_create_user_migration.rb"
|
208
|
+
- "./lib/rubypitaya/app-template/db/migration/002_create_player_migration.rb"
|
209
209
|
- "./lib/rubypitaya/app-template/docker-compose.yml"
|
210
210
|
- "./lib/rubypitaya/app-template/docker/dev/Dockerfile"
|
211
211
|
- "./lib/rubypitaya/app-template/docker/entrypoint.sh"
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- "./lib/rubypitaya/core/redis_connector.rb"
|
245
245
|
- "./lib/rubypitaya/core/routes_base.rb"
|
246
246
|
- "./lib/rubypitaya/core/session.rb"
|
247
|
+
- "./lib/rubypitaya/core/status_codes.rb"
|
247
248
|
- "./lib/rubypitaya/version.rb"
|
248
249
|
- bin/rubypitaya
|
249
250
|
homepage: https://gitlab.com/LucianoPC/ruby-pitaya
|