ru.Bee 2.3.0 → 2.3.2

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: e4265fe78eeb8daacd156944598c50939c7a2f98aeee6b8b7cf5752f853f7a75
4
- data.tar.gz: 0f5b0f9e44474beed31ecd28f9d42950131db539dd467d68436c21ae4e8772b3
3
+ metadata.gz: 3098241bea70d0e5fadfb944de3d50f411d7799142a84858ed848082ea97b5b4
4
+ data.tar.gz: 24c80462cc23bc334324bbee12192dab6efb6517460ddb2b427b28cc5ed69df4
5
5
  SHA512:
6
- metadata.gz: 7f929f4a7bd876f0c6a0250b298dc9e546e22944602262b89abe6cd73f9981fa3888f9bde95226861346abf01ead84e3f77b442164c037fcaca33704eedcda84
7
- data.tar.gz: b2de33afa3602ef196972f06f36c5d6a3426ec2edf7b2c9f218ed537bebf6e6a46c232ffceb146927f40945d9b02ed8fd4f19b5d211f418779d511d9424afb31
6
+ metadata.gz: 3dfab254bc794bdd28ee8c4d36ddfcb8b10e5e0efd050e89fca05cda000d0861a5381aa6730767e0fbcc5f35ff6a64bf5d86f8c502a2de27ce670d98152fa5fd
7
+ data.tar.gz: 35d0922f40a339fd3ca2733d0682d60cea9b9b62b17ab080a0eb768e085217eeba3694a5a68a309974a45c4ed86b404cea9d468253c4bc7fc7f5949c1e12216a
@@ -12,6 +12,7 @@ class CreateComments
12
12
 
13
13
  end
14
14
 
15
- User.create(email: 'ok@ok.com', password: 'password')
15
+ user = User.create(email: 'ok@ok.com', password: 'password')
16
+ Comment.create(text: 'hello', user_id: user.id)
16
17
  end
17
18
  end
@@ -0,0 +1,13 @@
1
+ class CreateDummies
2
+ def call
3
+ return if Rubee::SequelObject::DB.tables.include?(:dummies)
4
+
5
+ Rubee::SequelObject::DB.create_table(:dummies) do
6
+ primary_key(:id)
7
+ String(:color, null: false)
8
+ # timestamps
9
+ datetime(:created)
10
+ datetime(:updated)
11
+ end
12
+ end
13
+ end
File without changes
data/lib/db/test.db ADDED
Binary file
@@ -7,9 +7,9 @@ module Rubee
7
7
  # autoload all rbs
8
8
  root_directory = File.join(Rubee::ROOT_PATH, '/lib')
9
9
  priority_order_require(root_directory, black_list)
10
+ load_inits(root_directory, black_list)
10
11
  # ensure sequel object is connected
11
12
  Rubee::SequelObject.reconnect!
12
-
13
13
  Dir.glob(File.join(Rubee::APP_ROOT, '**', '*.rb')).sort.each do |file|
14
14
  base_name = File.basename(file)
15
15
 
@@ -27,7 +27,7 @@ module Rubee
27
27
  end
28
28
  end
29
29
 
30
- def priority_order_require(root_directory, black_list)
30
+ def load_inits(root_directory, black_list)
31
31
  # rubee inits
32
32
  Dir[File.join(root_directory, 'inits/**', '*.rb')].each do |file|
33
33
  require_relative file unless black_list.include?("#{file}.rb")
@@ -36,6 +36,9 @@ module Rubee
36
36
  Dir[File.join(Rubee::APP_ROOT, 'inits/**', '*.rb')].each do |file|
37
37
  require_relative file unless black_list.include?("#{file}.rb")
38
38
  end
39
+ end
40
+
41
+ def priority_order_require(root_directory, black_list)
39
42
  # rubee pub sub
40
43
  Dir[File.join(root_directory, 'rubee/pubsub/**', '*.rb')].each do |file|
41
44
  require_relative file unless black_list.include?("#{file}.rb")
@@ -53,13 +56,6 @@ module Rubee
53
56
  require_relative File.join(Rubee::APP_ROOT, Rubee::LIB,
54
57
  'config/base_configuration')
55
58
  end
