ru.Bee 1.1.3 → 1.1.32

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: 6e8955bd33a079fb958c40784fa0eff94bae99964644fc03eeba77afb442382e
4
- data.tar.gz: 605a6479ae2db28de410d9dd78c80995af794c1ccc8c0d02981241aa69e2a749
3
+ metadata.gz: '03808642660607dcc9ecbd0f6f2fbcfc510e48f28e4eb583a0aace626642142f'
4
+ data.tar.gz: 11156690b45851b45f1ebeae3dff18ee8c9b44e2f3bef0a84d63a123f5e603a6
5
5
  SHA512:
6
- metadata.gz: 908ca83c33213cbe985b7b88a989b236aafe4a7ea02a1206da6bc4a25234f2fcc5188ea020cb9dc73424d5a9c50aa565f6edb7f83f5b4b5af46a5cad5090bdcf
7
- data.tar.gz: f85099cede5b96316373f0b4babb062dff1dad206743042325e1afaca76ef9b6ee57464349c4b47c785e39798c76a6c3034ac8ba87925eb0a5d0713e9a3548b8
6
+ metadata.gz: 5b48a1ccc2b3c7c9f7a5eb9492f8fca77488d842599d1a38a6d64f2f2534e41d1e69d69de7aa6d045935c98578ad9b77b36ccedbbd72f3b4086b8855e8e87b4d
7
+ data.tar.gz: 0c7067e04ddb2039b84a734a29ed743dcd187ea0ff8a21d076bd9c1c06d6413105c1c631b398c35186ee84c5a2d08c011cb24ed6b80bba0de57a3379f1d54d1b
data/bin/rubee CHANGED
@@ -9,7 +9,6 @@ require 'json'
9
9
  require 'rack'
10
10
  require 'rackup'
11
11
 
12
- require_relative '../lib/version'
13
12
  require_relative '../lib/inits/print_colors'
14
13
  require_relative '../lib/rubee'
15
14
 
@@ -30,7 +29,7 @@ LOGO
30
29
  command = ARGV.first
31
30
 
32
31
  def print_logo
33
- puts "\e[36m" + (LOGO % VERSION) + "\e[0m" # Cyan color
32
+ puts "\e[36m" + (LOGO % Rubee::VERSION) + "\e[0m" # Cyan color
34
33
  end
35
34
 
36
35
  if command =~ /^(start)$|^(start:(\d+))$/
@@ -60,6 +59,11 @@ elsif command == "project"
60
59
  exit 1
61
60
  end
62
61
 
62
+ if project_name == "rubee"
63
+ color_puts "Error: Project 'rubee' is reserved", color: :red
64
+ exit 1
65
+ end
66
+
63
67
  source_dir = File.expand_path("../lib", __dir__)
64
68
  target_dir = File.expand_path("./#{project_name}", Dir.pwd)
65
69
 
@@ -72,8 +76,8 @@ elsif command == "project"
72
76
  FileUtils.mkdir_p(target_dir)
73
77
 
74
78
  # Define blacklist
75
- blacklist_files = %w[rubee.rb print_colors.rb version.rb config.ru]
76
- blacklist_dirs = %w[rubee]
79
+ blacklist_files = %w[rubee.rb print_colors.rb version.rb config.ru test_helper.rb Gemfile.lock test.yml test.db development.db production.db]
80
+ blacklist_dirs = %w[rubee tests .git .github .idea]
77
81
 
78
82
  # Copy files, excluding blacklisted ones
79
83
  Dir.glob("#{source_dir}/**/*", File::FNM_DOTMATCH).each do |file|
@@ -94,6 +98,10 @@ elsif command == "project"
94
98
  end
95
99
  end
96
100
 
101
+ # create tests dir and copy test_helper.rb and user_model_test.rb
102
+ FileUtils.mkdir_p("#{target_dir}/tests")
103
+ FileUtils.cp("#{source_dir}/tests/user_model_test.rb", "#{target_dir}/tests/user_model_test.rb")
104
+
97
105
  # create a gemfile context
98
106
  gemfile = <<~GEMFILE
99
107
  source 'https://rubygems.org'
