rubypitaya 3.5.0 → 3.6.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/Rakefile +6 -5
- data/lib/rubypitaya/app-template/app/app_initializer.rb +8 -6
- data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +9 -5
- data/lib/rubypitaya/app-template/app/setup/rubypitaya.yml +0 -1
- data/lib/rubypitaya/app-template/features/step_definitions/rubypitaya_steps.rb +1 -0
- data/lib/rubypitaya/app-template/features/support/env.rb +8 -2
- data/lib/rubypitaya/app-template/spec/player_handler_spec.rb +6 -6
- data/lib/rubypitaya/app-template/spec/redis_service_spec.rb +19 -0
- data/lib/rubypitaya/core/app/services/mongo_service.rb +35 -0
- data/lib/rubypitaya/core/{redis_service.rb → app/services/redis_service.rb} +0 -2
- data/lib/rubypitaya/core/database_config.rb +9 -9
- data/lib/rubypitaya/core/database_connector.rb +6 -4
- data/lib/rubypitaya/core/handler_base.rb +1 -2
- data/lib/rubypitaya/core/handler_router.rb +3 -3
- data/lib/rubypitaya/core/helpers/setup_helper.rb +2 -3
- data/lib/rubypitaya/core/http_routes.rb +0 -1
- data/lib/rubypitaya/core/initializer_content.rb +2 -3
- data/lib/rubypitaya/core/main.rb +4 -19
- data/lib/rubypitaya/core/session.rb +8 -0
- data/lib/rubypitaya/core/setup.rb +4 -0
- data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +11 -1
- data/lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb +33 -25
- data/lib/rubypitaya/core/spec-helpers/rubypitaya_spec_helper.rb +9 -0
- data/lib/rubypitaya/core/spec-helpers/setup_spec_helper.rb +22 -4
- data/lib/rubypitaya/version.rb +1 -1
- metadata +5 -4
- data/lib/rubypitaya/core/mongo_connector.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a36b3ecb6147501bf5c3da00bfefa546c597e96e4520695d785d9dd7719d951e
|
4
|
+
data.tar.gz: 7517fb91a57fb3c9d4d53811c2a8c564e09bac59daee1a4cb231d17b31f45df6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4867c9c3420c29630326c79fe12eaa77865e12277af909a7b3be2ef3ed3e0d813f2f735ddc4fdadc113e337d18bb7ef2d1a516ca171db2db1d6e5cafe0ecf8a
|
7
|
+
data.tar.gz: 819bba7c9f059c09470b92082501cfe4355c3bba85f9ce62f348a39d1057272a22ad6f08867ecf3df0163430e8996994c1fbf40776f15713318612f305d7e775
|
@@ -99,7 +99,7 @@ GEM
|
|
99
99
|
rspec-support (~> 3.11.0)
|
100
100
|
rspec-support (3.11.0)
|
101
101
|
ruby2_keywords (0.0.5)
|
102
|
-
rubypitaya (3.
|
102
|
+
rubypitaya (3.6.0)
|
103
103
|
activerecord (= 7.0.2)
|
104
104
|
etcdv3 (= 0.11.5)
|
105
105
|
google-protobuf (= 3.19.4)
|
@@ -138,7 +138,7 @@ DEPENDENCIES
|
|
138
138
|
listen (= 3.7.1)
|
139
139
|
pry (= 0.14.1)
|
140
140
|
rspec (= 3.11.0)
|
141
|
-
rubypitaya (= 3.
|
141
|
+
rubypitaya (= 3.6.0)
|
142
142
|
sinatra-contrib (= 2.1.0)
|
143
143
|
|
144
144
|
BUNDLED WITH
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
require 'rubypitaya/core/path'
|
4
|
+
require 'rubypitaya/core/setup'
|
4
5
|
require 'rubypitaya/core/database_config'
|
5
6
|
|
6
7
|
|
@@ -8,7 +9,7 @@ namespace :db do
|
|
8
9
|
|
9
10
|
desc 'Create the database'
|
10
11
|
task :create do
|
11
|
-
database_config = RubyPitaya::DatabaseConfig.new
|
12
|
+
database_config = RubyPitaya::DatabaseConfig.new(RubyPitaya::Setup.new)
|
12
13
|
connection_data = database_config.connection_data_without_database
|
13
14
|
|
14
15
|
ActiveRecord::Base.establish_connection(connection_data)
|
@@ -20,7 +21,7 @@ namespace :db do
|
|
20
21
|
|
21
22
|
desc 'Migrate the database'
|
22
23
|
task :migrate do
|
23
|
-
database_config = RubyPitaya::DatabaseConfig.new
|
24
|
+
database_config = RubyPitaya::DatabaseConfig.new(RubyPitaya::Setup.new)
|
24
25
|
connection_data = database_config.connection_data
|
25
26
|
migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
|
26
27
|
migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
|
@@ -36,7 +37,7 @@ namespace :db do
|
|
36
37
|
|
37
38
|
desc 'Rollback migrations'
|
38
39
|
task :rollback do
|
39
|
-
database_config = RubyPitaya::DatabaseConfig.new
|
40
|
+
database_config = RubyPitaya::DatabaseConfig.new(RubyPitaya::Setup.new)
|
40
41
|
connection_data = database_config.connection_data
|
41
42
|
migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
|
42
43
|
migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
|
@@ -61,7 +62,7 @@ namespace :db do
|
|
61
62
|
|
62
63
|
desc 'Drop the database'
|
63
64
|
task :drop do
|
64
|
-
database_config = RubyPitaya::DatabaseConfig.new
|
65
|
+
database_config = RubyPitaya::DatabaseConfig.new(RubyPitaya::Setup.new)
|
65
66
|
connection_data = database_config.connection_data_without_database
|
66
67
|
|
67
68
|
ActiveRecord::Base.establish_connection(connection_data)
|
@@ -74,7 +75,7 @@ namespace :db do
|
|
74
75
|
|
75
76
|
desc 'migration status'
|
76
77
|
task :status do
|
77
|
-
database_config = RubyPitaya::DatabaseConfig.new
|
78
|
+
database_config = RubyPitaya::DatabaseConfig.new(RubyPitaya::Setup.new)
|
78
79
|
connection_data = database_config.connection_data
|
79
80
|
migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
|
80
81
|
migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'rubypitaya/core/
|
1
|
+
require 'rubypitaya/core/app/services/mongo_service'
|
2
|
+
require 'rubypitaya/core/app/services/redis_service'
|
2
3
|
|
3
4
|
class AppInitializer < RubyPitaya::InitializerBase
|
4
5
|
|
@@ -8,10 +9,6 @@ class AppInitializer < RubyPitaya::InitializerBase
|
|
8
9
|
# - services
|
9
10
|
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/service_holder.rb
|
10
11
|
#
|
11
|
-
# - mongo
|
12
|
-
# - class: Mongo::Client
|
13
|
-
# - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
|
14
|
-
#
|
15
12
|
# - config
|
16
13
|
# - class: RubyPitaya::Config
|
17
14
|
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
|
@@ -30,15 +27,20 @@ class AppInitializer < RubyPitaya::InitializerBase
|
|
30
27
|
# - methods:
|
31
28
|
# - info
|
32
29
|
# - log information
|
33
|
-
|
30
|
+
#
|
34
31
|
# services:
|
35
32
|
# - redis
|
36
33
|
# - link: https://github.com/redis/redis-rb/
|
34
|
+
#
|
35
|
+
# - mongo
|
36
|
+
# - class: Mongo::Client
|
37
|
+
# - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
|
37
38
|
|
38
39
|
def run(initializer_content)
|
39
40
|
setup = initializer_content.setup
|
40
41
|
services = initializer_content.services
|
41
42
|
|
43
|
+
services.add(:mongo, RubyPitaya::MongoService.new(setup))
|
42
44
|
services.add(:redis, RubyPitaya::RedisService.new(setup))
|
43
45
|
|
44
46
|
playerBll = PlayerBLL.new
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class PlayerHandler < RubyPitaya::HandlerBase
|
2
2
|
|
3
|
-
# class: HandlerBase
|
3
|
+
# class: RubyPitaya::HandlerBase
|
4
4
|
# attributes:
|
5
5
|
# - @objects
|
6
6
|
# - class: InstanceHolder
|
@@ -8,10 +8,6 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
8
8
|
# - [](key)
|
9
9
|
# - info: get object by key
|
10
10
|
#
|
11
|
-
# - @mongo
|
12
|
-
# - class: Mongo::Client
|
13
|
-
# - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
|
14
|
-
#
|
15
11
|
# - @config
|
16
12
|
# - info: Hash with config json files inside of 'app/config'
|
17
13
|
# - example:
|
@@ -41,6 +37,14 @@ class PlayerHandler < RubyPitaya::HandlerBase
|
|
41
37
|
# of the session, for example you can set an userId on
|
42
38
|
# @session, like `@session.uid = '123'`, and then you can
|
43
39
|
# bind this session with `@postman.bind_session(@session)`
|
40
|
+
#
|
41
|
+
# - @services:
|
42
|
+
# - redis
|
43
|
+
# - link: https://github.com/redis/redis-rb/
|
44
|
+
#
|
45
|
+
# - mongo
|
46
|
+
# - class: Mongo::Client
|
47
|
+
# - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
|
44
48
|
|
45
49
|
non_authenticated_actions :authenticate
|
46
50
|
|
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'cucumber/rspec/doubles'
|
3
3
|
|
4
|
+
require 'rubypitaya/core/helpers/setup_helper'
|
5
|
+
require 'rubypitaya/core/spec-helpers/handler_spec_helper_class'
|
6
|
+
|
4
7
|
ENV['RUBYPITAYA_ENV'] = 'test'
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
RubyPitaya::HandlerSpecHelper.initialize_before_suite
|
10
|
+
|
11
|
+
at_exit do
|
12
|
+
RubyPitaya::HandlerSpecHelper.finalize_after_suite
|
13
|
+
end
|
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe 'PlayerHandler', type: :request do
|
4
4
|
context 'authenticate' do
|
5
5
|
it 'create_new_user' do
|
6
|
-
|
7
|
-
'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
set_config({
|
7
|
+
'initial_player' => {
|
8
|
+
'name' => 'Guest',
|
9
|
+
'wallet' => {'gold' => 10},
|
10
|
+
}
|
11
|
+
})
|
12
12
|
|
13
13
|
params = {}
|
14
14
|
request("rubypitaya.playerHandler.authenticate", params)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'RubyPitaya::RedisService', type: :request do
|
4
|
+
it 'mock service' do
|
5
|
+
allow(services[:redis]).to receive(:get).with('key').and_return('something')
|
6
|
+
|
7
|
+
value = services[:redis].get('key')
|
8
|
+
|
9
|
+
expect(value).to eq('something')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'not mock service' do
|
13
|
+
services[:redis].set('foo', 'bar')
|
14
|
+
|
15
|
+
value = services[:redis].get('foo')
|
16
|
+
|
17
|
+
expect(value).to eq('bar')
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
require 'rubypitaya/core/service_base'
|
3
|
+
|
4
|
+
module RubyPitaya
|
5
|
+
|
6
|
+
class MongoService < ServiceBase
|
7
|
+
|
8
|
+
def initialize(setup)
|
9
|
+
@mongo = nil
|
10
|
+
@mongo_address = setup['rubypitaya.mongo.url']
|
11
|
+
@mongo_user = setup['rubypitaya.mongo.user']
|
12
|
+
@mongo_password = setup['rubypitaya.mongo.pass']
|
13
|
+
@mongo_database_name = setup['rubypitaya.mongo.database']
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect
|
17
|
+
@mongo = Mongo::Client.new([@mongo_address],
|
18
|
+
user: @mongo_user,
|
19
|
+
password: @mongo_password,
|
20
|
+
database: @mongo_database_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def disconnect
|
24
|
+
# TODO: implement it
|
25
|
+
end
|
26
|
+
|
27
|
+
def client
|
28
|
+
@mongo
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear_all_data
|
32
|
+
# TODO: implement it
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -7,20 +7,20 @@ module RubyPitaya
|
|
7
7
|
|
8
8
|
class DatabaseConfig
|
9
9
|
|
10
|
-
def initialize()
|
11
|
-
@setup = Setup.new
|
12
|
-
|
10
|
+
def initialize(setup)
|
13
11
|
@config = {
|
14
12
|
'adapter' => 'postgresql',
|
15
13
|
'encoding' => 'unicode',
|
16
|
-
'pool' =>
|
17
|
-
'host' =>
|
18
|
-
'user' =>
|
19
|
-
'password' =>
|
20
|
-
'database' =>
|
14
|
+
'pool' => setup.fetch('rubypitaya.database.pool', 5),
|
15
|
+
'host' => setup['rubypitaya.database.host'],
|
16
|
+
'user' => setup['rubypitaya.database.user'],
|
17
|
+
'password' => setup['rubypitaya.database.password'],
|
18
|
+
'database' => setup['rubypitaya.database.name'],
|
21
19
|
}
|
22
20
|
|
23
|
-
|
21
|
+
environment_name = setup.fetch('rubypitaya.server.environment', 'development')
|
22
|
+
|
23
|
+
@config['database'] = "#{@config['database']}_test" if environment_name == 'test'
|
24
24
|
end
|
25
25
|
|
26
26
|
def config
|
@@ -5,14 +5,16 @@ module RubyPitaya
|
|
5
5
|
|
6
6
|
class DatabaseConnector
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@database_config =
|
10
|
-
@logger
|
8
|
+
def initialize(setup, logger = nil)
|
9
|
+
@database_config = DatabaseConfig.new(setup)
|
10
|
+
@logger = ActiveSupport::Logger.new(STDOUT)
|
11
|
+
# TODO: Use this
|
12
|
+
# @logger = logger || ActiveSupport::Logger.new(STDOUT)
|
11
13
|
end
|
12
14
|
|
13
15
|
def connect
|
14
16
|
ActiveRecord::Base.establish_connection(@database_config.connection_data)
|
15
|
-
ActiveRecord::Base.logger =
|
17
|
+
ActiveRecord::Base.logger = @logger
|
16
18
|
ActiveSupport::LogSubscriber.colorize_logging = true
|
17
19
|
end
|
18
20
|
|
@@ -21,10 +21,9 @@ module RubyPitaya
|
|
21
21
|
@objects = self.class.objects
|
22
22
|
end
|
23
23
|
|
24
|
-
def set_attributes(log, services,
|
24
|
+
def set_attributes(log, services, setup, config, params, session, postman)
|
25
25
|
@log = log
|
26
26
|
@services = services
|
27
|
-
@mongo = mongo
|
28
27
|
@setup = setup
|
29
28
|
@config = config
|
30
29
|
@params = params
|
@@ -64,7 +64,7 @@ module RubyPitaya
|
|
64
64
|
@handler_name_map = @handler_name_map.to_h
|
65
65
|
end
|
66
66
|
|
67
|
-
def call(handler_name, action_name, session, postman, services,
|
67
|
+
def call(handler_name, action_name, session, postman, services, setup,
|
68
68
|
config, log, params)
|
69
69
|
unless @handler_name_map.include?(handler_name)
|
70
70
|
return {
|
@@ -83,11 +83,11 @@ module RubyPitaya
|
|
83
83
|
handler = @handler_name_map[handler_name]
|
84
84
|
|
85
85
|
if !handler.class.authenticated_action_name?(action_name)
|
86
|
-
handler.set_attributes(log, services,
|
86
|
+
handler.set_attributes(log, services, setup, config, params, session, postman)
|
87
87
|
handler.send(action_name)
|
88
88
|
else
|
89
89
|
if session.authenticated?
|
90
|
-
handler.set_attributes(log, services,
|
90
|
+
handler.set_attributes(log, services, setup, config, params, session, postman)
|
91
91
|
handler.send(action_name)
|
92
92
|
else
|
93
93
|
return {
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
|
+
require 'rubypitaya/core/setup'
|
3
4
|
require 'rubypitaya/core/database_config'
|
4
5
|
|
5
6
|
# Database connection
|
6
|
-
database_config = RubyPitaya::DatabaseConfig.new
|
7
|
+
database_config = RubyPitaya::DatabaseConfig.new(RubyPitaya::Setup.new)
|
7
8
|
ActiveRecord::Base.establish_connection(database_config.connection_data)
|
8
|
-
# ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
|
9
|
-
# ActiveSupport::LogSubscriber.colorize_logging = true
|
10
9
|
|
11
10
|
connection_data = database_config.connection_data
|
12
11
|
migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
|
@@ -2,12 +2,11 @@ module RubyPitaya
|
|
2
2
|
|
3
3
|
class InitializerContent
|
4
4
|
|
5
|
-
attr_reader :log, :services, :
|
5
|
+
attr_reader :log, :services, :setup, :config
|
6
6
|
|
7
|
-
def initialize(log, services,
|
7
|
+
def initialize(log, services, setup, config)
|
8
8
|
@log = log
|
9
9
|
@services = services
|
10
|
-
@mongo = mongo
|
11
10
|
@setup = setup
|
12
11
|
@config = config
|
13
12
|
end
|
data/lib/rubypitaya/core/main.rb
CHANGED
@@ -17,9 +17,7 @@ require 'rubypitaya/core/etcd_connector'
|
|
17
17
|
require 'rubypitaya/core/handler_router'
|
18
18
|
require 'rubypitaya/core/nats_connector'
|
19
19
|
require 'rubypitaya/core/service_holder'
|
20
|
-
require 'rubypitaya/core/database_config'
|
21
20
|
require 'rubypitaya/core/instance_holder'
|
22
|
-
require 'rubypitaya/core/mongo_connector'
|
23
21
|
require 'rubypitaya/core/database_connector'
|
24
22
|
require 'rubypitaya/core/initializer_content'
|
25
23
|
require 'rubypitaya/core/initializer_broadcast'
|
@@ -64,19 +62,9 @@ module RubyPitaya
|
|
64
62
|
@nats_connector = NatsConnector.new(@nats_address, @service_uuid,
|
65
63
|
@server_name)
|
66
64
|
|
67
|
-
@
|
68
|
-
@database_connector = DatabaseConnector.new(@database_config, @log)
|
65
|
+
@database_connector = DatabaseConnector.new(@setup, @log)
|
69
66
|
@database_connector.connect
|
70
67
|
|
71
|
-
@mongo_enabled = @setup['rubypitaya.mongo.enabled']
|
72
|
-
@mongo_address = @setup['rubypitaya.mongo.url']
|
73
|
-
@mongo_user = @setup['rubypitaya.mongo.user']
|
74
|
-
@mongo_password = @setup['rubypitaya.mongo.pass']
|
75
|
-
@mongo_database_name = @setup['rubypitaya.mongo.database']
|
76
|
-
@mongo_connector = MongoConnector.new(@mongo_address, @mongo_user,
|
77
|
-
@mongo_password, @mongo_database_name)
|
78
|
-
@mongo_connector.connect if @mongo_enabled
|
79
|
-
|
80
68
|
@session = Session.new
|
81
69
|
@postman = Postman.new(@nats_connector)
|
82
70
|
@config = Config.new
|
@@ -88,7 +76,6 @@ module RubyPitaya
|
|
88
76
|
|
89
77
|
@initializer_content = InitializerContent.new(@log,
|
90
78
|
@services,
|
91
|
-
@mongo_connector.mongo,
|
92
79
|
@setup,
|
93
80
|
@config)
|
94
81
|
@initializer_broadcast = InitializerBroadcast.new
|
@@ -115,7 +102,6 @@ module RubyPitaya
|
|
115
102
|
def run_http
|
116
103
|
HttpRoutes.set :log, @log
|
117
104
|
HttpRoutes.set :services, @services
|
118
|
-
HttpRoutes.set :mongo, @mongo_connector.mongo
|
119
105
|
HttpRoutes.set :setup, @setup
|
120
106
|
HttpRoutes.set :config, @config
|
121
107
|
HttpRoutes.set :objects, @objects
|
@@ -196,17 +182,16 @@ module RubyPitaya
|
|
196
182
|
|
197
183
|
begin
|
198
184
|
response = @handler_router.call(handler_name, action_name, @session,
|
199
|
-
@postman, @services,
|
200
|
-
@mongo_connector.mongo, @setup, @config,
|
185
|
+
@postman, @services, @setup, @config,
|
201
186
|
@log, params)
|
202
187
|
rescue RouteError => error
|
203
|
-
@log.error "ROUTE ERROR: #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
|
188
|
+
@log.error "ROUTE ERROR: #{error.code} | #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
|
204
189
|
response = {
|
205
190
|
code: error.code,
|
206
191
|
message: error.message
|
207
192
|
}
|
208
193
|
rescue Exception => error
|
209
|
-
@log.error "INTERNAL ERROR: #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
|
194
|
+
@log.error "INTERNAL ERROR: #{error.code} | #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
|
210
195
|
response = {
|
211
196
|
code: StatusCodes::CODE_INTERNAL_ERROR,
|
212
197
|
message: StatusCodes::MESSAGE_INTERNAL_ERROR,
|
@@ -27,6 +27,10 @@ module RubyPitaya
|
|
27
27
|
@config_mock = merge_recursively(@config_mock, add_hash).deep_symbolize_keys.stringify_keys
|
28
28
|
end
|
29
29
|
|
30
|
+
def clear
|
31
|
+
@config_mock = {}
|
32
|
+
end
|
33
|
+
|
30
34
|
private
|
31
35
|
|
32
36
|
def undig(*keys, value)
|
@@ -34,7 +38,13 @@ module RubyPitaya
|
|
34
38
|
end
|
35
39
|
|
36
40
|
def merge_recursively(a, b)
|
37
|
-
a.merge(b)
|
41
|
+
a.merge(b) do |key, a_item, b_item|
|
42
|
+
if a_item.is_a?(Hash) && b_item.is_a?(Hash)
|
43
|
+
merge_recursively(a_item, b_item)
|
44
|
+
else
|
45
|
+
a[key] = b_item
|
46
|
+
end
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
@@ -9,39 +9,52 @@ module RubyPitaya
|
|
9
9
|
|
10
10
|
module HandlerSpecHelper
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def self.initialize_before_suite
|
13
|
+
default_setup = Setup.new.get_config
|
14
14
|
|
15
15
|
@@log = Logger.new('/dev/null')
|
16
|
-
@@setup = SetupSpecHelper.new
|
16
|
+
@@setup = SetupSpecHelper.new(default_setup)
|
17
17
|
@@config = ConfigSpecHelper.new
|
18
18
|
@@session = Session.new
|
19
19
|
@@postman = PostmanSpecHelper.new
|
20
20
|
@@services = ServiceHolder.new
|
21
21
|
|
22
|
-
@@
|
23
|
-
|
24
|
-
initialize_mongo
|
22
|
+
@@default_setup = Setup.new
|
25
23
|
|
26
|
-
is_cheats_enabled = @@setup.fetch('rubypitaya.server.cheats',
|
24
|
+
is_cheats_enabled = @@setup.fetch('rubypitaya.server.cheats', true)
|
27
25
|
@@handler_router ||= HandlerRouter.new(is_cheats_enabled)
|
28
26
|
|
29
27
|
|
30
28
|
@@initializer_content = InitializerContent.new(@@log,
|
31
29
|
@@services,
|
32
|
-
@@mongo_connector.mongo,
|
33
30
|
@@setup,
|
34
31
|
@@config)
|
35
32
|
@@initializer_broadcast = InitializerBroadcast.new
|
36
33
|
@@initializer_broadcast.run(@@initializer_content)
|
34
|
+
|
35
|
+
connect_services
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.finalize_after_suite
|
39
|
+
disconnect_services
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.update_before_each
|
43
|
+
@@response = {}
|
44
|
+
@@setup.clear
|
45
|
+
@@config.clear
|
46
|
+
@@session.clear
|
47
|
+
clear_all_services_data
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(context)
|
37
51
|
end
|
38
52
|
|
39
53
|
def request(route, params = {})
|
40
54
|
handler_name, action_name = route.split('.')[1..-1]
|
41
55
|
|
42
56
|
@@response = @@handler_router.call(handler_name, action_name, @@session,
|
43
|
-
@@postman, @@services,
|
44
|
-
@@mongo_connector.mongo, @@setup,
|
57
|
+
@@postman, @@services, @@setup,
|
45
58
|
@@config, @@log, params)
|
46
59
|
rescue RouteError => error
|
47
60
|
@@response = {
|
@@ -104,21 +117,16 @@ module RubyPitaya
|
|
104
117
|
|
105
118
|
private
|
106
119
|
|
107
|
-
def
|
108
|
-
@@
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
mongo_password, mongo_database_name)
|
118
|
-
@@mongo_connector.connect
|
119
|
-
end
|
120
|
-
|
121
|
-
@@mongo_connector.mongo.collections.map(&:drop)
|
120
|
+
def self.connect_services
|
121
|
+
@@services.all_services.map(&:connect)
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.disconnect_services
|
125
|
+
@@services.all_services.map(&:disconnect)
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.clear_all_services_data
|
129
|
+
@@services.all_services.map(&:clear_all_data)
|
122
130
|
end
|
123
131
|
end
|
124
132
|
end
|
@@ -8,7 +8,16 @@ require 'rubypitaya/core/spec-helpers/handler_spec_helper'
|
|
8
8
|
RSpec.configure do |config|
|
9
9
|
config.include RubyPitaya::HandlerSpecHelper
|
10
10
|
|
11
|
+
config.before(:suite) do
|
12
|
+
RubyPitaya::HandlerSpecHelper.initialize_before_suite
|
13
|
+
end
|
14
|
+
|
15
|
+
config.after(:suite) do
|
16
|
+
RubyPitaya::HandlerSpecHelper.finalize_after_suite
|
17
|
+
end
|
18
|
+
|
11
19
|
config.before(:each) do
|
20
|
+
RubyPitaya::HandlerSpecHelper.update_before_each
|
12
21
|
ActiveRecord::Base.descendants.each { |c| c.delete_all unless c == ActiveRecord::SchemaMigration }
|
13
22
|
end
|
14
23
|
|
@@ -2,13 +2,18 @@ module RubyPitaya
|
|
2
2
|
|
3
3
|
class SetupSpecHelper
|
4
4
|
|
5
|
-
def initialize
|
5
|
+
def initialize(default_setup = {})
|
6
|
+
@empty_hash = {}
|
6
7
|
@setup_mock = {}
|
8
|
+
@default_setup = default_setup
|
7
9
|
end
|
8
10
|
|
9
11
|
def [](key)
|
10
12
|
split_key = key.split('.')
|
11
|
-
@setup_mock.dig(*split_key)
|
13
|
+
result = @setup_mock.dig(*split_key)
|
14
|
+
return result unless result.nil?
|
15
|
+
|
16
|
+
@default_setup.dig(*split_key)
|
12
17
|
end
|
13
18
|
|
14
19
|
def auto_reload
|
@@ -25,7 +30,14 @@ module RubyPitaya
|
|
25
30
|
end
|
26
31
|
|
27
32
|
def fetch(*args)
|
28
|
-
|
33
|
+
result = self[args[0]]
|
34
|
+
return result unless result.nil?
|
35
|
+
|
36
|
+
@empty_hash.fetch(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def clear
|
40
|
+
@setup_mock = {}
|
29
41
|
end
|
30
42
|
|
31
43
|
private
|
@@ -35,7 +47,13 @@ module RubyPitaya
|
|
35
47
|
end
|
36
48
|
|
37
49
|
def merge_recursively(a, b)
|
38
|
-
a.merge(b)
|
50
|
+
a.merge(b) do |key, a_item, b_item|
|
51
|
+
if a_item.is_a?(Hash) && b_item.is_a?(Hash)
|
52
|
+
merge_recursively(a_item, b_item)
|
53
|
+
else
|
54
|
+
a[key] = b_item
|
55
|
+
end
|
56
|
+
end
|
39
57
|
end
|
40
58
|
end
|
41
59
|
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: 3.
|
4
|
+
version: 3.6.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: 2022-03-
|
11
|
+
date: 2022-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -332,9 +332,12 @@ files:
|
|
332
332
|
- "./lib/rubypitaya/app-template/plugins.yaml"
|
333
333
|
- "./lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb"
|
334
334
|
- "./lib/rubypitaya/app-template/spec/player_handler_spec.rb"
|
335
|
+
- "./lib/rubypitaya/app-template/spec/redis_service_spec.rb"
|
335
336
|
- "./lib/rubypitaya/app-template/spec/spec_helper.rb"
|
336
337
|
- "./lib/rubypitaya/core/app/migrations/0000000001_create_user_migration.rb"
|
337
338
|
- "./lib/rubypitaya/core/app/models/user.rb"
|
339
|
+
- "./lib/rubypitaya/core/app/services/mongo_service.rb"
|
340
|
+
- "./lib/rubypitaya/core/app/services/redis_service.rb"
|
338
341
|
- "./lib/rubypitaya/core/application_files_importer.rb"
|
339
342
|
- "./lib/rubypitaya/core/config.rb"
|
340
343
|
- "./lib/rubypitaya/core/config_core.rb"
|
@@ -351,14 +354,12 @@ files:
|
|
351
354
|
- "./lib/rubypitaya/core/initializer_content.rb"
|
352
355
|
- "./lib/rubypitaya/core/instance_holder.rb"
|
353
356
|
- "./lib/rubypitaya/core/main.rb"
|
354
|
-
- "./lib/rubypitaya/core/mongo_connector.rb"
|
355
357
|
- "./lib/rubypitaya/core/nats_connector.rb"
|
356
358
|
- "./lib/rubypitaya/core/parameters.rb"
|
357
359
|
- "./lib/rubypitaya/core/path.rb"
|
358
360
|
- "./lib/rubypitaya/core/postman.rb"
|
359
361
|
- "./lib/rubypitaya/core/protos/nats_connector.proto"
|
360
362
|
- "./lib/rubypitaya/core/protos/nats_connector_pb.rb"
|
361
|
-
- "./lib/rubypitaya/core/redis_service.rb"
|
362
363
|
- "./lib/rubypitaya/core/route_error.rb"
|
363
364
|
- "./lib/rubypitaya/core/routes_base.rb"
|
364
365
|
- "./lib/rubypitaya/core/service_base.rb"
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'mongo'
|
2
|
-
|
3
|
-
module RubyPitaya
|
4
|
-
|
5
|
-
class MongoConnector
|
6
|
-
|
7
|
-
def initialize(mongo_address, mongo_user, mongo_password, mongo_database_name)
|
8
|
-
@mongo_address = mongo_address
|
9
|
-
@mongo_user = mongo_user
|
10
|
-
@mongo_password = mongo_password
|
11
|
-
@mongo_database_name = mongo_database_name
|
12
|
-
end
|
13
|
-
|
14
|
-
def connect
|
15
|
-
@mongo_client = Mongo::Client.new([@mongo_address],
|
16
|
-
user: @mongo_user,
|
17
|
-
password: @mongo_password,
|
18
|
-
database: @mongo_database_name)
|
19
|
-
end
|
20
|
-
|
21
|
-
def mongo
|
22
|
-
@mongo_client
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|