56
- # This is necessary prerequisitedb init step
57
- if Rubee::PROJECT_NAME == 'rubee'
58
- Rubee::Configuration.setup(env = :test) do |config|
59
- config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
60
- end
61
- end
62
-
63
59
  require_relative File.join(Rubee::APP_ROOT, Rubee::LIB, 'config/routes') unless black_list.include?('routes.rb')
64
60
  # rubee extensions
65
61
  Dir[File.join(root_directory, 'rubee/extensions/**', '*.rb')].each do |file|
@@ -10,12 +10,6 @@ module Rubee
10
10
  argv.clear
11
11
  ENV['RACK_ENV'] ||= 'development'
12
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
- end
18
-
19
13
  begin
20
14
  # Start IRB
21
15
  IRB.start
data/lib/rubee/cli/db.rb CHANGED
@@ -5,13 +5,6 @@ module Rubee
5
5
  def call(command, argv)
6
6
  command = argv[1].split(':').first
7
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
8
  send(command, argv)
16
9
  end
17
10
 
@@ -25,12 +18,9 @@ module Rubee
25
18
  else
26
19
  [file_name]
27
20
  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
21
+ file_names.each do |file|
22
+ color_puts("Run #{file} file for #{ENV['RACK_ENV']} env", color: :cyan)
23
+ Object.const_get(file.split('_').map(&:capitalize).join).new.call
34
24
  end
35
25
  color_puts("Migration for #{file_name} completed", color: :green)
36
26
  unless Rubee::PROJECT_NAME == 'rubee'