@@ -120,20 +128,37 @@ elsif command == "project"
120
128
  file.puts gemfile
121
129
  end
122
130
 
131
+ # create test_helper.rb file
132
+ test_helper = <<~TESTHELPER
133
+ require "bundler/setup"
134
+ Bundler.require(:test)
135
+
136
+ require 'minitest/autorun'
137
+ require 'rack/test'
138
+ require 'rubee'
139
+
140
+ Rubee::Autoload.call
141
+ TESTHELPER
142
+
143
+ File.open("#{target_dir}/tests/test_helper.rb", 'w') do |file|
144
+ file.puts test_helper
145
+ end
146
+
123
147
  color_puts "Project #{project_name} created successfully at #{target_dir}", color: :green
124
148
 
125
149
  elsif command == "version"
126
- puts "ruBee v#{VERSION}"
150
+ color_puts "ru.Bee v#{Rubee::VERSION}", color: :yellow
127
151
  elsif command == "test"
152
+
128
153
  ENV['RACK_ENV'] = 'test'
129
154
  file_name = ARGV[1] # Get the first argument
130
-
155
+ lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
131
156
  if file_name
132
157
  color_puts "Running #{file_name} test ...", color: :yellow
133
- exec("ruby -Itest -e \"require './tests/#{file_name}'\"")
158
+ exec("ruby -Itest -e \"require '.#{lib}/tests/#{file_name}'\"")
134
159
  else
135
160
  color_puts "Running all tests ...", color: :yellow
136
- exec("ruby -Itest -e \"Dir.glob('./tests/**/*_test.rb').each { |file| require file }\"")
161
+ exec("ruby -Itest -e \"Dir.glob('.#{lib}/tests/**/*_test.rb').each { |file| require file }\"")
137
162
  end
138
163
  elsif ['generate', 'g'].include? command
139
164
  method, path = ARGV[1..2]
@@ -154,7 +179,12 @@ elsif command == "db"
154
179
  ENV['RACK_ENV'] ||= 'development'
155
180
 
156
181
  command, file_name = ARGV[1]&.split(':')
157
-
182
+ if Rubee::PROJECT_NAME == 'rubee'
183
+ Rubee::Configuration.setup(env=:test) do |config|
184
+ config.database_url = { url: "sqlite://test.db", env: }
185
+ end
186
+ Rubee::SequelObject.reconnect!
187
+ end
158
188
 
159
189
  def ensure_database_exists(db_url)
160
190
  uri = URI.parse(db_url)
@@ -207,7 +237,7 @@ elsif command == "db"
207
237
  end
208
238
 
209
239
 
210
- if command == 'run'
240
+ if command == 'run'
211
241
  Rubee::Autoload.call
212
242
  Rubee::Configuration.envs.each do |env|
213
243
  ENV['RACK_ENV'] = env.to_s
@@ -215,8 +245,10 @@ elsif command == "db"
215
245
  Object.const_get(file_name.split('_').map(&:capitalize).join).new.call
216
246
  end
217
247
  color_puts "Migration #{file_name} completed", color: :green
218
- color_puts "Regenerate schema file", color: :cyan
219
- generate_structure
248
+ unless Rubee::PROJECT_NAME == 'rubee'
249
+ color_puts "Regenerate schema file", color: :cyan
250
+ generate_structure
251
+ end
220
252
  elsif command == 'init'
221
253
  ensure_database_exists(Rubee::Configuration.get_database_url)
222
254
  elsif command == 'structure'
data/bin/test.db ADDED
Binary file
@@ -43,7 +43,8 @@ module Rubee
43
43
  else # rendering erb view is a default behavior
44
44
  view_file_name = self.class.name.split("Controller").first.downcase
45
45
  erb_file = render_view ? "#{render_view}.erb" : "#{view_file_name}_#{@route[:action]}.erb"
46
- rendered_erb = ERB.new(File.open("app/views/#{erb_file}").read).result(binding)
46
+ lib = Rubee::PROJECT_NAME == 'rubee' ? 'lib/' : ''
47
+ rendered_erb = ERB.new(File.open("#{lib}app/views/#{erb_file}").read).result(binding)
47
48
  return [status, headers.merge("content-type" => "text/html"), [rendered_erb]]
