rubypitaya 3.4.0 → 3.5.0

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: a3416fbf6a02d6e883d1f97b9f4c6ca36e246043ff2541ef690cc13170cdd727
4
- data.tar.gz: 961e1d3f9a24f416e3a37ef422358dfc6a89677f369816999550c7d76215c571
3
+ metadata.gz: bea764ce3cb4595677dc5ff2b0af555d0fa0db47500e0ae28a4431275ff0b3d0
4
+ data.tar.gz: b4d3ac9a4b66605396f1fd27fb83618e8897f5284e6fc9b97426b0ece545ef10
5
5
  SHA512:
6
- metadata.gz: 3892526f8d71b6a11448309ac6c1176a698ca46cfcda9b2c49a5860a2ed5913ffa285cc736ad39a23d480d6aebbd4ad8ea3a7352f2cd5cf8a48f2956ec02339f
7
- data.tar.gz: c57731543e86c6c161ead30fc84800f1c60c7895d18722ec47018da758736cd5d8cd1c5a6616a31307e910e838636587f701e1e37d76301e85fb44f1b2a6795a
6
+ metadata.gz: 38152d121b929079ba9315832bfac315771bb640c7cabbd7c66fdd286662706c54f9a0412d575bc2024e3aa929aae950c679c6189969ecfe454e41d333e38fb7
7
+ data.tar.gz: c3b9b060a58f659a32fbff7baa950eade738672d426e1aaadb295df58bed56cbd5ddde2b09f1ce3a8caca47c4b1ce85e086b10598798c858fb45fdc0483604cb
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '3.4.0'
3
+ gem 'rubypitaya', '3.5.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.1'
@@ -1,83 +1,79 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activemodel (6.1.4.1)
5
- activesupport (= 6.1.4.1)
6
- activerecord (6.1.4.1)
7
- activemodel (= 6.1.4.1)
8
- activesupport (= 6.1.4.1)
9
- activesupport (6.1.4.1)
4
+ activemodel (7.0.2)
5
+ activesupport (= 7.0.2)
6
+ activerecord (7.0.2)
7
+ activemodel (= 7.0.2)
8
+ activesupport (= 7.0.2)
9
+ activesupport (7.0.2)
10
10
  concurrent-ruby (~> 1.0, >= 1.0.2)
11
11
  i18n (>= 1.6, < 2)
12
12
  minitest (>= 5.1)
13
13
  tzinfo (~> 2.0)
14
- zeitwerk (~> 2.3)
15
- bson (4.12.1)
14
+ bson (4.14.1)
16
15
  builder (3.2.4)
17
16
  coderay (1.1.3)
18
17
  concurrent-ruby (1.1.9)
19
- cucumber (7.0.0)
18
+ cucumber (7.1.0)
20
19
  builder (~> 3.2, >= 3.2.4)
21
- cucumber-core (~> 10.0, >= 10.0.1)
20
+ cucumber-core (~> 10.1, >= 10.1.0)
22
21
  cucumber-create-meta (~> 6.0, >= 6.0.1)
23
- cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
24
- cucumber-gherkin (~> 20.0, >= 20.0.1)
25
- cucumber-html-formatter (~> 16.0, >= 16.0.1)
26
- cucumber-messages (~> 17.0, >= 17.0.1)
27
- cucumber-wire (~> 6.0, >= 6.0.1)
22
+ cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
23
+ cucumber-gherkin (~> 22.0, >= 22.0.0)
24
+ cucumber-html-formatter (~> 17.0, >= 17.0.0)
25
+ cucumber-messages (~> 17.1, >= 17.1.1)
26
+ cucumber-wire (~> 6.2, >= 6.2.0)
28
27
  diff-lcs (~> 1.4, >= 1.4.4)
29
28
  mime-types (~> 3.3, >= 3.3.1)
30
29
  multi_test (~> 0.1, >= 0.1.2)
31
30
  sys-uname (~> 1.2, >= 1.2.2)
