rubypitaya 1.4.1 → 1.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: c48497c9641d832115ba3afc04d0a5fca2ddda41432d7e575ac51df4b1043ecc
4
- data.tar.gz: ca9b999ce0c3e1944b82928413b31e76437101eb2be55ff8e7b71d5a6e352e5c
3
+ metadata.gz: 8ce9fce444231d413f663d1af94356f0a04204af86050e6041a24f3b2bf37d8d
4
+ data.tar.gz: cc4c79730ea4e46891bff56f635c0135c62adc0f5ce06c6a473567bd46a48b78
5
5
  SHA512:
6
- metadata.gz: 88f66376c9de1733ab53c64e81ce5f4cf43f00de6f8a4c6607f3d48beb5ce37817fcdb87f4649f12c4b96b381050bb3d51d8ae7c1abb3452d68467062e4082d0
7
- data.tar.gz: cf4917a58e56c6dc275d2a0e40072a0e65ca5022703c5e9acce40cfbd2a9e590113d3726473bd5de3f79678fc06d307306820f6062d1f6a0d03fbf531b51f63f
6
+ metadata.gz: 46fff9b02c5d40577864c21bd226d7b412b93d70af22612b3dfe39409546d2b14361f2f63d0ba0f4c07db5fe118908d4700b804c5ad134f7ceb06e8c94b5cdc2
7
+ data.tar.gz: 40b3def401682e4f98e6efaabaad9afc384128f6e0a39a3ae495d36643155bab86c1913969fd3ac35f647275836b06c24aafd818dcf7e2657618ffb1754587ee
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '1.4.1'
3
+ gem 'rubypitaya', '1.5.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.12.2'
@@ -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 (1.4.1)
65
+ rubypitaya (1.5.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 (= 1.4.1)
88
+ rubypitaya (= 1.5.0)
89
89
 
90
90
  BUNDLED WITH
91
91
  1.17.2
@@ -1,11 +1,13 @@
1
- class HelloWorldHandler < RubyPitaya::HandlerBase
1
+ module MyApp
2
+ class HelloWorldHandler < RubyPitaya::HandlerBase
2
3
 
3
- non_authenticated_actions :sayHello
4
+ non_authenticated_actions :sayHello
4
5
 
5
- def sayHello
6
- response = {
7
- code: 'RP-200',
8
- msg: 'Hello!'
9
- }
6
+ def sayHello
7
+ response = {
8
+ code: 'RP-200',
9
+ msg: 'Hello!'
10
+ }
11
+ end
10
12
  end
11
- end
13
+ end
@@ -0,0 +1,11 @@
1
+ class Routes < RubyPitaya::RoutesBase
2
+
3
+ # class: RoutesBase
4
+ # methods:
5
+ # - match('new_handler_name', to: 'ClassHandler')
6
+ # - Defines a new name to handler
7
+
8
+ def setup
9
+ # match('helloHandler', to: 'MyApp::HelloWorldHandler')
10
+ end
11
+ end
@@ -4,11 +4,26 @@ module RubyPitaya
4
4
 
5
5
  class HandlerRouter
6
6
 
7
- def initialize(handler_folder_path)
7
+ def initialize(handler_folder_path, routes_path)
8
+ import_routes_file(routes_path)
8
9
  import_handler_files(handler_folder_path)
10
+
11
+ import_routes_class
9
12
  import_handler_classes
10
13
  end
11
14
 
15
+ def import_routes_file(routes_path)
16
+ require routes_path
17
+ end
18
+
19
+ def import_routes_class
20
+ routes_classes = ObjectSpace.each_object(RoutesBase.singleton_class).select do |klass|
21
+ klass != RoutesBase
22
+ end
23
+
24
+ @routes = routes_classes.first.new
25
+ end
26
+
12
27
  def import_handler_files(handler_folder_path)
13
28
  Gem.find_files("#{handler_folder_path}/*.rb").each { |path| require path }
14
29
  end
@@ -22,6 +37,8 @@ module RubyPitaya
22
37
 
23
38
  @handler_name_map = @handlers.map do |handler|
24
39
  handler_name = handler.class.to_s
40
+ handler_name = @routes.get_new_handler_name(handler_name)
41
+ handler_name = handler_name.split('::').last
25
42
  handler_name = handler_name[0].downcase + handler_name[1..-1]
26
43
 
27
44
  [handler_name, handler]
@@ -7,6 +7,7 @@ require 'rubypitaya/core/config'
7
7
  require 'rubypitaya/core/session'
8
8
  require 'rubypitaya/core/postman'
9
9
  require 'rubypitaya/core/parameters'
10
+ require 'rubypitaya/core/routes_base'
10
11
  require 'rubypitaya/core/handler_router'
11
12
  require 'rubypitaya/core/etcd_connector'
12
13
  require 'rubypitaya/core/nats_connector'
@@ -69,7 +70,8 @@ module RubyPitaya
69
70
  @initializer_broadcast = InitializerBroadcast.new
70
71
  @initializer_broadcast.run(@initializer_content)
71
72
 
72
- @handler_router = HandlerRouter.new(Path::HANDLERS_FOLDER_PATH)
73
+ @handler_router = HandlerRouter.new(Path::HANDLERS_FOLDER_PATH,
74
+ Path::ROUTES_FILE_PATH)
73
75
 
74
76
  run_server
75
77
  end
@@ -9,5 +9,7 @@ module RubyPitaya
9
9
  HANDLERS_FOLDER_PATH = File.join(Dir.pwd, 'app/handlers/')
10
10
  APP_CONFIG_FOLDER_PATH = File.join(Dir.pwd, 'app/config/')
11
11
  MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/migrate/')
12
+
13
+ ROUTES_FILE_PATH = File.join(Dir.pwd, 'config/routes.rb')
12
14
  end
13
15
  end
@@ -0,0 +1,36 @@
1
+
2
+ module RubyPitaya
3
+
4
+ class RoutesBase
5
+
6
+ def initialize
7
+ @handler_name_map = {}
8
+
9
+ setup
10
+ end
11
+
12
+ def setup
13
+ end
14
+
15
+ def match(route_name, to:)
16
+ handler_name, action_name = to.split('#')
17
+ new_handler_name, new_action_name = route_name.split('.')
18
+
19
+ if new_action_name.nil?
20
+ set_handler_name(handler_name, new_handler_name)
21
+ end
22
+ end
23
+
24
+ def get_new_handler_name(handler_name)
25
+ return handler_name unless @handler_name_map.include?(handler_name)
26
+
27
+ @handler_name_map[handler_name]
28
+ end
29
+
30
+ private
31
+
32
+ def set_handler_name(handler_name, new_handler_name)
33
+ @handler_name_map[handler_name] = new_handler_name
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = "1.4.1"
2
+ VERSION = "1.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: 1.4.1
4
+ version: 1.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: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -203,6 +203,7 @@ files:
203
203
  - "./lib/rubypitaya/app-template/app/models/user.rb"
204
204
  - "./lib/rubypitaya/app-template/bin/console"
205
205
  - "./lib/rubypitaya/app-template/config/database.yml"
206
+ - "./lib/rubypitaya/app-template/config/routes.rb"
206
207
  - "./lib/rubypitaya/app-template/db/migrate/001_create_user_migration.rb"
207
208
  - "./lib/rubypitaya/app-template/db/migrate/002_create_player_migration.rb"
208
209
  - "./lib/rubypitaya/app-template/docker-compose.yml"
@@ -227,6 +228,7 @@ files:
227
228
  - "./lib/rubypitaya/core/path.rb"
228
229
  - "./lib/rubypitaya/core/postman.rb"
229
230
  - "./lib/rubypitaya/core/redis_connector.rb"
231
+ - "./lib/rubypitaya/core/routes_base.rb"
230
232
  - "./lib/rubypitaya/core/session.rb"
231
233
  - "./lib/rubypitaya/version.rb"
232
234
  - bin/rubypitaya