@@ -81,6 +71,7 @@ module Rubee
81
71
  if File.exist?(db_path = db_url.sub(%r{^sqlite://}, ''))
82
72
  color_puts("Database #{ENV['RACK_ENV']} exists", color: :cyan)
83
73
  else
74
+ db_path = "#{Rubee::LIB}/#{db_path}" if Rubee::PROJECT_NAME == 'rubee'
84
75
  Sequel.sqlite(db_path)
85
76
  color_puts("Database #{ENV['RACK_ENV']} created", color: :green)
86
77
  end
@@ -34,7 +34,7 @@ module Rubee
34
34
 
35
35
  def database_url=(args)
36
36
  args[:app] ||= :app
37
- @configuraiton[args[:app].to_sym][args[:env].to_sym][:database_url] = args[:url]
37
+ @configuraiton[args[:app].to_sym][args[:env].to_sym][:database_url] = args[:url].gsub("//", "//#{Rubee::LIB}")
38
38
  end
39
39
 
40
40
  def redis_url=(args)
@@ -160,13 +160,19 @@ module Rubee
160
160
  end
161
161
 
162
162
  def reconnect!
163
- return if defined?(DB) && !DB.nil?
163
+ return if db_set?
164
164
 
165
165
  const_set(:DB, Sequel.connect(Rubee::Configuration.get_database_url))
166
166
 
167
167
  Rubee::DBTools.set_prerequisites!
168
168
 
169
169
  true
170
+ rescue Exception => e
171
+ false
172
+ end
173
+
174
+ def db_set?
175
+ defined?(DB) && !DB.nil?
170
176
  end
171
177
 
172
178
  def dataset
data/lib/rubee.rb CHANGED
@@ -17,7 +17,7 @@ module Rubee
17
17
  CSS_DIR = File.join(APP_ROOT, LIB, 'css') unless defined?(CSS_DIR)
18
18
  ROOT_PATH = File.expand_path(File.join(__dir__, '..')) unless defined?(ROOT_PATH)
19
19
 
20
- VERSION = '2.3.0'
20
+ VERSION = '2.3.2'
21
21
 
22
22
  require_relative 'rubee/router'
23
23
  require_relative 'rubee/logger'
@@ -0,0 +1,29 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe 'Rubee::CLI::Db' do
4
+ describe 'when run db run:all with no ENV set' do
5
+ it 'goes with no errors' do
6
+ out = capture_stdout do
7
+ Rubee::CLI::Command.new(['db', 'run:create_dummies']).call
8
+ end
9
+
10
+ _(out).must_equal(
11
+ "\e[0;36mRun create_dummies file for test env\e[0m
12
+ \e[0;32mMigration for create_dummies completed\e[0m
13
+ "
14
+ )
15
+
16
+ Rubee::SequelObject::DB.drop_table(:dummies)
17
+ end
18
+
19
+ it 'cretes dummies table' do
20
+ Rubee::SequelObject::DB.drop_table(:dummies) if Rubee::SequelObject::DB.tables.include?(:dummies)
21
+
22
+ _(Rubee::SequelObject::DB.tables.include?(:dummies)).must_equal false
23
+ Rubee::CLI::Command.new(['db', 'run:create_dummies']).call
24
+ _(Rubee::SequelObject::DB.tables.include?(:dummies)).must_equal true
25
+
26
+ Rubee::SequelObject::DB.drop_table(:dummies)
27
+ end
28
+ end
29
+ end
@@ -15,10 +15,6 @@ require 'stringio'
15
15
  require_relative '../../lib/rubee'
16
16
 
17
17
  Rubee::Autoload.call
18
- Rubee::Configuration.setup(env = :test) do |config|
19
- config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
20
- end
21
- Rubee::SequelObject.reconnect!
22
18
 
23
19
  def assert_difference(expression, difference = 1)
24
20
  before = expression.call
data/readme.md CHANGED
@@ -978,8 +978,9 @@ irb(main):047> foo.errors
978
978
  Model example
979
979
  ```ruby
980
980
  class User < Rubee::SequelObject
981
- attr_accessor :id, :email, :password, :created, :updated
982
-
981
+ attr_accessor :id, :email, :password, :created
982
+
983
+ validate_after_setters # This will run validation after each setter.
983
984
  validate_before_persist! # This will validate and raise error in case invalid before saving to DB
984
985
  validate do
985
986
  attribute(:email).required
@@ -1016,6 +1017,15 @@ irb(main):081> user
1016
1017
  @password=123,
1017
1018
  @updated=2025-11-30 17:18:52.254206 -0500>
1018
1019
  ```
1020
+ If you want to apply validation_before_persist! and validation_after_setters globally,
1021
+ add init/sequle_object_preloader.rb(you can chose any name)
1022
+ file withing set up those methods
1023
+ for Rubee::SequelObject parent class by adding:
1024
+ ```
1025
+ Rubee::SequelObject.validate_befor_persist!
1026
+ Rubee::SequelObject.validate_after_setters
1027
+ ```
1028
+ So you shouldn't add it to each model again and again.
1019
1029
  [Back to content](#content)
1020
1030
 
1021
1031
  ## JWT based authentification
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru.Bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
@@ -39,7 +39,6 @@ extra_rdoc_files: []
39
39
  files:
40
40
  - LICENSE
41
41
  - bin/rubee
42
- - bin/test.db
43
42
  - lib/Dockerfile
44
43
  - lib/app/controllers/users_controller.rb
45
44
  - lib/app/controllers/welcome_controller.rb
@@ -61,9 +60,12 @@ files:
61
60
  - lib/db/create_carrots.rb
62
61
  - lib/db/create_clients.rb
63
62
  - lib/db/create_comments.rb
63
+ - lib/db/create_dummies.rb
64
64
  - lib/db/create_posts.rb
65
65
  - lib/db/create_users.rb
66
+ - lib/db/development.db
66
67
  - lib/db/structure.rb
68
+ - lib/db/test.db
67
69
  - lib/esbuild.config.js
68
70
  - lib/images/rubee.svg
69
71
  - lib/inits/charged_hash.rb
@@ -275,6 +277,7 @@ files:
275
277
  - lib/rubee/websocket/websocket_connections.rb
276
278
  - lib/tests/async/thread_async_test.rb
277
279
  - lib/tests/cli/attach_test.rb
280
+ - lib/tests/cli/db_test.rb
278
281
  - lib/tests/controllers/auth_tokenable_test.rb
279
282
  - lib/tests/controllers/base_controller_test.rb
280
283
  - lib/tests/controllers/hookable_test.rb
@@ -296,7 +299,6 @@ files:
296
299
  - lib/tests/models/user_model_test.rb
297
300
  - lib/tests/rubee_attach_test.rb
298
301
  - lib/tests/rubee_generator_test.rb
299
- - lib/tests/test.db
300
302
  - lib/tests/test_helper.rb
301
303
  - readme.md
302
304
  homepage: https://github.com/nucleom42/rubee
data/bin/test.db DELETED
Binary file
data/lib/tests/test.db DELETED
Binary file