32
- cucumber-core (10.0.1)
33
- cucumber-gherkin (~> 20.0, >= 20.0.1)
34
- cucumber-messages (~> 17.0, >= 17.0.1)
35
- cucumber-tag-expressions (~> 3.0, >= 3.0.1)
31
+ cucumber-core (10.1.1)
32
+ cucumber-gherkin (~> 22.0, >= 22.0.0)
33
+ cucumber-messages (~> 17.1, >= 17.1.1)
34
+ cucumber-tag-expressions (~> 4.1, >= 4.1.0)
36
35
  cucumber-create-meta (6.0.4)
37
36
  cucumber-messages (~> 17.1, >= 17.1.1)
38
37
  sys-uname (~> 1.2, >= 1.2.2)
39
- cucumber-cucumber-expressions (12.1.3)
40
- cucumber-gherkin (20.0.1)
41
- cucumber-messages (~> 17.0, >= 17.0.1)
42
- cucumber-html-formatter (16.0.1)
43
- cucumber-messages (~> 17.0, >= 17.0.1)
38
+ cucumber-cucumber-expressions (14.0.0)
39
+ cucumber-gherkin (22.0.0)
40
+ cucumber-messages (~> 17.1, >= 17.1.1)
41
+ cucumber-html-formatter (17.0.0)
42
+ cucumber-messages (~> 17.1, >= 17.1.0)
44
43
  cucumber-messages (17.1.1)
45
- cucumber-tag-expressions (3.0.1)
46
- cucumber-wire (6.1.1)
47
- cucumber-core (~> 10.0, >= 10.0.1)
48
- cucumber-cucumber-expressions (~> 12.1, >= 12.1.2)
49
- cucumber-messages (~> 17.0, >= 17.0.1)
50
- diff-lcs (1.4.4)
51
- etcdv3 (0.11.4)
44
+ cucumber-tag-expressions (4.1.0)
45
+ cucumber-wire (6.2.1)
46
+ cucumber-core (~> 10.1, >= 10.1.0)
47
+ cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
48
+ diff-lcs (1.5.0)
49
+ etcdv3 (0.11.5)
52
50
  grpc (~> 1.17)
53
- eventmachine (1.2.7)
54
- ffi (1.15.4)
55
- google-protobuf (3.18.1-x86_64-linux)
51
+ ffi (1.15.5)
52
+ google-protobuf (3.19.4-x86_64-linux)
56
53
  googleapis-common-protos-types (1.3.0)
57
54
  google-protobuf (~> 3.14)
58
- grpc (1.41.1-x86_64-linux)
59
- google-protobuf (~> 3.17)
55
+ grpc (1.43.1-x86_64-linux)
56
+ google-protobuf (~> 3.18)
60
57
  googleapis-common-protos-types (~> 1.0)
61
- i18n (1.8.11)
58
+ i18n (1.9.1)
62
59
  concurrent-ruby (~> 1.0)
63
- listen (3.7.0)
60
+ listen (3.7.1)
64
61
  rb-fsevent (~> 0.10, >= 0.10.3)
65
62
  rb-inotify (~> 0.9, >= 0.9.10)
66
63
  method_source (1.0.0)
67
64
  mime-types (3.4.1)
68
65
  mime-types-data (~> 3.2015)
69
- mime-types-data (3.2021.1115)
70
- minitest (5.14.4)
71
- mongo (2.16.0)
66
+ mime-types-data (3.2022.0105)
67
+ minitest (5.15.0)
68
+ mongo (2.17.0)
72
69
  bson (>= 4.8.2, < 5.0.0)
73
70
  multi_json (1.15.0)
74
71
  multi_test (0.1.2)
75
72
  mustermann (1.1.1)
76
73
  ruby2_keywords (~> 0.0.1)
77
- nats (0.11.0)
78
- eventmachine (~> 1.2, >= 1.2)
79
- ostruct (0.4.0)
80
- pg (1.2.3)
74
+ nats-pure (2.0.0)
75
+ ostruct (0.5.3)
76
+ pg (1.3.1)
81
77
  pry (0.14.1)
82
78
  coderay (~> 1.1)
83
79
  method_source (~> 1.0)
@@ -85,34 +81,34 @@ GEM
85
81
  rack-protection (2.1.0)
86
82
  rack
87
83
  rake (13.0.6)
88
- rb-fsevent (0.11.0)
84
+ rb-fsevent (0.11.1)
89
85
  rb-inotify (0.10.1)
90
86
  ffi (~> 1.0)
