ru.Bee 1.5.4 → 1.7.0

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rubee +6 -295
  3. data/lib/app/views/index.html +1 -1
  4. data/lib/config/base_configuration.rb +25 -7
  5. data/lib/db/create_addresses.rb +17 -0
  6. data/lib/inits/charged_hash.rb +16 -0
  7. data/lib/inits/charged_string.rb +12 -0
  8. data/lib/js/app.js +3 -3
  9. data/lib/package.json +1 -1
  10. data/lib/rubee/async/fiber_queue.rb +27 -0
  11. data/lib/rubee/async/thread_async.rb +1 -1
  12. data/lib/rubee/async/thread_pool.rb +32 -34
  13. data/lib/rubee/autoload.rb +86 -0
  14. data/lib/rubee/cli/attach.rb +124 -0
  15. data/lib/rubee/cli/command.rb +41 -0
  16. data/lib/rubee/cli/console.rb +39 -0
  17. data/lib/rubee/cli/db.rb +105 -0
  18. data/lib/rubee/cli/generate.rb +33 -0
  19. data/lib/rubee/cli/project.rb +124 -0
  20. data/lib/rubee/cli/react.rb +28 -0
  21. data/lib/rubee/cli/routes.rb +18 -0
  22. data/lib/rubee/cli/server.rb +52 -0
  23. data/lib/rubee/cli/test.rb +24 -0
  24. data/lib/rubee/cli/version.rb +15 -0
  25. data/lib/rubee/configuration.rb +83 -0
  26. data/lib/rubee/controllers/base_controller.rb +12 -6
  27. data/lib/rubee/controllers/extensions/auth_tokenable.rb +2 -2
  28. data/lib/rubee/extensions/hookable.rb +9 -2
  29. data/lib/rubee/generator.rb +160 -0
  30. data/lib/rubee/logger.rb +83 -0
  31. data/lib/rubee/models/database_objectable.rb +1 -1
  32. data/lib/rubee/models/sequel_object.rb +3 -3
  33. data/lib/rubee/router.rb +40 -0
  34. data/lib/rubee.rb +13 -317
  35. data/lib/tests/async/thread_async_test.rb +9 -5
  36. data/lib/tests/cli/attach_test.rb +36 -0
  37. data/lib/tests/{auth_tokenable_test.rb → controllers/auth_tokenable_test.rb} +2 -2
  38. data/lib/tests/controllers/base_controller_test.rb +23 -0
  39. data/lib/tests/controllers/hookable_test.rb +220 -0
  40. data/lib/tests/{rubeeapp_test.rb → controllers/rubeeapp_test.rb} +3 -2
  41. data/lib/tests/example_models/address.rb +5 -0
  42. data/lib/tests/example_models/user.rb +1 -0
  43. data/lib/tests/logger_test.rb +76 -0
  44. data/lib/tests/{account_model_test.rb → models/account_model_test.rb} +1 -1
  45. data/lib/tests/{comment_model_test.rb → models/comment_model_test.rb} +13 -1
  46. data/lib/tests/models/db_objectable_test.rb +21 -0
  47. data/lib/tests/models/seralizable_test.rb +36 -0
  48. data/lib/tests/{user_model_test.rb → models/user_model_test.rb} +32 -1
  49. data/lib/tests/rubee_attach_test.rb +0 -0
  50. data/lib/tests/test.db +0 -0
  51. data/lib/tests/test_helper.rb +20 -2
  52. data/readme.md +174 -15
  53. metadata +34 -9
  54. data/lib/app/views/apples_.erb +0 -1
  55. data/lib/app/views/s_.erb +0 -1
  56. /data/lib/app/views/{app.tsx → App.tsx} +0 -0
@@ -0,0 +1,124 @@
1
+ module Rubee
2
+ module CLI
3
+ class Attach
4
+ using ChargedString
5
+
6
+ class << self
7
+ def call(command, argv)
8
+ send(command, argv)
9
+ end
10
+
11
+ def attach(argv)
12
+ new_app_name = argv[1]
13
+
14
+ # create project folde
15
+ if new_app_name.nil?
16
+ color_puts('Please indicate app name.', color: :red)
17
+ exit(1)
18
+ end
19
+
20
+ if new_app_name == 'rubee'
21
+ color_puts("Error: App 'rubee' name is reserved", color: :red)
22
+ exit(1)
23
+ end
24
+ target_dir = File.join(Rubee::APP_ROOT, new_app_name)
25
+
26
+ if Dir.exist?(target_dir)
27
+ color_puts("Error: App #{new_app_name} already exists!", color: :red)
28
+ exit(1)
29
+ end
30
+
31
+ # create controllers models view folders
32
+ FileUtils.mkdir_p(target_dir)
33
+ # creare controllers models views dirs
34
+ ['controllers', 'models', 'views'].each do |dir|
35
+ FileUtils.mkdir_p("#{target_dir}/#{dir}")
36
+ end
37
+
38
+ config_file = <<~CONFIG_FILE
39
+ Rubee::Configuration.setup(env = :test, app = :#{new_app_name}) do |config|
40
+ end
41
+ Rubee::Configuration.setup(env = :developmenti, app = :#{new_app_name}) do |config|
42
+ end
43
+ Rubee::Configuration.setup(env = :production, app = :#{new_app_name}) do |config|
44
+ end
45
+ CONFIG_FILE
46
+
47
+ File.open("#{target_dir}/#{new_app_name}_configuration.rb", 'w') do |file|
48
+ file.puts config_file
49
+ end
50
+
51
+ # create app routes.rb file
52
+ route_file = <<~ROUTE_FILE
53
+ Rubee::Router.draw do |router|
54
+ end
55
+ ROUTE_FILE
56
+
57
+ File.open("#{target_dir}/#{new_app_name}_routes.rb", 'w') do |file|
58
+ file.puts route_file
59
+ end
60
+
61
+ # copy views
62
+ copy_files(
63
+ File.join(Rubee::ROOT_PATH, '/lib/app/views'),
64
+ "#{target_dir}/views",
65
+ %w[welcome_header.erb welcome_show.erb App.tsx],
66
+ %w[utils],
67
+ app_name: new_app_name
68
+ )
69
+
70
+ # create namespace module
71
+ module_content = <<~RUBY
72
+ module #{new_app_name.camelize}
73
+ end
74
+ RUBY
75
+
76
+ File.open("#{target_dir}/#{new_app_name.snakeize}_namespace.rb", 'w') { |file| file.write(module_content) }
77
+ color_puts("App #{new_app_name} attached!", color: :green)
78
+
79
+ # create react app file
80
+ react_app_file = <<~REACT_APP_FILE
81
+ import React from 'react';
82
+
83
+ export function #{new_app_name.camelize}App() {
84
+ return (
85
+ <h1>#{new_app_name.camelize}App</h1>
86
+ );
87
+ }
88
+ REACT_APP_FILE
89
+
90
+ File.open("#{target_dir}/views/#{new_app_name.camelize}App.tsx", 'w') do |file|
91
+ file.puts react_app_file
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def copy_files(source_dir, target_dir, blacklist_files = [], blacklist_dirs = [], **options)
98
+ Dir.glob("#{source_dir}/**/*", File::FNM_DOTMATCH).each do |file|
99
+ relative_path = file.sub("#{source_dir}/", '')
100
+ next if blacklist_dirs.any? { |dir| relative_path.split('/').include?(dir) }
101
+ next if blacklist_files.include?(File.basename(file))
102
+
103
+ target_path = File.join(target_dir, relative_path)
104
+ if File.directory?(file)
105
+ FileUtils.mkdir_p(target_path)
106
+ else
107
+ FileUtils.cp(file, target_path)
108
+ end
109
+ end
110
+ return unless options[:app_name]
111
+ # rename copied file with prefixing base name with app_name
112
+ Dir["#{target_dir}/**/*"].each do |f|
113
+ ext = File.extname(f).delete('.')
114
+ if %w[ts tsx js jsx].include?(ext)
115
+ File.rename(f, f.gsub(File.basename(f), "#{options[:app_name].camelize}#{File.basename(f)}"))
116
+ else
117
+ File.rename(f, f.gsub(File.basename(f), "#{options[:app_name].snakeize}_#{File.basename(f)}"))
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,41 @@
1
+ module Rubee
2
+ module CLI
3
+ class Command
4
+ def initialize(argv)
5
+ @command = argv[0]
6
+ @argv = argv
7
+ end
8
+
9
+ def call
10
+ factory.call(@command, @argv)
11
+ end
12
+
13
+ def factory
14
+ case @command
15
+ in /^(start|start_dev|stop|status)$/
16
+ Rubee::CLI::Server
17
+ in /^react$/
18
+ Rubee::CLI::React
19
+ in /^project$/
20
+ Rubee::CLI::Project
21
+ in /^version$/
22
+ Rubee::CLI::Version
23
+ in /^routes$/
24
+ Rubee::CLI::Routes
25
+ in /^test$/
26
+ Rubee::CLI::Test
27
+ in /^(generate|gen)$/
28
+ Rubee::CLI::Generate
29
+ in /^db$/
30
+ Rubee::CLI::Db
31
+ in /^(console|c)$/
32
+ Rubee::CLI::Console
33
+ in /^(attach|att)$/
34
+ Rubee::CLI::Attach
35
+ else
36
+ proc { color_puts("Unknown command: #{@command}", color: :red) }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ module Rubee
2
+ module CLI
3
+ module Console
4
+ class << self
5
+ def call(command, argv)
6
+ send(command, argv)
7
+ end
8
+
9
+ def console(argv)
10
+ argv.clear
11
+ ENV['RACK_ENV'] ||= 'development'
12
+
13
+ if Rubee::PROJECT_NAME == 'rubee'
14
+ Rubee::Configuration.setup(env = :test) do |config|
15
+ config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
16
+ end
17
+ # Rubee::Autoload.call
18
+ # Rubee::SequelObject.reconnect!
19
+ end
20
+
21
+ def reload
22
+ app_files = Dir["./#{Rubee::APP_ROOT}/**/*.rb"]
23
+ app_files.each { |file| load(file) }
24
+ color_puts('Reloaded ..', color: :green)
25
+ end
26
+
27
+ begin
28
+ # Start IRB
29
+ IRB.start
30
+ rescue => _e
31
+ IRB.start
32
+ end
33
+ end
34
+
35
+ alias_method :c, :console
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,105 @@
1
+ module Rubee
2
+ module CLI
3
+ module Db
4
+ class << self
5
+ def call(command, argv)
6
+ command = argv[1].split(':').first
7
+ ENV['RACK_ENV'] ||= 'development'
8
+ if Rubee::PROJECT_NAME == 'rubee'
9
+ Rubee::Configuration.setup(env = :test) do |config|
10
+ config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
11
+ end
12
+ Rubee::SequelObject.reconnect! unless command == 'init'
13
+ end
14
+
15
+ send(command, argv)
16
+ end
17
+
18
+ def run(argv)
19
+ _, file_name = argv[1]&.split(':')
20
+ file_names = if file_name == 'all'
21
+ lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
22
+ Dir.glob(".#{lib}/db/*.rb").map do |file|
23
+ File.basename(file, '.rb')
24
+ end.reject { |file| file == 'structure' }
25
+ else
26
+ [file_name]
27
+ end
28
+ Rubee::Configuration.envs.each do |env|
29
+ ENV['RACK_ENV'] = env.to_s
30
+ file_names.each do |file|
31
+ color_puts("Run #{file} file for #{env} env", color: :cyan)
32
+ Object.const_get(file.split('_').map(&:capitalize).join).new.call
33
+ end
34
+ end
35
+ color_puts("Migration for #{file_name} completed", color: :green)
36
+ unless Rubee::PROJECT_NAME == 'rubee'
37
+ color_puts('Regenerate schema file', color: :cyan)
38
+ generate_structure
39
+ end
40
+ end
41
+
42
+ def init(_argv)
43
+ ensure_database_exists(Rubee::Configuration.get_database_url)
44
+ end
45
+
46
+ def structure(_argv)
47
+ generate_structure
48
+ end
49
+
50
+ private
51
+
52
+ def generate_structure
53
+ schema_hash = {}
54
+
55
+ Rubee::SequelObject::DB.tables.each do |table|
56
+ schema_hash[table] = {}
57
+
58
+ Rubee::SequelObject::DB.schema(table).each do |column, details|
59
+ schema_hash[table][column] = details
60
+ end
61
+ end
62
+ formatted_hash = JSON.pretty_generate(schema_hash)
63
+ .gsub(/"(\w+)":/, '\1:') # Convert keys to symbols
64
+ .gsub(': null', ': nil') # Convert `null` to `nil`
65
+
66
+ File.open('db/structure.rb', 'w') do |file|
67
+ file.puts "STRUCTURE = #{formatted_hash}"
68
+ end
69
+
70
+ color_puts('db/structure.rb updated', color: :green)
71
+ end
72
+
73
+ def ensure_database_exists(db_url)
74
+ uri = URI.parse(db_url)
75
+ case uri.scheme
76
+ when 'sqlite'
77
+ begin
78
+ Sequel.connect(db_url)
79
+ color_puts("Database #{ENV['RACK_ENV']} exists", color: :cyan)
80
+ rescue => _e
81
+ if File.exist?(db_path = db_url.sub(%r{^sqlite://}, ''))
82
+ color_puts("Database #{ENV['RACK_ENV']} exists", color: :cyan)
83
+ else
84
+ Sequel.sqlite(db_path)
85
+ color_puts("Database #{ENV['RACK_ENV']} created", color: :green)
86
+ end
87
+ end
88
+ when 'postgres'
89
+ begin
90
+ Sequel.connect(db_url)
91
+ color_puts("Database #{ENV['RACK_ENV']} exists", color: :cyan)
92
+ rescue StandardError => _e
93
+ con = Sequel.connect(Rubee::Configuration.get_database_url.gsub(%r{(/test|/development|/production)},
94
+ ''))
95
+ con.run("CREATE DATABASE #{ENV['RACK_ENV']}")
96
+ color_puts("Database #{ENV['RACK_ENV']} created", color: :green)
97
+ end
98
+ else
99
+ color_puts("Unsupported database type: #{db_url}", color: :red)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,33 @@
1
+ module Rubee
2
+ module CLI
3
+ module Generate
4
+ class << self
5
+ def call(command, argv)
6
+ send(command, argv)
7
+ end
8
+
9
+ def generate(argv)
10
+ method, path = argv[1..2]
11
+ app = argv[3]
12
+ app_name = app.nil? ? :app : app.split(':')[1]
13
+ ENV['RACK_ENV'] ||= 'development'
14
+ file = Rubee::PROJECT_NAME == 'rubee' ? File.join(Dir.pwd, '/lib', 'config/routes.rb') : 'config/routes.rb'
15
+ routes = eval(File.read(file))
16
+ route = routes.find { |route| route[:path] == path.to_s && route[:method] == method.to_sym }
17
+
18
+ color_puts("Route not found with path: #{path} and method: #{method}", color: :red) unless route
19
+ Rubee::Generator.new(
20
+ route[:model]&.[](:name),
21
+ route[:model]&.[](:attributes),
22
+ "#{route[:controller]&.capitalize}Controller",
23
+ route[:action],
24
+ react: route[:react],
25
+ app_name:
26
+ ).call
27
+ end
28
+
29
+ alias_method :gen, :generate
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,124 @@
1
+ module Rubee
2
+ module CLI
3
+ class Project
4
+ class << self
5
+ def call(command, argv)
6
+ send(command, argv)
7
+ end
8
+
9
+ def project(argv)
10
+ project_name = argv[1]
11
+
12
+ if project_name.nil?
13
+ color_puts('Please indicate project name.', color: :red)
14
+ exit(1)
15
+ end
16
+
17
+ if project_name == 'rubee'
18
+ color_puts("Error: Project 'rubee' is reserved", color: :red)
19
+ exit(1)
20
+ end
21
+ source_dir = File.join(Rubee::ROOT_PATH, '/lib')
22
+ target_dir = File.expand_path("./#{project_name}", Dir.pwd)
23
+
24
+ if Dir.exist?(target_dir)
25
+ color_puts("Error: Project #{project_name} already exists!", color: :red)
26
+ exit(1)
27
+ end
28
+ # Create target directory
29
+ FileUtils.mkdir_p(target_dir)
30
+ # Define blacklist
31
+ blacklist_files = %w[rubee.rb print_colors.rb version.rb config.ru test_helper.rb Gemfile.lock test.yml test.db
32
+ development.db production.db]
33
+ blacklist_dirs = %w[rubee tests .git .github .idea node_modules db inits]
34
+ # Copy files, excluding blacklisted ones
35
+ copy_project_files(source_dir, target_dir, blacklist_files, blacklist_dirs)
36
+ # create tests dir and copy test_helper.rb and user_model_test.rb
37
+ setup_test_structure(target_dir, source_dir)
38
+ # create db dir
39
+ setup_db_structure(target_dir, source_dir)
40
+ # create inits dir
41
+ FileUtils.mkdir_p("#{target_dir}/inits")
42
+ # create a gemfile context
43
+ setup_gemfile(target_dir)
44
+ color_puts("Project #{project_name} created successfully at #{target_dir}", color: :green)
45
+ end
46
+
47
+ private
48
+
49
+ def copy_project_files(source_dir, target_dir, blacklist_files, blacklist_dirs)
50
+ Dir.glob("#{source_dir}/**/*", File::FNM_DOTMATCH).each do |file|
51
+ relative_path = file.sub("#{source_dir}/", '')
52
+ # Skip blacklisted directories
53
+ next if blacklist_dirs.any? { |dir| relative_path.split('/').include?(dir) }
54
+ # Skip blacklisted files
55
+ next if blacklist_files.include?(File.basename(file))
56
+
57
+ target_path = File.join(target_dir, relative_path)
58
+ if File.directory?(file)
59
+ FileUtils.mkdir_p(target_path)
60
+ else
61
+ FileUtils.cp(file, target_path)
62
+ end
63
+ end
64
+ end
65
+
66
+ def setup_test_structure(target_dir, source_dir)
67
+ FileUtils.mkdir_p("#{target_dir}/tests")
68
+ FileUtils.mkdir_p("#{target_dir}/tests/models")
69
+ FileUtils.mkdir_p("#{target_dir}/tests/controllers")
70
+ FileUtils.cp("#{source_dir}/tests/models/user_model_test.rb", "#{target_dir}/tests/models/user_model_test.rb")
71
+
72
+ # create test_helper.rb file
73
+ test_helper = <<~TESTHELPER
74
+ require "bundler/setup"
75
+ Bundler.require(:test)
76
+
77
+ require 'minitest/autorun'
78
+ require 'rack/test'
79
+ require 'rubee'
80
+
81
+ Rubee::Autoload.call
82
+ TESTHELPER
83
+
84
+ File.open("#{target_dir}/tests/test_helper.rb", 'w') do |file|
85
+ file.puts test_helper
86
+ end
87
+ end
88
+
89
+ def setup_db_structure(target_dir, source_dir)
90
+ FileUtils.mkdir_p("#{target_dir}/db")
91
+ FileUtils.cp("#{source_dir}/db/structure.rb", "#{target_dir}/db/structure.rb")
92
+ FileUtils.cp("#{source_dir}/db/create_users.rb", "#{target_dir}/db/create_users.rb")
93
+ end
94
+
95
+ def setup_gemfile(target_dir)
96
+ gemfile = <<~GEMFILE
97
+ source 'https://rubygems.org'
98
+
99
+ gem 'ru.Bee'
100
+ gem 'sequel'
101
+ gem 'sqlite3'
102
+ gem 'rake'
103
+ gem 'rack'
104
+ gem 'rackup'
105
+ gem 'pry'
106
+ gem 'pry-byebug'
107
+ gem 'puma'
108
+ gem 'json'
109
+
110
+ group :development do
111
+ gem 'rerun'
112
+ gem 'minitest'
113
+ gem 'rack-test'
114
+ end
115
+ GEMFILE
116
+ # create a gemfile
117
+ File.open("#{target_dir}/Gemfile", 'w') do |file|
118
+ file.puts gemfile
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,28 @@
1
+ module Rubee
2
+ module CLI
3
+ class React
4
+ class << self
5
+ def call(command, argv)
6
+ command = argv[1]
7
+ send(command, argv)
8
+ end
9
+
10
+ def prepare(_argv)
11
+ if Rubee::PROJECT_NAME == 'rubee'
12
+ exec('cd ./lib && npm run prepare')
13
+ else
14
+ exec('npm run prepare')
15
+ end
16
+ end
17
+
18
+ def watch(_argv)
19
+ if Rubee::PROJECT_NAME == 'rubee'
20
+ exec('cd ./lib && npm run watch')
21
+ else
22
+ exec('npm run watch')
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ module Rubee
2
+ module CLI
3
+ class Routes
4
+ class << self
5
+ def call(command, argv)
6
+ send(command, argv)
7
+ end
8
+
9
+ def routes(_argv)
10
+ file = Rubee::PROJECT_NAME == 'rubee' ? File.join(Dir.pwd, '/lib', 'config/routes.rb') : 'config/routes.rb'
11
+ routes = eval(File.read(file)) # TODO: rewrite it omitting eval
12
+
13
+ color_puts(routes, color: :green)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ module Rubee
2
+ module CLI
3
+ class Server
4
+ LOGO = <<-'LOGO'
5
+ ____ _ _ ____ _____
6
+ | _ \| | | || __ )| ____|
7
+ | |_) | | | || _ \| _|
8
+ | _ <| |__| || |_) | |___
9
+ |_| \_\\____/ |____/|_____|
10
+ Ver: %s
11
+ LOGO
12
+
13
+ class << self
14
+ def call(command, argv)
15
+ send(command, argv)
16
+ end
17
+
18
+ def start(argv)
19
+ _, port = argv.first&.split(':')
20
+
21
+ port ||= '7000'
22
+ print_logo
23
+ color_puts("Starting takeoff of ruBee server on port #{port}...", color: :yellow)
24
+ exec("rackup #{ENV['RACKUP_FILE']} -p #{port}")
25
+ end
26
+
27
+ def start_dev(argv)
28
+ _, port = argv.first&.split(':')
29
+
30
+ port ||= '7000'
31
+ print_logo
32
+
33
+ color_puts("Starting takeoff of ruBee server on port #{port} in dev mode...", color: :yellow)
34
+
35
+ exec("rerun -- rackup --port #{port} #{ENV['RACKUP_FILE']}")
36
+ end
37
+
38
+ def stop(_argv)
39
+ exec('pkill -f rubee')
40
+ end
41
+
42
+ def status(_argv)
43
+ exec('ps aux | grep rubee')
44
+ end
45
+
46
+ def print_logo
47
+ puts "\e[36m#{LOGO % Rubee::VERSION}\e[0m" # Cyan color
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,24 @@
1
+ module Rubee
2
+ module CLI
3
+ module Test
4
+ class << self
5
+ def call(command, argv)
6
+ send(command, argv)
7
+ end
8
+
9
+ def test(argv)
10
+ ENV['RACK_ENV'] = 'test'
11
+ file_name = argv[1] # Get the first argument
12
+ lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
13
+ if file_name
14
+ color_puts("Running #{file_name} test ...", color: :yellow)
15
+ exec("ruby -Itest -e \"require '.#{lib}/tests/#{file_name}'\"")
16
+ else
17
+ color_puts('Running all tests ...', color: :yellow)
18
+ exec("ruby -Itest -e \"Dir.glob('.#{lib}/tests/**/*_test.rb').each { |file| require file }\"")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module Rubee
2
+ module CLI
3
+ class Version
4
+ class << self
5
+ def call(command, argv)
6
+ send(command, argv)
7
+ end
8
+
9
+ def version(_argv)
10
+ color_puts("ruBee v#{Rubee::VERSION}", color: :yellow)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,83 @@
1
+ module Rubee
2
+ class Configuration
3
+ include Singleton
4
+ require_relative '../inits/charged_hash' unless defined?(ChargedHash)
5
+ using ChargedHash
6
+
7
+ @configuraiton = {
8
+ app: {
9
+ development: {
10
+ database_url: '',
11
+ port: 7000,
12
+ },
13
+ production: {},
14
+ test: {},
15
+ },
16
+ }
17
+
18
+ class << self
19
+ def setup(env, app = :app)
20
+ unless @configuraiton[app.to_sym]
21
+ @configuraiton[app.to_sym] = {
22
+ development: {},
23
+ production: {},
24
+ test: {},
25
+ }
26
+ unless @configuraiton[app.to_sym][env.to_sym]
27
+ @configuraiton[app.to_sym][env.to_sym] = {}
28
+ end
29
+ end
30
+
31
+ yield(self)
32
+ end
33
+
34
+ def database_url=(args)
35
+ args[:app] ||= :app
36
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:database_url] = args[:url]
37
+ end
38
+
39
+ def async_adapter=(args)
40
+ args[:app] ||= :app
41
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:async_adapter] = args[:async_adapter]
42
+ end
43
+
44
+ def threads_limit=(args)
45
+ args[:app] ||= :app
46
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:thread_pool_limit] = args[:value]
47
+ end
48
+
49
+ def fibers_limit=(args)
50
+ args[:app] ||= :app
51
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:fiber_pool_limit] = args[:value]
52
+ end
53
+
54
+ def logger=(args)
55
+ args[:app] ||= :app
56
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:logger] = args[:logger]
57
+ end
58
+
59
+ def react=(args)
60
+ args[:app] ||= :app
61
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:react] ||= { on: false }
62
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:react].merge!(on: args[:on])
63
+ end
64
+
65
+ def react(**args)
66
+ args[:app] ||= :app
67
+ @configuraiton[args[:app].to_sym][ENV['RACK_ENV']&.to_sym || :development][:react] || {}
68
+ end
69
+
70
+ def method_missing(method_name, *args)
71
+ return unless method_name.to_s.start_with?('get_')
72
+
73
+ app_name = args[0] || :app
74
+ @configuraiton[app_name.to_sym][ENV['RACK_ENV']&.to_sym || :development]
75
+ &.[](method_name.to_s.delete_prefix('get_').to_sym)
76
+ end
77
+
78
+ def envs
79
+ @configuraiton.keys
80
+ end
81
+ end
82
+ end
83
+ end