rubypitaya 2.7.5 → 2.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c0e17a12d24e8681424de7febeb3c496362c9efb6ddba566e2cb5a94a8e076
4
- data.tar.gz: c01c5cdc3bd4adf77d1fae5479418d1f09f693e157b1bb28bc458260841198ee
3
+ metadata.gz: ea061a423e6810b67f1a1256c58ca9f37b1f0494abe0808f999a3b1b4db2a955
4
+ data.tar.gz: ca8eb926d63d2331911e835c9d06e167092dea7be8f5e7433530ae50a9bea674
5
5
  SHA512:
6
- metadata.gz: 2e54976ad166dfef5c686cbd75cabb7c15e2dbb991aa7946b43a120213e26d1fa46b414212d9c1d18a970b17a6689ac89c38c8bedc075670d0ed4ea9a1050253
7
- data.tar.gz: d510fcd44c66d24be9b7f07de8184f8fbff14d24308abd7955f9d156a2d056bc7417b47cf9c50da0ad9b17e307f7471949b50883b542118a029376c6f35f36f2
6
+ metadata.gz: 72ca0233433069c86b70fb0235bb7dcd47441cac23bf994019456f16a130b60e0f6801ed4d1fe1c3bfa12cce4c6f3bab7821fe49fd4167bef2f6a11a5bc62f8c
7
+ data.tar.gz: 77a113fb20486be58a6403c421553955dd8e451f76d2ae4ab788f4ffeefb04d10a99f9e7f72a9d3a5eb00e484076d226008afa5365068c4a9a87e80f279efd7d
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rubypitaya'
4
4
 
5
- COMMANDS = ['run', 'create']
5
+ COMMANDS = ['run', 'create', 'create-migration', 'add-plugin']
6
6
 
7
7
  def main
8
8
  if ARGV.size == 0 || !COMMANDS.include?(ARGV[0])
@@ -19,6 +19,14 @@ def main
19
19
  if command == 'create'
20
20
  command_create(ARGV)
21
21
  end
22
+
23
+ if command == 'create-migration'
24
+ command_create_migration(ARGV)
25
+ end
26
+
27
+ if command == 'add-plugin'
28
+ command_add_plugin(ARGV)
29
+ end
22
30
  end
23
31
 
24
32
  def command_run(argv)
@@ -40,11 +48,38 @@ def command_create(argv)
40
48
  puts "Project #{project_name} created!"
41
49
  end
42
50
 
51
+ def command_create_migration(argv)
52
+ if argv.size <= 1
53
+ show_help_create_migration()
54
+ exit(-1)
55
+ end
56
+
57
+ migration_name = argv[1]
58
+
59
+ migration_file_name = RubyPitaya::RubyPitaya.create_migration(migration_name)
60
+
61
+ puts "Migration #{migration_file_name} created!"
62
+ end
63
+
64
+ def command_add_plugin(argv)
65
+ if argv.size <= 1
66
+ show_help_add_plugin()
67
+ exit(-1)
68
+ end
69
+
70
+ plugin_git_link = argv[1]
71
+
72
+ plugin_name = RubyPitaya::RubyPitaya.add_plugin(plugin_git_link)
73
+
74
+ puts "Plugin #{plugin_name} added!"
75
+ end
76
+
43
77
  def show_help
44
78
  puts 'Usage: $ rubypitaya [COMMAND]'
45
79
  puts 'COMMAND:'
46
- puts ' run: - Run server'
47
- puts ' create: - Create project'
80
+ puts ' run: - Run server'
81
+ puts ' create: - Create project'
82
+ puts ' create-migration: - Create migration'
48
83
  puts ''
49
84
  end
50
85
 
@@ -53,4 +88,14 @@ def show_help_create
53
88
  puts ''
54
89
  end
55
90
 
91
+ def show_help_create_migration
92
+ puts 'Usage: $ rubypitaya create-migration [migration_name]'
93
+ puts ''
94
+ end
95
+
96
+ def show_help_add_plugin
97
+ puts 'Usage: $ rubypitaya create-migration [migration_name]'
98
+ puts ''
99
+ end
100
+
56
101
  main
@@ -1,3 +1,5 @@
1
+ require 'erb'
2
+ require 'ostruct'
1
3
  require 'fileutils'