91
- redis (4.5.1)
92
- rspec (3.10.0)
93
- rspec-core (~> 3.10.0)
94
- rspec-expectations (~> 3.10.0)
95
- rspec-mocks (~> 3.10.0)
96
- rspec-core (3.10.1)
97
- rspec-support (~> 3.10.0)
98
- rspec-expectations (3.10.1)
87
+ redis (4.6.0)
88
+ rspec (3.11.0)
89
+ rspec-core (~> 3.11.0)
90
+ rspec-expectations (~> 3.11.0)
91
+ rspec-mocks (~> 3.11.0)
92
+ rspec-core (3.11.0)
93
+ rspec-support (~> 3.11.0)
94
+ rspec-expectations (3.11.0)
99
95
  diff-lcs (>= 1.2.0, < 2.0)
100
- rspec-support (~> 3.10.0)
101
- rspec-mocks (3.10.2)
96
+ rspec-support (~> 3.11.0)
97
+ rspec-mocks (3.11.0)
102
98
  diff-lcs (>= 1.2.0, < 2.0)
103
- rspec-support (~> 3.10.0)
104
- rspec-support (3.10.3)
99
+ rspec-support (~> 3.11.0)
100
+ rspec-support (3.11.0)
105
101
  ruby2_keywords (0.0.5)
106
- rubypitaya (3.4.0)
107
- activerecord (= 6.1.4.1)
108
- etcdv3 (= 0.11.4)
109
- google-protobuf (= 3.18.1)
110
- mongo (= 2.16.0)
111
- nats (= 0.11.0)
112
- ostruct (= 0.4.0)
113
- pg (= 1.2.3)
102
+ rubypitaya (3.5.0)
103
+ activerecord (= 7.0.2)
104
+ etcdv3 (= 0.11.5)
105
+ google-protobuf (= 3.19.4)
106
+ mongo (= 2.17.0)
107
+ nats-pure (= 2.0.0)
108
+ ostruct (= 0.5.3)
109
+ pg (= 1.3.1)
114
110
  rake (= 13.0.6)
115
- redis (= 4.5.1)
111
+ redis (= 4.6.0)
116
112
  sinatra (= 2.1.0)
117
113
  webrick (= 1.7.0)
118
114
  sinatra (2.1.0)
@@ -132,19 +128,18 @@ GEM
132
128
  tzinfo (2.0.4)
133
129
  concurrent-ruby (~> 1.0)
134
130
  webrick (1.7.0)
135
- zeitwerk (2.5.1)
136
131
 
137
132
  PLATFORMS
138
133
  x86_64-linux
139
134
 
140
135
  DEPENDENCIES
141
- bundler (= 2.2.22)
142
- cucumber (= 7.0.0)
143
- listen (= 3.7.0)
136
+ bundler (= 2.2.32)
137
+ cucumber (= 7.1.0)
138
+ listen (= 3.7.1)
144
139
  pry (= 0.14.1)
145
- rspec (= 3.10.0)
146
- rubypitaya (= 3.4.0)
140
+ rspec (= 3.11.0)
141
+ rubypitaya (= 3.5.0)
147
142
  sinatra-contrib (= 2.1.0)
148
143
 
149
144
  BUNDLED WITH
150
- 2.2.22
145
+ 2.2.32
@@ -99,6 +99,12 @@ prod-push-image:
99
99
  prod-deploy-image:
100
100
  kubectl --context='$(KUBECONTEXT)' -n $(KUBE_NAMESPACE) set image deployment $(KUBE_DEPLOYMENT_SERVER) $(KUBE_DEPLOYMENT_SERVER)=$(IMAGE_REGISTRY):$(IMAGE_TAG)
101
101
 
102
+ ## + Other Commands
103
+
104
+ ## Clear docker containers and volumes
105
+ clear:
106
+ @docker rm -f $$(docker ps -aq) ; docker volume rm -f $$(docker volume ls)
107
+
102
108
  .DEFAULT_GOAL := show-help
103
109
 
104
110
  .PHONY: show-help
@@ -1,10 +1,12 @@
1
+ require 'rubypitaya/core/redis_service'
2
+
1
3
  class AppInitializer < RubyPitaya::InitializerBase
2
4
 