48
49
  end
49
50
  end
@@ -11,7 +11,7 @@ module Rubee
11
11
  base.include(InstanceMethods)
12
12
  base.extend(ClassMethods)
13
13
 
14
- base.attach('AuthTokenMiddleware')
14
+ base.attach('Rubee::AuthTokenMiddleware')
15
15
  end
16
16
 
17
17
  module InstanceMethods
@@ -50,6 +50,10 @@ module Rubee
50
50
  nil
51
51
  end
52
52
 
53
+ def reconnect!
54
+ const_set(:DB, Sequel.connect(Rubee::Configuration.get_database_url))
55
+ end
56
+
53
57
  def connection
54
58
  @connection ||= DB[pluralize_class_name.to_sym]
55
59
  end
data/lib/rubee.rb CHANGED
@@ -8,6 +8,7 @@ module Rubee
8
8
  APP_ROOT = File.expand_path(Dir.pwd) unless defined?(APP_ROOT)
9
9
  IMAGE_DIR = File.join(APP_ROOT, 'images') unless defined?(IMAGE_DIR)
10
10
  PROJECT_NAME = File.basename(APP_ROOT) unless defined?(PROJECT_NAME)
11
+ VERSION = '1.1.32'
11
12
 
12
13
  class Application
13
14
  include Singleton
@@ -146,8 +147,9 @@ module Rubee
146
147
  require_relative file unless black_list.include?("#{file}.rb")
147
148
  end
148
149
  # app config and routes
149
- require_relative File.join(APP_ROOT, "config/base_configuration") unless black_list.include?('base_configuration.rb')
150
- require_relative File.join(APP_ROOT, "config/routes") unless black_list.include?('routes.rb')
150
+ lib = PROJECT_NAME == 'rubee' ? 'lib/' : ''
151
+ require_relative File.join(APP_ROOT, lib, "config/base_configuration") unless black_list.include?('base_configuration.rb')
152
+ require_relative File.join(APP_ROOT, lib, "config/routes") unless black_list.include?('routes.rb')
151
153
  # rubee extensions
152
154
  Dir[File.join(root_directory, "rubee/extensions/**", '*.rb')].each do |file|
153
155
  require_relative file unless black_list.include?("#{file}.rb")
@@ -19,7 +19,7 @@ class RubeeAppTest < Minitest::Test
19
19
  end
20
20
 
21
21
  def test_welcome_controller_included_auth_tokenable
22
- WelcomeController.include(AuthTokenable)
22
+ WelcomeController.include(Rubee::AuthTokenable)
23
23
  WelcomeController.auth_methods :show
24
24
 
25
25
  get '/'
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ Bundler.require(:test)
3
+
4
+ require 'minitest/autorun'
5
+ require 'rack/test'
6
+ require_relative '../../lib/rubee'
7
+
8
+ Rubee::Autoload.call
9
+ Rubee::Configuration.setup(env=:test) do |config|
10
+ config.database_url = { url: "sqlite://test.db", env: }
11
+ end
12
+ Rubee::SequelObject.reconnect!
13
+
14
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru.Bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-17 00:00:00.000000000 Z
10
+ date: 2025-03-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -39,13 +39,10 @@ extra_rdoc_files: []
39
39
  files:
40
40
  - LICENSE
41
41
  - bin/rubee
42
+ - bin/test.db
42
43
  - lib/Dockerfile
43
44
  - lib/app/controllers/welcome_controller.rb
44
45
  - lib/app/models/user.rb
45
- - lib/app/tests/auth_tokenable_test.rb
46
- - lib/app/tests/rubeeapp_test.rb
47
- - lib/app/tests/test_helper.rb
48
- - lib/app/tests/user_model_test.rb
49
46
  - lib/app/views/welcome_show.erb
50
47
  - lib/config.ru
51
48
  - lib/config/base_configuration.rb
@@ -68,11 +65,10 @@ files:
68
65
  - lib/rubee/extensions/serializable.rb
69
66
  - lib/rubee/models/database_object.rb
70
67
  - lib/rubee/models/sequel_object.rb