2
4
 
3
5
  require 'rubypitaya/core/main'
@@ -16,5 +18,38 @@ module RubyPitaya
16
18
 
17
19
  FileUtils.cp_r app_template_path, project_path
18
20
  end
21
+
22
+ def self.create_migration(migration_name)
23
+ migration_name = "#{migration_name}_migration" unless migration_name.underscore.end_with?('migration')
24
+ migration_timestamp = Time.now.utc.to_i
25
+ migration_file_name = "#{migration_timestamp}_#{migration_name.underscore}.rb"
26
+ migration_class_name = migration_name.camelcase
27
+
28
+ template_struct = OpenStruct.new(
29
+ class_name: migration_class_name,
30
+ )
31
+
32
+ template = File.open(Path::MIGRATION_TEMPLATE_PATH, &:read)
33
+ template_result = ERB.new(template).result(template_struct.instance_eval { binding })
34
+
35
+ migration_file_path = File.join(Path::MIGRATIONS_FOLDER_PATH, migration_file_name)
36
+ File.open(migration_file_path, 'w') { |f| f.write(template_result) }
37
+
38
+ migration_file_name
39
+ end
40
+
41
+ def self.add_plugin(plugin_git_link)
42
+ Dir.mkdir(Path::PLUGINS_FOLDER_PATH) unless File.exists?(Path::PLUGINS_FOLDER_PATH)
43
+
44
+ plugin_name = plugin_git_link.scan(/.+\/(.+)\.git/).flatten.first
45
+ plugin_folder_path = File.join(Path::PLUGINS_FOLDER_PATH, plugin_name)
46
+ plugin_git_path = File.join(plugin_folder_path, '.git/')
47
+
48
+ FileUtils.rm_rf(plugin_folder_path) if File.exists?(plugin_folder_path)
49
+ `git -C #{Path::PLUGINS_FOLDER_PATH} clone #{plugin_git_link}`
50
+ FileUtils.rm_rf(plugin_git_path)
51
+
52
+ plugin_name
53
+ end
19
54
  end
20
55
  end
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.7.5'
3
+ gem 'rubypitaya', '2.9.3'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.12.2'
@@ -18,11 +18,11 @@ GEM
18
18
  etcdv3 (0.10.2)
19
19
  grpc (~> 1.17)
20
20
  eventmachine (1.2.7)
21
- ffi (1.13.1)
21
+ ffi (1.14.2)
22
22
  google-protobuf (3.14.0)
23
23
  googleapis-common-protos-types (1.0.5)
24
24
  google-protobuf (~> 3.11)
25
- grpc (1.32.0)
25
+ grpc (1.34.0)
26
26
  google-protobuf (~> 3.13)
27
27
  googleapis-common-protos-types (~> 1.0)
28
28
  i18n (1.8.5)
@@ -38,6 +38,7 @@ GEM
38
38
  ruby2_keywords (~> 0.0.1)
39
39
  nats (0.11.0)
40
40
  eventmachine (~> 1.2, >= 1.2)
41
+ ostruct (0.1.0)
41
42
  pg (0.21.0)
42
43
  protobuf (3.10.0)
43
44
  activesupport (>= 3.2)
@@ -69,11 +70,12 @@ GEM
69
70
  rspec-support (~> 3.8.0)
70
71
  rspec-support (3.8.3)
71
72
  ruby2_keywords (0.0.2)
72
- rubypitaya (2.7.5)
73
+ rubypitaya (2.9.3)
73
74
  activerecord (= 6.0.2)
74
75
  etcdv3 (= 0.10.2)
75
76
  eventmachine (= 1.2.7)
76
77
  nats (= 0.11.0)
78
+ ostruct (= 0.1.0)
77
79
  pg (= 0.21.0)
78
80
  protobuf (= 3.10.0)
79
81
  rake (= 10.0)
@@ -94,7 +96,7 @@ GEM
94
96
  thor (1.0.1)
95
97
  thread_safe (0.3.6)
96
98
  tilt (2.0.10)
97
- tzinfo (1.2.8)
99
+ tzinfo (1.2.9)
98
100
  thread_safe (~> 0.1)
99
101
  zeitwerk (2.4.2)
100
102
 
@@ -106,7 +108,7 @@ DEPENDENCIES
106
108
  listen (= 3.2.1)
107
109
  pry (= 0.12.2)
108
110
  rspec (= 3.8.0)
109
- rubypitaya (= 2.7.5)
111
+ rubypitaya (= 2.9.3)
110
112
 
111
113
  BUNDLED WITH
112
114
  1.17.2
@@ -2,6 +2,9 @@ IMAGE_TAG ?= latest
2
2
  IMAGE_REGISTRY ?= [put-your-registry-here]
3
3
  KUBE_NAMESPACE ?= [put-your-namespace-here]
4
4
  KUBE_DEPLOYMENT_SERVER ?= rubypitaya
5
+ KUBECONTEXT ?= ''
6
+
7
+ ## + Server Commands
5
8
 
6
9
  ## Run ruby pitaya metagame project
7
10
  run:
@@ -11,14 +14,6 @@ run:
11
14
  build:
12
15
  @docker-compose build
13
16
 
14
- ## Kill all containers
15
- kill:
16
- @docker rm -f $$(docker-compose ps -aq)
17
-
18
- ## Run tests
19
- test:
20
- @docker-compose run --service-ports --rm rubypitaya bundle exec rspec
21
-
22
17
  ## Run ruby irb console
23
18
  console:
24
19
  @docker-compose run --service-ports --rm rubypitaya-console bundle exec ruby ./bin/console
@@ -27,6 +22,31 @@ console:
27
22
  bash:
28
23
  @docker-compose run --service-ports --rm rubypitaya bash
29
24
 
25
+ ## Run tests
26
+ test:
27
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rspec
28
+
29
+ ## Kill all containers
30
+ kill:
31
+ @docker rm -f $$(docker-compose ps -aq)
32
+
33
+ ## Update gems dependencies on Gemfile.lock
34
+ update-dependencies:
35
+ @rm -f Gemfile.lock
36
+ @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.6.6 bundle install
37
+
38
+ ## + Improve metagame
39
+
40
+ ## Create new migrgation. NAME=[migration-name]
41
+ create-migration:
42
+ @docker-compose run --service-ports --rm rubypitaya-console bundle exec rubypitaya create-migration $(NAME)
43
+
44
+ ## Add or update a plugim. GIT=[plugin-git-link]
45
+ add-plugin:
46
+ @docker-compose run --service-ports --rm rubypitaya-console bundle exec rubypitaya add-plugin $(GIT)
47
+
48
+ ## + Database Commands
49
+
30
50
  ## Create database
31
51
  db-create:
32
52
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
@@ -35,6 +55,10 @@ db-create:
35
55
  db-migrate:
36
56
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
37
57
 
58
+ ## Show migrations status on database
59
+ db-migrate-status:
60
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:status
61
+
38
62
  ## Rollback migrations STEP=1
39
63
  db-rollback:
40
64
  @docker-compose run --service-ports --rm -e STEP="$(STEP)" rubypitaya bundle exec rake db:rollback
@@ -47,9 +71,7 @@ db-drop:
47
71
  db-reset:
48
72
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
49
73
 
50
- ## Generate Gemfile.lock
51
- generate-gemfilelock:
52
- @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.6.6 bundle install
74
+ ## + Deployment commands
53
75
 
54
76
  ## Build image to production environment
55
77
  prod-build-image:
@@ -68,7 +90,6 @@ prod-deploy-image:
68
90
  .PHONY: show-help
69
91
  show-help:
70
92
  @echo "$$(tput bold)Commands:$$(tput sgr0)"
71
- @echo
72
93
  @sed -n -e "/^## / { \
73
94
  h; \
74
95
  s/.*//; \
@@ -83,14 +104,16 @@ show-help:
83
104
  s/\\n/ /g; \
84
105
  p; \
85
106
  }" ${MAKEFILE_LIST} \
86
- | LC_ALL='C' sort --ignore-case \
87
107
  | awk -F '---' \
88
108
  -v ncol=$$(tput cols) \
89
- -v indent=22 \
109
+ -v indent=19 \
90
110
  -v col_on="$$(tput setaf 6)" \
91
111
  -v col_off="$$(tput sgr0)" \
92
112
  '{ \
93
113
  printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
114
+ if (length($$1) == 0) { \
115
+ printf "\n"; \
116
+ } \
94
117
  n = split($$2, words, " "); \
95
118
  line_length = ncol - indent; \
96
119
  for (i = 1; i <= n; i++) { \
@@ -103,3 +126,6 @@ show-help:
103
126
  } \
104
127
  printf "\n"; \
105
128
  }'
129
+
130
+
131
+
@@ -75,6 +75,25 @@ namespace :db do
75
75
  puts 'Database deleted.'
76
76
  end
77
77
 
78
+ desc 'migration status'
79
+ task :status do
80
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
81
+ database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
82
+ connection_data = database_config.connection_data
83
+ migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
84
+ migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
85
+ migrations_paths += [RubyPitaya::Path::MIGRATIONS_FOLDER_PATH]
86
+
87
+ ActiveRecord::Base.establish_connection(connection_data)
88
+ ActiveRecord::Migrator.migrations_paths = migrations_paths
89
+ ActiveRecord::Base.connection.migration_context.migrations_status.each do |status, version, name|
90
+ puts "#{status.center(8)} #{version.ljust(14)} #{name}"
91
+ end
92
+ ActiveRecord::Base.connection.close
93
+
94
+ puts 'Rollback done.'
95
+ end
96
+
78
97
  desc 'Reset the database'
79
98
  task :reset do
80
99
  Rake::Task['db:drop'].invoke
@@ -34,7 +34,6 @@ module MyApp
34
34
  # - info
35
35
  # - log information
36
36
 
37
-
38
37
  def run(initializer_content)
39
38
  bll = initializer_content.bll
40
39
 
@@ -42,5 +41,9 @@ module MyApp
42
41
 
43
42
  bll.add_instance(:player, playerBll)
44
43
  end
44
+
45
+ def self.path
46
+ __FILE__
47
+ end
45
48
  end
46
49
  end
@@ -7,7 +7,9 @@ module MyApp
7
7
  def sayHello
8
8
  response = {
9
9
  code: 'RP-200',
10
- msg: 'Hello!'
10
+ data: {
11
+ message: 'Hello!'
12
+ }
11
13
  }
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ require 'rubypitaya/core/app/models/user'
2
+
1
3
  User.class_eval do
2
4
  # has_one :player
3
5
  end
@@ -6,25 +6,35 @@ require 'active_record'
6
6
  require 'rubypitaya'
7
7
  require 'rubypitaya/core/database_config'
8
8
 
9
+ # Database connection
9
10
  environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
10
11
  database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
11
12
  ActiveRecord::Base.establish_connection(database_config.connection_data)
12
13
  ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
13
14
  ActiveSupport::LogSubscriber.colorize_logging = true
14
15
 
16
+ # Loading core files
15
17
  Gem.find_files('rubypitaya/**/*.rb').each do |path|
16
18
  require path unless path.end_with?('spec.rb') ||
17
19
  path.include?('db/migration') ||
20
+ path.include?('core/templates') ||
18
21
  path.include?('app-template')
19
22
  end
20
23
 
21
- app_files_path = File.join(RubyPitaya::Path::APP_FOLDER_PATH, '**/*.rb')
22
- Dir[app_files_path].each do |path|
23
- require path unless path.end_with?('spec.rb') ||
24
- path.include?('db/migration')
24
+ # Loading application files
25
+ app_folder_paths = RubyPitaya::Path::Plugins::APP_FOLDER_PATHS + [RubyPitaya::Path::APP_FOLDER_PATH]
26
+ app_folder_paths.each do |app_folder_path|
27
+ app_files_path = File.join(app_folder_path, '**/*.rb')
28
+
29
+ Dir[app_files_path].each do |path|
30
+ require path unless path.end_with?('spec.rb') ||
31
+ path.include?('db/migration')
32
+ end
25
33
  end
26
34
 
35
+ # Starting irb
27
36
  require 'irb'
28
37
  IRB.start(__FILE__)
29
38
 
39
+ # Closing database connection
30
40
  ActiveRecord::Base.connection.close
@@ -16,7 +16,7 @@ spec:
16
16
  spec:
17
17
  containers:
18
18
  - name: rubypitaya
19
- image: git.topfreegames.com:4567/prestes/tech-prototype/rubypitaya:latest
19
+ image: registry.gitlab.com/lucianopc/ruby-pitaya:latest
20
20
  command: ["bundle", "exec", "rubypitaya", "run"]
21
21
  ports:
22
22
  - containerPort: 4567
@@ -45,4 +45,4 @@ spec:
45
45
  - name: DATABASE_NAME
46
46
  value: "ruby_pitaya"
47
47
  imagePullSecrets:
48
- - name: gitlab-registry
48
+ - name: gitlab-registry
@@ -2,6 +2,10 @@ module RubyPitaya
2
2
 
3
3
  class InitializerBase
4
4
 
5
+ def self.path
6
+ __FILE__
7
+ end
8
+
5
9
  def run(main)
6
10
  end
7
11
  end
@@ -6,7 +6,25 @@ module RubyPitaya
6
6
  class InitializerBroadcast
7
7
 
8
8
  def run(initializer_content)
9
+ app_classes = []
10
+ plugin_classes = []
11
+
9
12
  ObjectSpace.each_object(InitializerBase.singleton_class) do |klass|
13
+ is_plugin_class = klass.path.include?('plugins')
14
+
15
+ if is_plugin_class
16
+ plugin_classes << klass
17
+ else
18
+ app_classes << klass
19
+ end
20
+ end
21
+
22
+ plugin_classes.each do |klass|
23
+ instance = klass.new
24
+ instance.run(initializer_content)
25
+ end
26
+
27
+ app_classes.each do |klass|
10
28
  instance = klass.new
11
29
  instance.run(initializer_content)
12
30
  end
@@ -2,6 +2,7 @@ module RubyPitaya
2
2
 
3
3
  class Path
4
4
  APP_TEMPLATE_FOLDER_PATH = File.join(__dir__, '../app-template/')
5
+ MIGRATION_TEMPLATE_PATH = File.join(__dir__, 'templates/template_migration.rb.erb')
5
6
 
6
7
  DATABASE_CONFIG_PATH = File.join(Dir.pwd, 'config/database.yml')
7
8
 
@@ -10,11 +11,13 @@ module RubyPitaya
10
11
  APP_CONFIG_FOLDER_PATH = File.join(Dir.pwd, 'app/config/')
11
12
  APP_SETUP_FOLDER_PATH = File.join(Dir.pwd, 'app/setup/')
12
13
  MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/migration/')
14
+ PLUGINS_FOLDER_PATH = File.join(Dir.pwd, 'plugins/')
13
15
 
14
16
  ROUTES_FILE_PATH = File.join(Dir.pwd, 'config/routes.rb')
15
17
 
16
18
  HTTP_VIEWS_PATH = File.join(Dir.pwd, 'app/http/views')
17
19
 
20
+
18
21
  class Core
19
22
  APP_FOLDER_PATH = File.join(__dir__, 'app/')
20
23
  MIGRATIONS_FOLDER_PATH = File.join(__dir__, 'db/migration/')
@@ -0,0 +1,13 @@
1
+ require 'active_record'
2
+
3
+ class <%= class_name %> < ActiveRecord::Migration[5.1]
4
+
5
+ enable_extension 'pgcrypto'
6
+
7
+ def change
8
+ create_table :[table-name-here-in-plural], id: :uuid do |t|
9
+ # t.belongs_to :user, type: :uuid
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.7.5'
2
+ VERSION = '2.9.3'
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: 2.7.5
4
+ version: 2.9.3
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-12-02 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: ostruct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.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: 0.1.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: sinatra-contrib
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -285,6 +299,7 @@ files:
285
299
  - "./lib/rubypitaya/core/session.rb"
286
300
  - "./lib/rubypitaya/core/setup.rb"
287
301
  - "./lib/rubypitaya/core/status_codes.rb"
302
+ - "./lib/rubypitaya/core/templates/template_migration.rb.erb"
288
303
  - "./lib/rubypitaya/version.rb"
289
304
  - bin/rubypitaya
290
305
  homepage: https://gitlab.com/LucianoPC/ruby-pitaya