3
5
  # method: run
4
6
  # parameter: initializer_content
5
7
  # attributes:
6
- # - redis
7
- # - link: https://github.com/redis/redis-rb/
8
+ # - services
9
+ # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/service_holder.rb
8
10
  #
9
11
  # - mongo
10
12
  # - class: Mongo::Client
@@ -29,9 +31,17 @@ class AppInitializer < RubyPitaya::InitializerBase
29
31
  # - info
30
32
  # - log information
31
33
 
34
+ # services:
35
+ # - redis
36
+ # - link: https://github.com/redis/redis-rb/
37
+
32
38
  def run(initializer_content)
33
- playerBll = PlayerBLL.new
39
+ setup = initializer_content.setup
40
+ services = initializer_content.services
34
41
 
42
+ services.add(:redis, RubyPitaya::RedisService.new(setup))
43
+
44
+ playerBll = PlayerBLL.new
35
45
  PlayerHandler.objects.add(:bll, playerBll)
36
46
  end
37
47
 
@@ -0,0 +1,18 @@
1
+ class ErrorHandler < RubyPitaya::HandlerBase
2
+
3
+ non_authenticated_actions :getError
4
+
5
+ def getError
6
+ error_code = RubyPitaya::StatusCodes::CODE_ERROR
7
+ error_message = "Some Error"
8
+
9
+ raise RubyPitaya::RouteError.new(error_code, error_message)
10
+
11
+ response = {
12
+ code: 'RP-200',
13
+ data: {
14
+ message: 'Ok!'
15
+ }
16
+ }
17
+ end
18
+ end
@@ -8,9 +8,6 @@ class PlayerHandler < RubyPitaya::HandlerBase
8
8
  # - [](key)
9
9
  # - info: get object by key
10
10
  #
11
- # - @redis
12
- # - link: https://github.com/redis/redis-rb/
13
- #
14
11
  # - @mongo
15
12
  # - class: Mongo::Client
16
13
  # - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
@@ -1,12 +1,12 @@
1
1
  require 'active_record'
2
2
 
3
- class CreatePlayerMigration < ActiveRecord::Migration[6.1]
3
+ class CreatePlayerMigration < ActiveRecord::Migration[7.0]
4
4
 
5
5
  enable_extension 'pgcrypto'
6
6
 
7
7
  def change
8
8
  create_table :players, id: :uuid do |t|
9
- t.belongs_to :user, type: :uuid
9
+ t.belongs_to :user, type: :uuid, foreing_key: true, index: { unique: true }
10
10
  t.string :name, null: false
11
11
  t.integer :gold, null: false
12
12
  t.timestamps null: false
@@ -19,7 +19,6 @@ RUN rm -rf /usr/local/bundle/cache && \
19
19
  rm -rf /usr/local/bundle/build_info && \
20
20
  rm -rf /usr/local/bundle/doc && \
21
21
  rm -rf /usr/local/bundle/doc && \
22
- find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.4/ -name "*.so" -delete && \
23
22
  find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.5/ -name "*.so" -delete && \
24
23
  find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.6/ -name "*.so" -delete && \
25
24
  find /usr/local/bundle/gems/grpc-*/src/ruby/lib/grpc/2.7/ -name "*.so" -delete && \
@@ -7,11 +7,11 @@ module RubyPitaya
7
7
  class_attribute :non_authenticated_routes, default: []
8
8
  class_attribute :handler_objects, default: nil, instance_reader: false, instance_writer: false, instance_accessor: false, instance_predicate: false
9
9
 
10
- attr_reader :objects, :log, :redis, :setup, :config, :params, :session, :postman
10
+ attr_reader :objects, :log, :services, :setup, :config, :params, :session, :postman
11
11
 
12
12
  def initialize
13
13
  @log = nil
14
- @redis = nil
14
+ @services = nil
15
15
  @setup = nil
16
16
  @config = nil
17
17
  @params = nil
@@ -21,9 +21,9 @@ module RubyPitaya
21
21
  @objects = self.class.objects
22
22
  end
23
23
 
24
- def set_attributes(log, redis, mongo, setup, config, params, session, postman)
24
+ def set_attributes(log, services, mongo, setup, config, params, session, postman)
25
25
  @log = log