71
- - lib/rubee/tests/auth_tokenable_test.rb
72
- - lib/rubee/tests/rubeeapp_test.rb
73
- - lib/rubee/tests/test_helper.rb
74
- - lib/rubee/tests/user_model_test.rb
75
- - lib/version.rb
68
+ - lib/tests/auth_tokenable_test.rb
69
+ - lib/tests/rubeeapp_test.rb
70
+ - lib/tests/test_helper.rb
71
+ - lib/tests/user_model_test.rb
76
72
  - readme.md
77
73
  homepage: https://github.com/nucleom42/rubee
78
74
  licenses:
@@ -1,10 +0,0 @@
1
- require "bundler/setup"
2
- Bundler.require(:test)
3
-
4
- require 'minitest/autorun'
5
- require 'rack/test'
6
- require 'rubee'
7
-
8
- Rubee::Autoload.call
9
-
10
-
@@ -1,29 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class RubeeAppTest < Minitest::Test
4
- include Rack::Test::Methods
5
-
6
- def app
7
- Rubee::Application.instance
8
- end
9
-
10
- def setup
11
- Rubee::Autoload.call
12
- end
13
-
14
- def teardown
15
- # detach auth methods
16
- if WelcomeController.instance_variable_defined?(:@auth_methods)
17
- WelcomeController.send(:remove_instance_variable, :@auth_methods)
18
- end
19
- end
20
-
21
- def test_welcome_controller_included_auth_tokenable
22
- WelcomeController.include(AuthTokenable)
23
- WelcomeController.auth_methods :show
24
-
25
- get '/'
26
-
27
- assert_equal last_response.status, 401
28
- end
29
- end
@@ -1,24 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- class RubeeAppTest < Minitest::Test
4
- include Rack::Test::Methods
5
-
6
- def app
7
- Rubee::Application.instance
8
- end
9
-
10
-
11
- def test_welcome_route
12
- get '/'
13
-
14
- assert_equal 200, last_response.status, "Unexpected response: #{last_response.body}"
15
- assert_includes last_response.body, 'All set up and running!'
16
- end
17
-
18
-
19
- def test_not_found_route
20
- get '/random'
21
-
22
- assert_equal 404, last_response.status
23
- end
24
- end
@@ -1,10 +0,0 @@
1
- require "bundler/setup"
2
- Bundler.require(:test)
3
-
4
- require 'minitest/autorun'
5
- require 'rack/test'
6
- require 'rubee'
7
-
8
- Rubee::Autoload.call
9
-
10
-
@@ -1,60 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- describe 'User model' do
4
- describe ".create" do
5
- after do
6
- User.destroy_all
7
- end
8
-
9
- describe 'when data is valid' do
10
- it 'persists to db' do
11
- user = User.create(email: "ok-test@test.com", password: "123")
12
-
13
- _(user.persisted?).must_equal true
14
- end
15
- end
16
-
17
- describe 'when data is invalid' do
18
- it 'is not changing users number' do
19
- initial_count = User.all.count
20
- User.create(wrong: "test@test") rescue nil
21
-
22
- _(User.all.count).must_equal initial_count
23
- end
24
- end
25
- end
26
-
27
- describe '.save' do
28
- after do
29
- User.destroy_all
30
- end
31
-
32
- describe 'when data is valid' do
33
- it 'persists to db' do
34
- user = User.new(email: "ok-test@test.com", password: "123")
35
- user.save
36
-
37
- _(user.persisted?).must_equal true
38
- end
39
- end
40
-
41
- describe 'when save existing user' do
42
- it 'persists to db' do
43
- user = User.new(email: "ok-test@test.com", password: "123")
44
- user.save
45
-
46
- _(user.reload.password).must_equal "123"
47
- end
48
- end
49
-
50
- describe 'when data is invalid' do
51
- it 'is not changing users number' do
52
- initial_count = User.all.count
53
- user = User.new(wrong: "test@test") rescue nil
54
- user.save rescue nil
55
-
56
- _(User.all.count).must_equal initial_count
57
- end
58
- end
59
- end
60
- end
data/lib/version.rb DELETED
@@ -1 +0,0 @@
1
- VERSION = '1.1.1'
File without changes
File without changes