rubypitaya 2.4.1 → 2.5.1
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 +8 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +11 -11
- data/lib/rubypitaya/app-template/Makefile +1 -1
- data/lib/rubypitaya/app-template/Rakefile +4 -0
- data/lib/rubypitaya/app-template/app/app_initializer.rb +6 -0
- data/lib/rubypitaya/app-template/app/bll/player_bll.rb +3 -2
- data/lib/rubypitaya/app-template/app/constants/status_codes.rb +2 -2
- data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +4 -4
- data/lib/rubypitaya/app-template/app/http/hello_world.rb +27 -0
- data/lib/rubypitaya/app-template/app/http/views/hello_world.erb +1 -0
- data/lib/rubypitaya/app-template/app/models/player.rb +2 -1
- data/lib/rubypitaya/app-template/app/setup/initial_player.yml +2 -0
- data/lib/rubypitaya/app-template/config/database.yml +2 -4
- data/lib/rubypitaya/app-template/db/migration/0000000002_create_player_migration.rb +1 -0
- data/lib/rubypitaya/app-template/docker-compose.yml +7 -1
- data/lib/rubypitaya/core/handler_base.rb +2 -1
- data/lib/rubypitaya/core/handler_router.rb +5 -4
- data/lib/rubypitaya/core/http_routes.rb +26 -0
- data/lib/rubypitaya/core/initializer_content.rb +2 -1
- data/lib/rubypitaya/core/main.rb +19 -1
- data/lib/rubypitaya/core/path.rb +5 -0
- data/lib/rubypitaya/core/setup.rb +96 -0
- data/lib/rubypitaya/core/status_codes.rb +2 -2
- data/lib/rubypitaya/version.rb +1 -1
- metadata +35 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84f3bb326f6529e6952dceb0f93ac795cfb862cd7661dd14c7d9714296094e6e
|
4
|
+
data.tar.gz: 0c731e2b492a3392cb8ffc58999e407229ba9283af9f3ac425a864651f703678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f231eed02e593db2e16890cdba291d99ed58a48358c00b5e0bbd9d7136da0e76d21c532028b9133bf77478130978c2c6233cc212b577d6985d2d1b06a81363e6
|
7
|
+
data.tar.gz: e3d32e830dc6a436a06a549ebd428dd004facbbd45cd0fb3107a34a8d01e48ef4da127eae55035989b941a997fc7da7d3d37a93e10973aedc80dbfe5a4ee637a
|
@@ -13,26 +13,26 @@ GEM
|
|
13
13
|
tzinfo (~> 1.1)
|
14
14
|
zeitwerk (~> 2.2)
|
15
15
|
coderay (1.1.2)
|
16
|
-
concurrent-ruby (1.1.
|
16
|
+
concurrent-ruby (1.1.7)
|
17
17
|
diff-lcs (1.3)
|
18
18
|
etcdv3 (0.10.2)
|
19
19
|
grpc (~> 1.17)
|
20
20
|
eventmachine (1.2.7)
|
21
21
|
ffi (1.12.2)
|
22
|
-
google-protobuf (3.
|
22
|
+
google-protobuf (3.13.0)
|
23
23
|
googleapis-common-protos-types (1.0.5)
|
24
24
|
google-protobuf (~> 3.11)
|
25
|
-
grpc (1.
|
26
|
-
google-protobuf (~> 3.
|
25
|
+
grpc (1.32.0)
|
26
|
+
google-protobuf (~> 3.13)
|
27
27
|
googleapis-common-protos-types (~> 1.0)
|
28
|
-
i18n (1.8.
|
28
|
+
i18n (1.8.5)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
30
|
listen (3.2.1)
|
31
31
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
32
32
|
rb-inotify (~> 0.9, >= 0.9.10)
|
33
33
|
method_source (0.9.2)
|
34
34
|
middleware (0.1.0)
|
35
|
-
minitest (5.14.
|
35
|
+
minitest (5.14.2)
|
36
36
|
nats (0.11.0)
|
37
37
|
eventmachine (~> 1.2, >= 1.2)
|
38
38
|
pg (0.21.0)
|
@@ -62,19 +62,20 @@ 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.
|
65
|
+
rubypitaya (2.5.1)
|
66
66
|
activerecord (= 6.0.2)
|
67
67
|
etcdv3 (= 0.10.2)
|
68
68
|
eventmachine (= 1.2.7)
|
69
69
|
nats (= 0.11.0)
|
70
70
|
pg (= 0.21.0)
|
71
71
|
protobuf (= 3.10.0)
|
72
|
+
rake (= 10.0)
|
72
73
|
redis (= 4.1.3)
|
73
74
|
thor (1.0.1)
|
74
75
|
thread_safe (0.3.6)
|
75
|
-
tzinfo (1.2.
|
76
|
+
tzinfo (1.2.8)
|
76
77
|
thread_safe (~> 0.1)
|
77
|
-
zeitwerk (2.
|
78
|
+
zeitwerk (2.4.1)
|
78
79
|
|
79
80
|
PLATFORMS
|
80
81
|
ruby
|
@@ -83,9 +84,8 @@ DEPENDENCIES
|
|
83
84
|
bundler (= 1.17.2)
|
84
85
|
listen (= 3.2.1)
|
85
86
|
pry (= 0.12.2)
|
86
|
-
rake (= 10.0)
|
87
87
|
rspec (= 3.8.0)
|
88
|
-
rubypitaya (= 2.
|
88
|
+
rubypitaya (= 2.5.1)
|
89
89
|
|
90
90
|
BUNDLED WITH
|
91
91
|
1.17.2
|
@@ -16,7 +16,7 @@ test:
|
|
16
16
|
|
17
17
|
## Run ruby irb console
|
18
18
|
console:
|
19
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec ruby ./bin/console
|
19
|
+
@docker-compose run --service-ports --rm rubypitaya-console bundle exec ruby ./bin/console
|
20
20
|
|
21
21
|
## Run bash on container
|
22
22
|
bash:
|
@@ -40,6 +40,9 @@ namespace :db do
|
|
40
40
|
environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
|
41
41
|
database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
|
42
42
|
connection_data = database_config.connection_data
|
43
|
+
migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
|
44
|
+
migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
|
45
|
+
migrations_paths += [RubyPitaya::Path::MIGRATIONS_FOLDER_PATH]
|
43
46
|
|
44
47
|
step = ENV["STEP"] ? ENV["STEP"].to_i : 1
|
45
48
|
|
@@ -51,6 +54,7 @@ namespace :db do
|
|
51
54
|
end
|
52
55
|
|
53
56
|
ActiveRecord::Base.establish_connection(connection_data)
|
57
|
+
ActiveRecord::Migrator.migrations_paths = migrations_paths
|
54
58
|
ActiveRecord::Base.connection.migration_context.rollback(step)
|
55
59
|
ActiveRecord::Base.connection.close
|
56
60
|
|
@@ -19,6 +19,12 @@ class AppInitializer < RubyPitaya::InitializerBase
|
|
19
19
|
# - methods:
|
20
20
|
# - [](key)
|
21
21
|
# - get config file by config path
|
22
|
+
# - setup
|
23
|
+
# - class: RubyPitaya::Setup
|
24
|
+
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/setup.rb
|
25
|
+
# - methods:
|
26
|
+
# - [](key)
|
27
|
+
# - get config file by config path
|
22
28
|
|
23
29
|
def run(initializer_content)
|
24
30
|
bll = initializer_content.bll
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class PlayerBLL
|
2
2
|
|
3
|
-
def create_new_player(config)
|
3
|
+
def create_new_player(setup, config)
|
4
4
|
name = config['initial_player']['name']
|
5
|
+
gold = setup['initial_player.wallet.gold']
|
5
6
|
|
6
|
-
player = Player.new(name: name, user: User.new)
|
7
|
+
player = Player.new(name: name, gold: gold, user: User.new)
|
7
8
|
player.save
|
8
9
|
player
|
9
10
|
end
|
@@ -12,8 +12,8 @@ class StatusCodes
|
|
12
12
|
#
|
13
13
|
## Error codes
|
14
14
|
# RubyPitaya::StatusCodes::CODE_UNKNOWN = 'RP-000'
|
15
|
-
# RubyPitaya::StatusCodes::
|
16
|
-
# RubyPitaya::StatusCodes::
|
15
|
+
# RubyPitaya::StatusCodes::CODE_HANDLER_NOT_FOUND = 'RP-001'
|
16
|
+
# RubyPitaya::StatusCodes::CODE_ACTION_NOT_FOUND = 'RP-002'
|
17
17
|
# RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED = 'RP-003'
|
18
18
|
# RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR = 'RP-004'
|
19
19
|
#
|
@@ -47,7 +47,7 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
47
47
|
user_id = @params[:userId]
|
48
48
|
|
49
49
|
player = Player.find_by_user_id(user_id)
|
50
|
-
player = @bll[:player].create_new_player(@config) if player.nil?
|
50
|
+
player = @bll[:player].create_new_player(@setup, @config) if player.nil?
|
51
51
|
|
52
52
|
@session.uid = player.user_id
|
53
53
|
|
@@ -55,14 +55,14 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
55
55
|
|
56
56
|
unless bind_session_response.dig(:error, :code).nil?
|
57
57
|
return response = {
|
58
|
-
code: StatusCodes::CODE_AUTHENTICATION_ERROR,
|
58
|
+
code: RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR,
|
59
59
|
msg: 'Error to authenticate',
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
63
63
|
response = {
|
64
64
|
code: StatusCodes::CODE_OK,
|
65
|
-
|
65
|
+
data: player.to_hash,
|
66
66
|
}
|
67
67
|
end
|
68
68
|
|
@@ -73,7 +73,7 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
73
73
|
|
74
74
|
response = {
|
75
75
|
code: StatusCodes::CODE_OK,
|
76
|
-
|
76
|
+
data: player.to_hash,
|
77
77
|
}
|
78
78
|
end
|
79
79
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubypitaya/core/http_routes'
|
2
|
+
|
3
|
+
RubyPitaya::HttpRoutes.class_eval do
|
4
|
+
|
5
|
+
get '/hello-world/html' do
|
6
|
+
content_type 'text/html'
|
7
|
+
|
8
|
+
@message = "Hello World"
|
9
|
+
|
10
|
+
erb :hello_world
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/hello-world/json' do
|
14
|
+
response = {
|
15
|
+
message: 'Hello World!'
|
16
|
+
}.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def response_error(message)
|
22
|
+
response = {
|
23
|
+
code: StatusCodes::CODE_ERROR,
|
24
|
+
message: message,
|
25
|
+
}.to_json
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h3><%= @message %></h3>
|
@@ -8,7 +8,7 @@ default: &default
|
|
8
8
|
|
9
9
|
development:
|
10
10
|
<<: *default
|
11
|
-
database: <%= "#{ENV['DATABASE_NAME']}
|
11
|
+
database: <%= "#{ENV['DATABASE_NAME']}" %>
|
12
12
|
|
13
13
|
test:
|
14
14
|
<<: *default
|
@@ -16,7 +16,5 @@ test:
|
|
16
16
|
|
17
17
|
production:
|
18
18
|
<<: *default
|
19
|
-
database: <%= "#{ENV['DATABASE_NAME']}
|
20
|
-
# username: rails_project
|
21
|
-
# password: <%= ENV['RAILS_PROJECT_DATABASE_PASSWORD'] %>
|
19
|
+
database: <%= "#{ENV['DATABASE_NAME']}" %>
|
22
20
|
|
@@ -43,7 +43,7 @@ services:
|
|
43
43
|
PITAYA_CLUSTER_SD_ETCD_PREFIX: 'rubypitaya/'
|
44
44
|
SERVER_ROUTES: 'rubypitaya'
|
45
45
|
|
46
|
-
rubypitaya:
|
46
|
+
rubypitaya: &rubypitaya
|
47
47
|
depends_on:
|
48
48
|
- 'db'
|
49
49
|
- 'nats'
|
@@ -56,6 +56,8 @@ services:
|
|
56
56
|
working_dir: '/app/rubypitaya'
|
57
57
|
volumes:
|
58
58
|
- '.:/app/rubypitaya'
|
59
|
+
ports:
|
60
|
+
- '80:4567'
|
59
61
|
environment:
|
60
62
|
SERVER_NAME: 'rubypitaya'
|
61
63
|
RUBYPITAYA_ENV: 'development'
|
@@ -70,5 +72,9 @@ services:
|
|
70
72
|
DATABASE_PASSWORD: 'postgres'
|
71
73
|
DATABASE_NAME: 'ruby_pitaya'
|
72
74
|
|
75
|
+
rubypitaya-console:
|
76
|
+
<<: *rubypitaya
|
77
|
+
ports: []
|
78
|
+
|
73
79
|
volumes:
|
74
80
|
postgres:
|
@@ -4,11 +4,12 @@ module RubyPitaya
|
|
4
4
|
|
5
5
|
class_attribute :non_authenticated_routes, default: []
|
6
6
|
|
7
|
-
attr_accessor :bll, :redis, :config, :params, :session, :postman
|
7
|
+
attr_accessor :bll, :redis, :setup, :config, :params, :session, :postman
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@bll = nil
|
11
11
|
@redis = nil
|
12
|
+
@setup = nil
|
12
13
|
@config = nil
|
13
14
|
@params = nil
|
14
15
|
@session = nil
|
@@ -52,18 +52,18 @@ module RubyPitaya
|
|
52
52
|
@handler_name_map = @handler_name_map.to_h
|
53
53
|
end
|
54
54
|
|
55
|
-
def call(handler_name, action_name, session, postman, redis,
|
56
|
-
|
55
|
+
def call(handler_name, action_name, session, postman, redis, setup, config,
|
56
|
+
bll, params)
|
57
57
|
unless @handler_name_map.include?(handler_name)
|
58
58
|
return {
|
59
|
-
code: StatusCodes::
|
59
|
+
code: StatusCodes::CODE_HANDLER_NOT_FOUND,
|
60
60
|
msg: "Handler #{handler_name} not founded"
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
64
64
|
unless @handler_name_map[handler_name].methods.include?(action_name.to_sym)
|
65
65
|
return {
|
66
|
-
code: StatusCodes::
|
66
|
+
code: StatusCodes::CODE_ACTION_NOT_FOUND,
|
67
67
|
msg: "Handler #{handler_name} action #{action_name} not founded"
|
68
68
|
}
|
69
69
|
end
|
@@ -72,6 +72,7 @@ module RubyPitaya
|
|
72
72
|
|
73
73
|
handler.bll = bll
|
74
74
|
handler.redis = redis
|
75
|
+
handler.setup = setup
|
75
76
|
handler.config = config
|
76
77
|
handler.params = params
|
77
78
|
handler.session = session
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra/reloader' if ENV['RUBYPITAYA_ENV'] == 'development'
|
3
|
+
require 'rubypitaya/core/parameters'
|
4
|
+
|
5
|
+
module RubyPitaya
|
6
|
+
|
7
|
+
class HttpRoutes < Sinatra::Base
|
8
|
+
|
9
|
+
if ENV['RUBYPITAYA_ENV'] == 'development'
|
10
|
+
register Sinatra::Reloader
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
content_type :json
|
15
|
+
|
16
|
+
@bll = settings.bll
|
17
|
+
@setup = settings.setup
|
18
|
+
@config = settings.config
|
19
|
+
|
20
|
+
request_body = request.body.read
|
21
|
+
@params.merge!(JSON.parse(request_body)) if !request_body.blank?
|
22
|
+
|
23
|
+
@params = Parameters.new(@params)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rubypitaya/core/main.rb
CHANGED
@@ -3,6 +3,7 @@ require 'securerandom'
|
|
3
3
|
require 'active_model'
|
4
4
|
|
5
5
|
require 'rubypitaya/core/path'
|
6
|
+
require 'rubypitaya/core/setup'
|
6
7
|
require 'rubypitaya/core/config'
|
7
8
|
require 'rubypitaya/core/session'
|
8
9
|
require 'rubypitaya/core/postman'
|
@@ -64,22 +65,39 @@ module RubyPitaya
|
|
64
65
|
@postman = Postman.new(@nats_connector)
|
65
66
|
@config = Config.new
|
66
67
|
@config.auto_reload if @is_development_environment
|
68
|
+
@setup = Setup.new
|
69
|
+
@setup.auto_reload if @is_development_environment
|
67
70
|
|
68
71
|
@bll = InstanceHolder.new
|
69
72
|
|
70
73
|
@initializer_content = InitializerContent.new(@bll,
|
71
74
|
@redis_connector.redis,
|
75
|
+
@setup,
|
72
76
|
@config)
|
73
77
|
@initializer_broadcast = InitializerBroadcast.new
|
74
78
|
@initializer_broadcast.run(@initializer_content)
|
75
79
|
|
76
80
|
@handler_router = HandlerRouter.new()
|
77
81
|
|
82
|
+
run_http
|
78
83
|
run_server
|
79
84
|
end
|
80
85
|
|
81
86
|
private
|
82
87
|
|
88
|
+
def run_http
|
89
|
+
HttpRoutes.set :bll, @bll
|
90
|
+
HttpRoutes.set :setup, @setup
|
91
|
+
HttpRoutes.set :config, @config
|
92
|
+
HttpRoutes.set :views, [Path::HTTP_VIEWS_PATH] + Path::Plugins::APP_CONFIG_FOLDER_PATHS;
|
93
|
+
|
94
|
+
Thread.new do
|
95
|
+
HttpRoutes.bind = '0.0.0.0'
|
96
|
+
HttpRoutes.port = '4567'
|
97
|
+
HttpRoutes.run!
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
83
101
|
def run_server
|
84
102
|
@is_shutting_down = false
|
85
103
|
|
@@ -139,7 +157,7 @@ module RubyPitaya
|
|
139
157
|
|
140
158
|
response = @handler_router.call(handler_name, action_name, @session,
|
141
159
|
@postman, @redis_connector.redis,
|
142
|
-
@config, @bll, params)
|
160
|
+
@setup, @config, @bll, params)
|
143
161
|
|
144
162
|
delta_time_seconds = Time.now.to_i - start_time_seconds
|
145
163
|
|
data/lib/rubypitaya/core/path.rb
CHANGED
@@ -8,10 +8,13 @@ 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
|
+
APP_SETUP_FOLDER_PATH = File.join(Dir.pwd, 'app/setup/')
|
11
12
|
MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/migration/')
|
12
13
|
|
13
14
|
ROUTES_FILE_PATH = File.join(Dir.pwd, 'config/routes.rb')
|
14
15
|
|
16
|
+
HTTP_VIEWS_PATH = File.join(Dir.pwd, 'app/http/views')
|
17
|
+
|
15
18
|
class Core
|
16
19
|
APP_FOLDER_PATH = File.join(__dir__, 'app/')
|
17
20
|
MIGRATIONS_FOLDER_PATH = File.join(__dir__, 'db/migration/')
|
@@ -21,7 +24,9 @@ module RubyPitaya
|
|
21
24
|
APP_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/'))
|
22
25
|
HANDLERS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/handlers'))
|
23
26
|
APP_CONFIG_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/config/'))
|
27
|
+
APP_SETUP_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/setup/'))
|
24
28
|
MIGRATIONS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/db/migration'))
|
29
|
+
HTTP_VIEWS_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/http/views'))
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module RubyPitaya
|
2
|
+
|
3
|
+
class Setup
|
4
|
+
|
5
|
+
def initialize()
|
6
|
+
@config = {}
|
7
|
+
configs_folder_paths = Path::Plugins::APP_SETUP_FOLDER_PATHS + [Path::APP_SETUP_FOLDER_PATH]
|
8
|
+
|
9
|
+
configs_folder_paths.each do |configs_folder_path|
|
10
|
+
path_to_all_files = File.join(configs_folder_path, '**/*.yml')
|
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
|
+
result = get_config_from_env_var(key)
|
21
|
+
return result unless result.nil?
|
22
|
+
|
23
|
+
split_key = key.split('.')
|
24
|
+
@config.dig(*split_key)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_config_from_env_var(key)
|
28
|
+
env_key = key.gsub('.', '_').upcase
|
29
|
+
ENV.fetch(env_key) { nil }
|
30
|
+
end
|
31
|
+
|
32
|
+
def auto_reload
|
33
|
+
require 'listen'
|
34
|
+
|
35
|
+
configs_folder_path = Path::APP_CONFIG_FOLDER_PATH
|
36
|
+
|
37
|
+
config_files_listener = Listen.to(configs_folder_path,
|
38
|
+
only: /\.yml$/,
|
39
|
+
force_polling: true,
|
40
|
+
latency: 0.25,
|
41
|
+
wait_for_delay: 0.1) do |modified, added, removed|
|
42
|
+
import_added_files(configs_folder_path, added)
|
43
|
+
reload_modified_files(configs_folder_path, modified)
|
44
|
+
end
|
45
|
+
|
46
|
+
config_files_listener.start
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def load_config_file(configs_folder_path, file_path)
|
52
|
+
config_text = File.open(file_path, &:read)
|
53
|
+
config_hash = YAML.load(ERB.new(config_text).result)
|
54
|
+
|
55
|
+
path_array = file_path.sub(/^#{configs_folder_path}/, '')[0..-5]
|
56
|
+
.split('/')
|
57
|
+
|
58
|
+
set_config_value(path_array, config_hash)
|
59
|
+
|
60
|
+
rescue Exception => error
|
61
|
+
puts "ERROR: #{error}"
|
62
|
+
puts error.backtrace
|
63
|
+
end
|
64
|
+
|
65
|
+
def import_added_files(configs_folder_path, files_path)
|
66
|
+
files_path.each do |path|
|
67
|
+
load_config_file(configs_folder_path, path)
|
68
|
+
|
69
|
+
puts "ADDED config: #{path}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def reload_modified_files(configs_folder_path, files_path)
|
74
|
+
files_path.each do |path|
|
75
|
+
load_config_file(configs_folder_path, path)
|
76
|
+
|
77
|
+
puts "MODIFIED @config: #{path}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_config_value(keys, value)
|
82
|
+
config = @config
|
83
|
+
|
84
|
+
keys.each_with_index do |key, index|
|
85
|
+
is_last_index = index == keys.size - 1
|
86
|
+
|
87
|
+
if is_last_index
|
88
|
+
config[key] = value
|
89
|
+
else
|
90
|
+
config[key] = {} unless config.key?(key)
|
91
|
+
config = config[key]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -6,8 +6,8 @@ module RubyPitaya
|
|
6
6
|
|
7
7
|
# Error codes
|
8
8
|
CODE_UNKNOWN = 'RP-000'
|
9
|
-
|
10
|
-
|
9
|
+
CODE_HANDLER_NOT_FOUND = 'RP-001'
|
10
|
+
CODE_ACTION_NOT_FOUND = 'RP-002'
|
11
11
|
CODE_NOT_AUTHENTICATED = 'RP-003'
|
12
12
|
CODE_AUTHENTICATION_ERROR = 'RP-004'
|
13
13
|
|
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: 2.
|
4
|
+
version: 2.5.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-11-
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.10.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sinatra
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.1.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra-contrib
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.1.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.1.0
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: protobuf
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,8 +227,11 @@ files:
|
|
199
227
|
- "./lib/rubypitaya/app-template/app/constants/status_codes.rb"
|
200
228
|
- "./lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb"
|
201
229
|
- "./lib/rubypitaya/app-template/app/handlers/player_handler.rb"
|
230
|
+
- "./lib/rubypitaya/app-template/app/http/hello_world.rb"
|
231
|
+
- "./lib/rubypitaya/app-template/app/http/views/hello_world.erb"
|
202
232
|
- "./lib/rubypitaya/app-template/app/models/player.rb"
|
203
233
|
- "./lib/rubypitaya/app-template/app/models/user.rb"
|
234
|
+
- "./lib/rubypitaya/app-template/app/setup/initial_player.yml"
|
204
235
|
- "./lib/rubypitaya/app-template/bin/console"
|
205
236
|
- "./lib/rubypitaya/app-template/config/database.yml"
|
206
237
|
- "./lib/rubypitaya/app-template/config/routes.rb"
|
@@ -234,6 +265,7 @@ files:
|
|
234
265
|
- "./lib/rubypitaya/core/etcd_connector.rb"
|
235
266
|
- "./lib/rubypitaya/core/handler_base.rb"
|
236
267
|
- "./lib/rubypitaya/core/handler_router.rb"
|
268
|
+
- "./lib/rubypitaya/core/http_routes.rb"
|
237
269
|
- "./lib/rubypitaya/core/initializer_base.rb"
|
238
270
|
- "./lib/rubypitaya/core/initializer_broadcast.rb"
|
239
271
|
- "./lib/rubypitaya/core/initializer_content.rb"
|
@@ -246,6 +278,7 @@ files:
|
|
246
278
|
- "./lib/rubypitaya/core/redis_connector.rb"
|
247
279
|
- "./lib/rubypitaya/core/routes_base.rb"
|
248
280
|
- "./lib/rubypitaya/core/session.rb"
|
281
|
+
- "./lib/rubypitaya/core/setup.rb"
|
249
282
|
- "./lib/rubypitaya/core/status_codes.rb"
|
250
283
|
- "./lib/rubypitaya/version.rb"
|
251
284
|
- bin/rubypitaya
|