26
- @redis = redis
26
+ @services = services
27
27
  @mongo = mongo
28
28
  @setup = setup
29
29
  @config = config
@@ -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, redis, mongo, setup,
67
+ def call(handler_name, action_name, session, postman, services, mongo, 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, redis, mongo, setup, config, params, session, postman)
86
+ handler.set_attributes(log, services, mongo, setup, config, params, session, postman)
87
87
  handler.send(action_name)
88
88
  else
89
89
  if session.authenticated?
90
- handler.set_attributes(log, redis, mongo, setup, config, params, session, postman)
90
+ handler.set_attributes(log, services, mongo, setup, config, params, session, postman)
91
91
  handler.send(action_name)
92
92
  else
93
93
  return {
@@ -26,7 +26,7 @@ module RubyPitaya
26
26
  @log = settings.log
27
27
  @mongo = settings.mongo
28
28
  @setup = settings.setup
29
- @redis = settings.redis
29
+ @services = settings.services
30
30
  @config = settings.config
31
31
  @objects = settings.objects
32
32
  @session = nil
@@ -2,12 +2,12 @@ module RubyPitaya
2
2
 
3
3
  class InitializerContent
4
4
 
5
- attr_reader :log, :redis, :mongo, :setup, :config
5
+ attr_reader :log, :services, :mongo, :setup, :config
6
6
 
7
- def initialize(log, redis, mongo, setup, config)
7
+ def initialize(log, services, mongo, setup, config)
8
8
  @log = log
9
+ @services = services
9
10
  @mongo = mongo
10
- @redis = redis
11
11
  @setup = setup
12
12
  @config = config
13
13
  end
@@ -13,13 +13,13 @@ require 'rubypitaya/core/http_routes'
13
13
  require 'rubypitaya/core/route_error'
14
14
  require 'rubypitaya/core/routes_base'
15
15
  require 'rubypitaya/core/status_codes'
16
- require 'rubypitaya/core/handler_router'
17
16
  require 'rubypitaya/core/etcd_connector'
17
+ require 'rubypitaya/core/handler_router'
18
18
  require 'rubypitaya/core/nats_connector'
19
+ require 'rubypitaya/core/service_holder'
19
20
  require 'rubypitaya/core/database_config'
20
21
  require 'rubypitaya/core/instance_holder'
21
22
  require 'rubypitaya/core/mongo_connector'
22
- require 'rubypitaya/core/redis_connector'
23
23
  require 'rubypitaya/core/database_connector'
24
24
  require 'rubypitaya/core/initializer_content'
25
25
  require 'rubypitaya/core/initializer_broadcast'
@@ -64,10 +64,6 @@ module RubyPitaya
64
64
  @nats_connector = NatsConnector.new(@nats_address, @service_uuid,
65
65
  @server_name)
66
66
 
67
- @redis_address = @setup['rubypitaya.redis.url']
68
- @redis_connector = RedisConnector.new(@redis_address)
69
- @redis_connector.connect
70
-
71
67
  @database_config = DatabaseConfig.new
72
68
  @database_connector = DatabaseConnector.new(@database_config, @log)
73
69
  @database_connector.connect
@@ -86,10 +82,12 @@ module RubyPitaya
86
82
  @config = Config.new
87
83
  @config.auto_reload if @is_development_environment
88
84
 
85
+ @services = ServiceHolder.new
86
+
89
87
  @objects = InstanceHolder.new
90
88
 
91
89
  @initializer_content = InitializerContent.new(@log,
92
- @redis_connector.redis,
90
+ @services,
93
91
  @mongo_connector.mongo,
94
92
  @setup,
95
93
  @config)
@@ -98,15 +96,25 @@ module RubyPitaya
98
96
 
99
97
  @handler_router = HandlerRouter.new(@is_cheats_enabled)
100
98
 
99
+ connect_services
100
+
101
101
  run_http
102
102
  run_server
103
103
  end
104
104
 
105
105
  private
106
106
 
107
+ def connect_services
108
+ @services.all_services.map(&:connect)
109
+ end
110
+
111
+ def disconnect_services
112
+ @services.all_services.map(&:disconnect)
113
+ end
114
+
107
115
  def run_http
108
116
  HttpRoutes.set :log, @log
109
- HttpRoutes.set :redis, @redis_connector.redis
117
+ HttpRoutes.set :services, @services
110
118
  HttpRoutes.set :mongo, @mongo_connector.mongo
111
119
  HttpRoutes.set :setup, @setup
112
120
  HttpRoutes.set :config, @config
@@ -147,6 +155,8 @@ module RubyPitaya
147
155
 
148
156
  @log.info "Server shutting down..."
149
157
 
158
+ disconnect_services
159
+
150
160
  @etcd_connector.disconnect
151
161
  @nats_connector.disconnect
152
162
  @database_connector.disconnect
@@ -186,17 +196,17 @@ module RubyPitaya
186
196
 
187
197
  begin
188
198
  response = @handler_router.call(handler_name, action_name, @session,
189
- @postman, @redis_connector.redis,
199
+ @postman, @services,
190
200
  @mongo_connector.mongo, @setup, @config,
191
201
  @log, params)
192
202
  rescue RouteError => error
193
- @log.error "ROUTE ERROR: #{error.class} | #{error.message}} \n #{error.backtrace.join("\n")}"
203
+ @log.error "ROUTE ERROR: #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
194
204
  response = {
195
205
  code: error.code,
196
206
  message: error.message
197
207
  }
198
208
  rescue Exception => error
199
- @log.error "INTERNAL ERROR: #{error.class} | #{error.message}} \n #{error.backtrace.join("\n")}"
209
+ @log.error "INTERNAL ERROR: #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
200
210
  response = {
201
211
  code: StatusCodes::CODE_INTERNAL_ERROR,
202
212
  message: StatusCodes::MESSAGE_INTERNAL_ERROR,
@@ -1,14 +1,15 @@
1
1
  require 'redis'
2
+ require 'rubypitaya/core/service_base'
2
3
 
3
4
  module RubyPitaya
4
5
 
5
- class RedisConnector
6
+ class RedisService < ServiceBase
6
7
 
7
8
  attr_reader :redis
8
9
 
9
- def initialize(redis_address)
10
+ def initialize(setup)
10
11
  @redis = nil
11
- @redis_address = redis_address
12
+ @redis_address = setup['rubypitaya.redis.url']
12
13
  end
13
14
 
14
15
  def connect
@@ -21,5 +22,17 @@ module RubyPitaya
21
22
 
22
23
  @redis.ping
23
24
  end
25
+
26
+ def disconnect
27
+ @redis.close
28
+ end
29
+
30
+ def client
31
+ @redis
32
+ end
33
+
34
+ def clear_all_data
35
+ @redis.flushall
36
+ end
24
37
  end
25
38
  end
@@ -0,0 +1,21 @@
1
+ module RubyPitaya
2
+
3
+ class ServiceBase
4
+
5
+ def connect
6
+ raise "Service connect method not implemented"
7
+ end
8
+
9
+ def disconnect
10
+ raise "Service disconnect method not implemented"
11
+ end
12
+
13
+ # def get_service_instance
14
+ # raise "Service get_service_instance method not implemented"
15
+ # end
16
+
17
+ def clear_all_data
18
+ raise "Service disconnect method not implemented"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module RubyPitaya
2
+
3
+ class ServiceHolder
4
+
5
+ def initialize
6
+ @services = {}
7
+ end
8
+
9
+ def add(key, service)
10
+ check_service_instance(service)
11
+ @services[key] = service
12
+ end
13
+
14
+ def [](key)
15
+ @services[key].client
16
+ end
17
+
18
+ def all_services
19
+ @services.values
20
+ end
21
+
22
+ private
23
+
24
+ def check_service_instance(service)
25
+ raise not_a_service_message(service) unless service.is_a? ServiceBase
26
+ end
27
+
28
+ def not_a_service_message(service)
29
+ "Service #{service.class} is not inheriting from RubyPitaya::ServiceBase"
30
+ end
31
+ end
32
+ end
@@ -1,6 +1,6 @@
1
1
  require 'rubypitaya/core/setup'
2
2
  require 'rubypitaya/core/handler_router'
3
- require 'rubypitaya/core/redis_connector'
3
+ require 'rubypitaya/core/service_holder'
4
4
  require 'rubypitaya/core/spec-helpers/setup_spec_helper'
5
5
  require 'rubypitaya/core/spec-helpers/config_spec_helper'
6
6
  require 'rubypitaya/core/spec-helpers/postman_spec_helper'
@@ -17,10 +17,10 @@ module RubyPitaya
17
17
  @@config = ConfigSpecHelper.new
18
18
  @@session = Session.new
19
19
  @@postman = PostmanSpecHelper.new
20
+ @@services = ServiceHolder.new
20
21
 
21
22
  @@response = {}
22
23
 
23
- initialize_redis
24
24
  initialize_mongo
25
25
 
26
26
  is_cheats_enabled = @@setup.fetch('rubypitaya.server.cheats', false)
@@ -28,7 +28,7 @@ module RubyPitaya
28
28
 
29
29
 
30
30
  @@initializer_content = InitializerContent.new(@@log,
31
- @@redis_connector.redis,
31
+ @@services,
32
32
  @@mongo_connector.mongo,
33
33
  @@setup,
34
34
  @@config)
@@ -40,7 +40,7 @@ module RubyPitaya
40
40
  handler_name, action_name = route.split('.')[1..-1]
41
41
 
42
42
  @@response = @@handler_router.call(handler_name, action_name, @@session,
43
- @@postman, @@redis_connector.redis,
43
+ @@postman, @@services,
44
44
  @@mongo_connector.mongo, @@setup,
45
45
  @@config, @@log, params)
46
46
  rescue RouteError => error
@@ -98,25 +98,12 @@ module RubyPitaya
98
98
  @@postman
99
99
  end
100
100
 
101
- def redis
102
- @@redis_connector.redis
101
+ def services
102
+ @@services
103
103
  end
104
104
 
105
105
  private
106
106
 
107
- def initialize_redis
108
- @@redis_connector ||= nil
109
-
110
- if @@redis_connector.nil?
111
- @@core_setup ||= Setup.new
112
- redis_address = @@core_setup['rubypitaya.redis.url']
113
- @@redis_connector = RedisConnector.new(redis_address)
114
- @@redis_connector.connect
115
- end
116
-
117
- @@redis_connector.redis.flushall
118
- end
119
-
120
107
  def initialize_mongo
121
108
  @@mongo_connector ||= nil
122
109
 
@@ -1,6 +1,6 @@
1
1
  require 'active_record'
2
2
 
3
- class <%= class_name %> < ActiveRecord::Migration[6.1]
3
+ class <%= class_name %> < ActiveRecord::Migration[7.0]
4
4
 
5
5
  enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
6
6
 
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '3.4.0'
2
+ VERSION = '3.5.0'
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: 3.4.0
4
+ version: 3.5.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-02-11 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -268,6 +268,7 @@ files:
268
268
  - "./lib/rubypitaya/app-template/app/bll/player_bll.rb"
269
269
  - "./lib/rubypitaya/app-template/app/config/initial_player.json"
270
270
  - "./lib/rubypitaya/app-template/app/constants/status_codes.rb"
271
+ - "./lib/rubypitaya/app-template/app/handlers/error_handler.rb"
271
272
  - "./lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb"
272
273
  - "./lib/rubypitaya/app-template/app/handlers/player_handler.rb"
273
274
  - "./lib/rubypitaya/app-template/app/http/hello_world_http.rb"
@@ -357,9 +358,11 @@ files:
357
358
  - "./lib/rubypitaya/core/postman.rb"
358
359
  - "./lib/rubypitaya/core/protos/nats_connector.proto"
359
360
  - "./lib/rubypitaya/core/protos/nats_connector_pb.rb"
360
- - "./lib/rubypitaya/core/redis_connector.rb"
361
+ - "./lib/rubypitaya/core/redis_service.rb"
361
362
  - "./lib/rubypitaya/core/route_error.rb"
362
363
  - "./lib/rubypitaya/core/routes_base.rb"
364
+ - "./lib/rubypitaya/core/service_base.rb"
365
+ - "./lib/rubypitaya/core/service_holder.rb"
363
366
  - "./lib/rubypitaya/core/session.rb"
364
367
  - "./lib/rubypitaya/core/setup.rb"
365
368
  - "./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb"