rubypitaya 2.5.0 → 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 +1 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
- 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/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 +3 -26
- 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 +1 -0
- data/lib/rubypitaya/core/initializer_content.rb +2 -1
- data/lib/rubypitaya/core/main.rb +6 -1
- data/lib/rubypitaya/core/path.rb +2 -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 +4 -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
|
@@ -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.5.
|
65
|
+
rubypitaya (2.5.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
|
listen (= 3.2.1)
|
86
86
|
pry (= 0.12.2)
|
87
87
|
rspec (= 3.8.0)
|
88
|
-
rubypitaya (= 2.5.
|
88
|
+
rubypitaya (= 2.5.1)
|
89
89
|
|
90
90
|
BUNDLED WITH
|
91
91
|
1.17.2
|
@@ -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
|
@@ -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'
|
@@ -73,31 +73,8 @@ services:
|
|
73
73
|
DATABASE_NAME: 'ruby_pitaya'
|
74
74
|
|
75
75
|
rubypitaya-console:
|
76
|
-
|
77
|
-
|
78
|
-
- 'nats'
|
79
|
-
- 'etcd'
|
80
|
-
- 'redis'
|
81
|
-
- 'connector'
|
82
|
-
build:
|
83
|
-
context: '.'
|
84
|
-
dockerfile: 'docker/dev/Dockerfile'
|
85
|
-
working_dir: '/app/rubypitaya'
|
86
|
-
volumes:
|
87
|
-
- '.:/app/rubypitaya'
|
88
|
-
environment:
|
89
|
-
SERVER_NAME: 'rubypitaya'
|
90
|
-
RUBYPITAYA_ENV: 'development'
|
91
|
-
HISTFILE: '/app/rubypitaya/.bash-history'
|
92
|
-
NATS_URL: 'nats://nats:4222'
|
93
|
-
ETCD_URL: 'http://etcd:2379'
|
94
|
-
ETCD_PREFIX: 'rubypitaya/'
|
95
|
-
ETCD_LEASE_SECONDS: '60'
|
96
|
-
REDIS_URL: 'redis://redis:6379'
|
97
|
-
DATABASE_HOST: 'db'
|
98
|
-
DATABASE_USER: 'postgres'
|
99
|
-
DATABASE_PASSWORD: 'postgres'
|
100
|
-
DATABASE_NAME: 'ruby_pitaya'
|
76
|
+
<<: *rubypitaya
|
77
|
+
ports: []
|
101
78
|
|
102
79
|
volumes:
|
103
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
|
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,11 +65,14 @@ 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)
|
@@ -83,6 +87,7 @@ module RubyPitaya
|
|
83
87
|
|
84
88
|
def run_http
|
85
89
|
HttpRoutes.set :bll, @bll
|
90
|
+
HttpRoutes.set :setup, @setup
|
86
91
|
HttpRoutes.set :config, @config
|
87
92
|
HttpRoutes.set :views, [Path::HTTP_VIEWS_PATH] + Path::Plugins::APP_CONFIG_FOLDER_PATHS;
|
88
93
|
|
@@ -152,7 +157,7 @@ module RubyPitaya
|
|
152
157
|
|
153
158
|
response = @handler_router.call(handler_name, action_name, @session,
|
154
159
|
@postman, @redis_connector.redis,
|
155
|
-
@config, @bll, params)
|
160
|
+
@setup, @config, @bll, params)
|
156
161
|
|
157
162
|
delta_time_seconds = Time.now.to_i - start_time_seconds
|
158
163
|
|
data/lib/rubypitaya/core/path.rb
CHANGED
@@ -8,6 +8,7 @@ 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')
|
@@ -23,6 +24,7 @@ module RubyPitaya
|
|
23
24
|
APP_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/'))
|
24
25
|
HANDLERS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/handlers'))
|
25
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/'))
|
26
28
|
MIGRATIONS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/db/migration'))
|
27
29
|
HTTP_VIEWS_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/http/views'))
|
28
30
|
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.5.
|
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
|
@@ -231,6 +231,7 @@ files:
|
|
231
231
|
- "./lib/rubypitaya/app-template/app/http/views/hello_world.erb"
|
232
232
|
- "./lib/rubypitaya/app-template/app/models/player.rb"
|
233
233
|
- "./lib/rubypitaya/app-template/app/models/user.rb"
|
234
|
+
- "./lib/rubypitaya/app-template/app/setup/initial_player.yml"
|
234
235
|
- "./lib/rubypitaya/app-template/bin/console"
|
235
236
|
- "./lib/rubypitaya/app-template/config/database.yml"
|
236
237
|
- "./lib/rubypitaya/app-template/config/routes.rb"
|
@@ -277,6 +278,7 @@ files:
|
|
277
278
|
- "./lib/rubypitaya/core/redis_connector.rb"
|
278
279
|
- "./lib/rubypitaya/core/routes_base.rb"
|
279
280
|
- "./lib/rubypitaya/core/session.rb"
|
281
|
+
- "./lib/rubypitaya/core/setup.rb"
|
280
282
|
- "./lib/rubypitaya/core/status_codes.rb"
|
281
283
|
- "./lib/rubypitaya/version.rb"
|
282
284
|
- bin/rubypitaya
|