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.
- checksums.yaml +4 -4
- data/bin/rubee +6 -295
- data/lib/app/views/index.html +1 -1
- data/lib/config/base_configuration.rb +25 -7
- data/lib/db/create_addresses.rb +17 -0
- data/lib/inits/charged_hash.rb +16 -0
- data/lib/inits/charged_string.rb +12 -0
- data/lib/js/app.js +3 -3
- data/lib/package.json +1 -1
- data/lib/rubee/async/fiber_queue.rb +27 -0
- data/lib/rubee/async/thread_async.rb +1 -1
- data/lib/rubee/async/thread_pool.rb +32 -34
- data/lib/rubee/autoload.rb +86 -0
- data/lib/rubee/cli/attach.rb +124 -0
- data/lib/rubee/cli/command.rb +41 -0
- data/lib/rubee/cli/console.rb +39 -0
- data/lib/rubee/cli/db.rb +105 -0
- data/lib/rubee/cli/generate.rb +33 -0
- data/lib/rubee/cli/project.rb +124 -0
- data/lib/rubee/cli/react.rb +28 -0
- data/lib/rubee/cli/routes.rb +18 -0
- data/lib/rubee/cli/server.rb +52 -0
- data/lib/rubee/cli/test.rb +24 -0
- data/lib/rubee/cli/version.rb +15 -0
- data/lib/rubee/configuration.rb +83 -0
- data/lib/rubee/controllers/base_controller.rb +12 -6
- data/lib/rubee/controllers/extensions/auth_tokenable.rb +2 -2
- data/lib/rubee/extensions/hookable.rb +9 -2
- data/lib/rubee/generator.rb +160 -0
- data/lib/rubee/logger.rb +83 -0
- data/lib/rubee/models/database_objectable.rb +1 -1
- data/lib/rubee/models/sequel_object.rb +3 -3
- data/lib/rubee/router.rb +40 -0
- data/lib/rubee.rb +13 -317
- data/lib/tests/async/thread_async_test.rb +9 -5
- data/lib/tests/cli/attach_test.rb +36 -0
- data/lib/tests/{auth_tokenable_test.rb → controllers/auth_tokenable_test.rb} +2 -2
- data/lib/tests/controllers/base_controller_test.rb +23 -0
- data/lib/tests/controllers/hookable_test.rb +220 -0
- data/lib/tests/{rubeeapp_test.rb → controllers/rubeeapp_test.rb} +3 -2
- data/lib/tests/example_models/address.rb +5 -0
- data/lib/tests/example_models/user.rb +1 -0
- data/lib/tests/logger_test.rb +76 -0
- data/lib/tests/{account_model_test.rb → models/account_model_test.rb} +1 -1
- data/lib/tests/{comment_model_test.rb → models/comment_model_test.rb} +13 -1
- data/lib/tests/models/db_objectable_test.rb +21 -0
- data/lib/tests/models/seralizable_test.rb +36 -0
- data/lib/tests/{user_model_test.rb → models/user_model_test.rb} +32 -1
- data/lib/tests/rubee_attach_test.rb +0 -0
- data/lib/tests/test.db +0 -0
- data/lib/tests/test_helper.rb +20 -2
- data/readme.md +174 -15
- metadata +34 -9
- data/lib/app/views/apples_.erb +0 -1
- data/lib/app/views/s_.erb +0 -1
- /data/lib/app/views/{app.tsx → App.tsx} +0 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class CustomLogger
|
4
|
+
class << self
|
5
|
+
def warn(message:, **options, &block); end
|
6
|
+
|
7
|
+
def info(message:, **options, &block)
|
8
|
+
puts "CUSTOM INFO #{message}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def error(message:, **options, &block); end
|
12
|
+
|
13
|
+
def critical(message:, **options, &block); end
|
14
|
+
|
15
|
+
def debug(object:, **options, &block); end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Rubee::Logger' do
|
20
|
+
describe 'logger' do
|
21
|
+
it 'exists' do
|
22
|
+
_(Rubee::Logger).wont_be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.warn' do
|
27
|
+
it 'output message' do
|
28
|
+
output = capture_stdout { Rubee::Logger.warn(message: 'test') }
|
29
|
+
|
30
|
+
assert_includes(output, "WARN test")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.info' do
|
35
|
+
it 'output message' do
|
36
|
+
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
37
|
+
|
38
|
+
assert_includes(output, "INFO test")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.error' do
|
43
|
+
it 'output message' do
|
44
|
+
output = capture_stdout { Rubee::Logger.error(message: 'test') }
|
45
|
+
|
46
|
+
assert_includes(output, "ERROR test")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.critical' do
|
51
|
+
it 'output message' do
|
52
|
+
output = capture_stdout { Rubee::Logger.critical(message: 'test') }
|
53
|
+
|
54
|
+
assert_includes(output, "CRITICAL test")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.debug' do
|
59
|
+
it 'output message' do
|
60
|
+
output = capture_stdout { Rubee::Logger.debug(object: User.new(email: 'ok@ok.com', password: 123)) }
|
61
|
+
|
62
|
+
assert_includes(output, "DEBUG #<User:")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'when custom logger defined in the configuration' do
|
67
|
+
it 'uses custom logger' do
|
68
|
+
Rubee::Configuration.setup(env = :test) { _1.logger = { logger: CustomLogger, env: } }
|
69
|
+
|
70
|
+
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
71
|
+
assert_includes(output, "CUSTOM INFO test")
|
72
|
+
|
73
|
+
Rubee::Configuration.setup(env = :test) { _1.logger = { env: } }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative 'test_helper'
|
1
|
+
require_relative '../test_helper'
|
2
2
|
|
3
3
|
describe 'Comment model' do
|
4
4
|
describe 'owns_many :users, over: :posts' do
|
@@ -32,4 +32,16 @@ describe 'Comment model' do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
describe 'method' do
|
37
|
+
it 'updates existing model' do
|
38
|
+
comment = Comment.new(text: 'test 1')
|
39
|
+
comment.save
|
40
|
+
|
41
|
+
comment.text = 'test 2'
|
42
|
+
comment.save
|
43
|
+
|
44
|
+
_(Comment.find(comment.id).text).must_equal('test 2')
|
45
|
+
end
|
46
|
+
end
|
35
47
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class MergBerg
|
4
|
+
include Rubee::DatabaseObjectable
|
5
|
+
attr_accessor :id, :foo, :bar
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'Database Objectable' do
|
9
|
+
describe 'class methods' do
|
10
|
+
it 'pluralizes class names' do
|
11
|
+
_(MergBerg.pluralize_class_name).must_equal('mergbergs')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'retrieves accessor names' do
|
15
|
+
accessors = MergBerg.accessor_names
|
16
|
+
_(accessors).must_include(:id)
|
17
|
+
_(accessors).must_include(:foo)
|
18
|
+
_(accessors).must_include(:bar)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class TestSerialized
|
4
|
+
include Rubee::Serializable
|
5
|
+
|
6
|
+
attr_accessor :id, :towel_color, :name
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Serializable Model' do
|
10
|
+
describe 'attributes' do
|
11
|
+
it 'exists and settable' do
|
12
|
+
cerealed = TestSerialized.new(id: 10, towel_color: 'blue', name: 'Ford Prefect')
|
13
|
+
|
14
|
+
_(cerealed.id).must_equal(10)
|
15
|
+
_(cerealed.towel_color).must_equal('blue')
|
16
|
+
_(cerealed.name).must_equal('Ford Prefect')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not exist not settable' do
|
20
|
+
_ { TestSerialized.new(blue: 'hello') }.must_raise(NoMethodError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'coverts to' do
|
25
|
+
before do
|
26
|
+
@cerealed = TestSerialized.new(id: 10, towel_color: 'blue', name: 'Ford Prefect')
|
27
|
+
end
|
28
|
+
it 'hash' do
|
29
|
+
_(@cerealed.to_h).must_be_instance_of(Hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'json' do
|
33
|
+
_(@cerealed.to_json).must_be_instance_of(String)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative 'test_helper'
|
1
|
+
require_relative '../test_helper'
|
2
2
|
|
3
3
|
describe 'User model' do
|
4
4
|
describe '.create' do
|
@@ -248,4 +248,35 @@ describe 'User model' do
|
|
248
248
|
end
|
249
249
|
end
|
250
250
|
end
|
251
|
+
|
252
|
+
describe 'owns_one' do
|
253
|
+
after do
|
254
|
+
User.destroy_all(cascade: true)
|
255
|
+
end
|
256
|
+
describe 'when there is one associated account' do
|
257
|
+
it 'cannot add more than one address' do
|
258
|
+
skip "This is an idea that can be implemented later"
|
259
|
+
user = User.new(email: 'bleh@example.com', password: '123')
|
260
|
+
user.save
|
261
|
+
|
262
|
+
address = Address.new(user_id: user.id, street: '1234 ble ave', apt: '', city: 'NY', state: 'NY', zip: '555555')
|
263
|
+
address.save
|
264
|
+
|
265
|
+
address_two = Address.new(user_id: user.id, street: '1234 ble ave', apt: '', city: 'NY', state: 'NY',
|
266
|
+
zip: '555555')
|
267
|
+
|
268
|
+
_ { address_two.save }.must_raise(Rubee::OwnsOneError)
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'returns the single address' do
|
272
|
+
user = User.new(email: 'bleh@example.com', password: '123')
|
273
|
+
user.save
|
274
|
+
|
275
|
+
address = Address.new(user_id: user.id, street: '1234 ble ave', apt: '', city: 'NY', state: 'NY', zip: '555555')
|
276
|
+
address.save
|
277
|
+
|
278
|
+
_(user.address.id).must_equal(address.id)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
251
282
|
end
|
File without changes
|
data/lib/tests/test.db
CHANGED
Binary file
|
data/lib/tests/test_helper.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
Bundler.require(:test)
|
3
3
|
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter %r{^/lib/db/}
|
7
|
+
add_filter %r{^/lib/inits/}
|
8
|
+
add_filter %r{^/lib/tests/}
|
9
|
+
end
|
10
|
+
|
4
11
|
require 'minitest/autorun'
|
5
12
|
require 'rack/test'
|
13
|
+
require 'stringio'
|
14
|
+
|
6
15
|
require_relative '../../lib/rubee'
|
7
16
|
|
8
17
|
Rubee::Autoload.call
|
@@ -17,7 +26,16 @@ def assert_difference(expression, difference = 1)
|
|
17
26
|
after = expression.call
|
18
27
|
actual_diff = after - before
|
19
28
|
|
20
|
-
assert_equal
|
21
|
-
"Expected change of #{difference}, but got #{actual_diff}"
|
29
|
+
assert_equal(difference, actual_diff,
|
30
|
+
"Expected change of #{difference}, but got #{actual_diff}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def capture_stdout
|
34
|
+
old_stdout = $stdout
|
35
|
+
$stdout = StringIO.new
|
36
|
+
yield
|
37
|
+
$stdout.string
|
38
|
+
ensure
|
39
|
+
$stdout = old_stdout
|
22
40
|
end
|
23
41
|
|
data/readme.md
CHANGED
@@ -16,12 +16,35 @@ Want to get a quick API server up and runing? You can do it for real quick!
|
|
16
16
|
<br />
|
17
17
|
[](https://www.youtube.com/watch?v=ko7H70s7qq0)
|
18
18
|
|
19
|
-
All
|
19
|
+
All great features are yet to come!
|
20
|
+
|
21
|
+
## Content:
|
22
|
+
|
23
|
+
- [Installation](#Installation)
|
24
|
+
- [Run tests](#run-tests)
|
25
|
+
- [Draw contract](#draw-contract)
|
26
|
+
- [Model](#Model)
|
27
|
+
- [Routing](#Routing)
|
28
|
+
- [Database](#Database)
|
29
|
+
- [Views](#Views)
|
30
|
+
- [Hooks](#Hooks)
|
31
|
+
- [JWT based authentification](#JWT-based-authentification)
|
32
|
+
- [Rubee commands](#Rubee-commands)
|
33
|
+
- [Generate commands](#Generate-commands)
|
34
|
+
- [Migration commands](#Migration-commands)
|
35
|
+
- [Rubee console](#Rubee-console)
|
36
|
+
- [Testing](#Testing)
|
37
|
+
- [Background jobs](#Background-jobs)
|
38
|
+
- [Modular](#Modular application)
|
39
|
+
- [Logger](#Logger)
|
20
40
|
|
21
41
|
## Features
|
22
42
|
|
23
43
|
- **Lightweight**: A minimal footprint that focuses on serving Ruby applications efficiently.
|
24
|
-
- **
|
44
|
+
- **Moduled** A modular approach to application development. Build modular monolith applications with ease by \
|
45
|
+
attaching as many subprojects you need.
|
46
|
+
- **Contract driven**: Define your API contracts in a simple, declarative manner.\
|
47
|
+
Then generate the biolerplate files you need.
|
25
48
|
- **Fast**: Optimized for speed, providing a quick response to requests. Everything is relative, I know!
|
26
49
|
- **Rack**: Rack backed. All Rack api is available for integration.
|
27
50
|
- **Databases**: Sqlite3, Postgres, Mysql and many more supported by sequel gem.
|
@@ -30,9 +53,11 @@ All greaet features are yet to come!
|
|
30
53
|
- **Bundlable** Charge your ruBee with any gem you need and update your project with bundle.
|
31
54
|
- **ORM** All models are natively ORM objects, however you can use it as a blueurpint for any datasources.
|
32
55
|
- **Authentificatable** Add JWT authentification easily to any controller action.
|
33
|
-
- **Hooks**
|
34
|
-
- **Test** Run all or selected tests witin minitest.
|
56
|
+
- **Hooks** Add logic before, after and around any action.
|
57
|
+
- **Test** Run all or selected tests witin fast and beloved minitest.
|
35
58
|
- **Asyncable** Add async adapter and pick any popular background job queue enginee
|
59
|
+
- **Console** Start the interactive console and reload it on the fly
|
60
|
+
- **Background jobs** Add async adapter and pick any popular background job queue engine
|
36
61
|
|
37
62
|
## Installation
|
38
63
|
|
@@ -46,6 +71,8 @@ gem install ru.Bee
|
|
46
71
|
rubee project my_project
|
47
72
|
cd my_project
|
48
73
|
```
|
74
|
+
- [Back to content](#Content)
|
75
|
+
|
49
76
|
|
50
77
|
3. Install dependencies
|
51
78
|
|
@@ -65,12 +92,13 @@ rubee start
|
|
65
92
|
|
66
93
|
5. Open your browser and go to http://localhost:7000
|
67
94
|
|
68
|
-
## Run
|
95
|
+
## Run tests
|
69
96
|
```bash
|
70
97
|
rubee test
|
71
98
|
```
|
99
|
+
- [Back to content](#Content)
|
72
100
|
|
73
|
-
##
|
101
|
+
## Draw contract
|
74
102
|
1. Add the routes to the routes.rb
|
75
103
|
```ruby
|
76
104
|
Rubee::Router.draw do |router|
|
@@ -88,23 +116,24 @@ rubee test
|
|
88
116
|
end
|
89
117
|
```
|
90
118
|
2. generate the files
|
91
|
-
|
119
|
+
```bash
|
92
120
|
rubee generate get /apples
|
93
|
-
|
94
|
-
|
95
|
-
|
121
|
+
```
|
122
|
+
This will generate the following files
|
123
|
+
```bash
|
96
124
|
./app/controllers/apples_controller.rb # Controller with respective action
|
97
125
|
./app/views/apples_index.erb # ERB view that is rendered by the controller right away
|
98
126
|
./app/models/apple.rb # Model that acts as ORM
|
99
127
|
./db/create_apples.rb # Database migration file needed for creating repsective table
|
100
|
-
|
128
|
+
```
|
101
129
|
|
102
130
|
3. Run the initial db migration
|
103
131
|
```bash
|
104
132
|
rubee db run:all
|
105
|
-
```
|
133
|
+
```
|
106
134
|
|
107
135
|
5. Fill the generated files with the logic you need and run the server again!
|
136
|
+
- [Back to content](#Content)
|
108
137
|
|
109
138
|
## Model
|
110
139
|
Model in ruBee is just simple ruby object that can be serilalized in the view
|
@@ -153,6 +182,7 @@ So in the controller you would need to query your target object now.
|
|
153
182
|
end
|
154
183
|
end
|
155
184
|
```
|
185
|
+
- [Back to content](#Content)
|
156
186
|
|
157
187
|
#### Rubee::SequelObject base methods:
|
158
188
|
|
@@ -283,6 +313,7 @@ irb(main):010> .then { |dataset| Comment.serialize(dataset) }
|
|
283
313
|
```
|
284
314
|
This is recommended when you want to run one query and serialize it back to Rubee object only once.
|
285
315
|
So it may safe some resources.
|
316
|
+
- [Back to content](#Content)
|
286
317
|
|
287
318
|
## Routing
|
288
319
|
Rubee uses explicit routes. In the routes.rb yout can define routes for any of the main HTTP methods. You can also add any matched parameter denoted by a pair of `{ }` in the path of the route. Eg. `/path/to/{a_key}/somewhere`
|
@@ -395,9 +426,9 @@ Example 3:
|
|
395
426
|
Rubee::Router.draw do |router|
|
396
427
|
...
|
397
428
|
# draw the contract
|
398
|
-
router.get "/apples", to: "apples#index",
|
399
|
-
model: {
|
400
|
-
name: 'apple',
|
429
|
+
router.get "/apples", to: "apples#index",
|
430
|
+
model: {
|
431
|
+
name: 'apple',
|
401
432
|
attributes: [
|
402
433
|
{ name: 'id', type: :primary },
|
403
434
|
{ name: 'colour', type: :string },
|
@@ -415,6 +446,80 @@ Will generate:
|
|
415
446
|
./db/create_apples.rb # Database migration file needed for creating repsective table
|
416
447
|
```
|
417
448
|
|
449
|
+
### Modualar application
|
450
|
+
|
451
|
+
You can also use ruBee to create modular applications.\
|
452
|
+
And attach as many subprojects you need.
|
453
|
+
Main philosophy of attach functinality is to keep the main project clean and easy to maintain. It will still\
|
454
|
+
share data with the main app. So where to define a border between main app and subprojects is up to developer.
|
455
|
+
Howerver by attching new subproject you will get a new folder and files configured and namespaced respectively.
|
456
|
+
|
457
|
+
So if you need to extend your main app with a separate project you can do it easily in ruBee.
|
458
|
+
1. Attach new subrpoject
|
459
|
+
|
460
|
+
```bash
|
461
|
+
rubee attach admin
|
462
|
+
```
|
463
|
+
This will create a dedicated folder in the project root called admin and all the MVC setup, route and configuraion \
|
464
|
+
files will be created there.
|
465
|
+
|
466
|
+
2. Add routes
|
467
|
+
|
468
|
+
```ruby
|
469
|
+
# admin_routes.rb
|
470
|
+
Rubee::Router.draw do |router|
|
471
|
+
...
|
472
|
+
# draw the contract
|
473
|
+
router.get '/admin/cabages', to: 'cabages#index',
|
474
|
+
model: {
|
475
|
+
name: 'cabage',
|
476
|
+
attributes: [
|
477
|
+
{ name: 'id', type: :primary },
|
478
|
+
{ name: 'name', type: :string }
|
479
|
+
]
|
480
|
+
},
|
481
|
+
namespace: :admin # mandatory option for supporting namespacing
|
482
|
+
end
|
483
|
+
```
|
484
|
+
3. Run gen command
|
485
|
+
|
486
|
+
```bash
|
487
|
+
rubee gen get /admin/cabages app:admin
|
488
|
+
```
|
489
|
+
|
490
|
+
This will generate the bolierplate files:
|
491
|
+
|
492
|
+
```bash
|
493
|
+
./admin/controllers/cabages_controller.rb
|
494
|
+
./admin/views/cabages_index.erb
|
495
|
+
./admin/models/cabage.rb
|
496
|
+
./db/create_cabages.rb
|
497
|
+
```
|
498
|
+
|
499
|
+
4. Perform migrations
|
500
|
+
|
501
|
+
```bash
|
502
|
+
rubee db run:create_cabages
|
503
|
+
```
|
504
|
+
5. Fill the views and controller with the content
|
505
|
+
|
506
|
+
```ruby
|
507
|
+
# ./admin/controllers/cabages_controller.rb
|
508
|
+
class Admin::CabagesController < Rubee::BaseController
|
509
|
+
def index
|
510
|
+
response_with object: Cabage.all, type: :json
|
511
|
+
end
|
512
|
+
end
|
513
|
+
```
|
514
|
+
|
515
|
+
6. Run the rubee server
|
516
|
+
|
517
|
+
```bash
|
518
|
+
rubee start # or rubee start_dev for development
|
519
|
+
```
|
520
|
+
|
521
|
+
- [Back to content](#Content)
|
522
|
+
|
418
523
|
## Views
|
419
524
|
View in ruBee is just a plain html/erb/react file that can be rendered from the controller.
|
420
525
|
|
@@ -549,6 +654,7 @@ function Users() {
|
|
549
654
|
}
|
550
655
|
|
551
656
|
```
|
657
|
+
- [Back to content](#Content)
|
552
658
|
|
553
659
|
## Object hooks
|
554
660
|
|
@@ -591,6 +697,8 @@ after index2
|
|
591
697
|
after log around
|
592
698
|
127.0.0.1 - - [17/Feb/2025:11:42:14 -0500] "GET /apples HTTP/1.1" 401 - 0.0359
|
593
699
|
```
|
700
|
+
- [Back to content](#Content)
|
701
|
+
|
594
702
|
|
595
703
|
## JWT based authentification
|
596
704
|
Charge you rpoject with token based authentification system and customize it for your needs.
|
@@ -640,6 +748,7 @@ class UsersController < Rubee::BaseController
|
|
640
748
|
end
|
641
749
|
end
|
642
750
|
```
|
751
|
+
- [Back to content](#Content)
|
643
752
|
|
644
753
|
## Rubee commands
|
645
754
|
```bash
|
@@ -674,6 +783,8 @@ rubee console # start the console
|
|
674
783
|
rubee test # run all tests
|
675
784
|
rubee test auth_tokenable_test.rb # run specific tests
|
676
785
|
```
|
786
|
+
- [Back to content](#Content)
|
787
|
+
|
677
788
|
|
678
789
|
If you want to run any ruBee command within a specific ENV make sure you added it before a command.
|
679
790
|
For instance if you want to run console in test environment you need to run the following command
|
@@ -755,6 +866,54 @@ end
|
|
755
866
|
|
756
867
|
TestAsyncRunnner.new.perform_async(options: {"email"=> "new@new.com", "password"=> "123"})
|
757
868
|
```
|
869
|
+
- [Back to content](#Content)
|
870
|
+
|
871
|
+
### Logger
|
872
|
+
|
873
|
+
You can use your own logger by setting it in the /config/base_configuration.rb.
|
874
|
+
|
875
|
+
```ruby
|
876
|
+
# config/base_configuration.rb
|
877
|
+
Rubee::Configuration.setup(env=:development) do |config|
|
878
|
+
config.database_url = { url: "sqlite://db/development.db", env: }
|
879
|
+
config.logger = { logger: MyLogger, env: }
|
880
|
+
end
|
881
|
+
```
|
882
|
+
|
883
|
+
Or you can use the default logger.
|
884
|
+
Let's consider example with welcome controller and around hook:
|
885
|
+
```ruby
|
886
|
+
# app/controllers/welcome_controller.rb
|
887
|
+
class WelcomeController < Rubee::BaseController
|
888
|
+
around :show, ->(&target_method) do
|
889
|
+
start = Time.now
|
890
|
+
Rubee::Logger.warn(message: 'This is a warning message', method: :show, class_name: 'WelcomeController')
|
891
|
+
Rubee::Logger.error(message: 'This is a warning message', class_name: 'WelcomeController')
|
892
|
+
Rubee::Logger.critical(message: 'We are on fire!')
|
893
|
+
target_method.call
|
894
|
+
Rubee::Logger.info(
|
895
|
+
message: "Execution Time: #{Time.now - start} seconds",
|
896
|
+
method: :show,
|
897
|
+
class_name: 'WelcomeController'
|
898
|
+
)
|
899
|
+
Rubee::Logger.debug(object: User.last, method: :show, class_name: 'WelcomeController')
|
900
|
+
end
|
901
|
+
|
902
|
+
def show
|
903
|
+
response_with
|
904
|
+
end
|
905
|
+
end
|
906
|
+
```
|
907
|
+
When you trigger the controller action, the logs will look like this:
|
908
|
+
|
909
|
+
```bash
|
910
|
+
[2025-04-26 12:32:33] WARN [method: show][class_name: WelcomeController] This is a warning message
|
911
|
+
[2025-04-26 12:32:33] ERROR [class_name: WelcomeController] This is a warning message
|
912
|
+
[2025-04-26 12:32:33] CRITICAL We are on fire!
|
913
|
+
[2025-04-26 12:32:33] INFO [method: show][class_name: WelcomeController] Execution Time: 0.000655 seconds
|
914
|
+
[2025-04-26 12:32:33] DEBUG [method: show][class_name: WelcomeController] #<User:0x000000012c5c63e0 @id=4545, @email="ok@op.com", @password="123">
|
915
|
+
```
|
916
|
+
- [Back to content](#Content)
|
758
917
|
|
759
918
|
### Contributing
|
760
919
|
|
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: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Saltykov
|
@@ -43,11 +43,9 @@ files:
|
|
43
43
|
- lib/Dockerfile
|
44
44
|
- lib/app/controllers/welcome_controller.rb
|
45
45
|
- lib/app/models/user.rb
|
46
|
-
- lib/app/views/
|
47
|
-
- lib/app/views/apples_.erb
|
46
|
+
- lib/app/views/App.tsx
|
48
47
|
- lib/app/views/index.html
|
49
48
|
- lib/app/views/layout.erb
|
50
|
-
- lib/app/views/s_.erb
|
51
49
|
- lib/app/views/utils/redirectToBackend.tsx
|
52
50
|
- lib/app/views/welcome_header.erb
|
53
51
|
- lib/app/views/welcome_show.erb
|
@@ -56,12 +54,14 @@ files:
|
|
56
54
|
- lib/config/routes.rb
|
57
55
|
- lib/css/app.css
|
58
56
|
- lib/db/create_accounts.rb
|
57
|
+
- lib/db/create_addresses.rb
|
59
58
|
- lib/db/create_comments.rb
|
60
59
|
- lib/db/create_posts.rb
|
61
60
|
- lib/db/create_users.rb
|
62
61
|
- lib/db/structure.rb
|
63
62
|
- lib/esbuild.config.js
|
64
63
|
- lib/images/rubee.svg
|
64
|
+
- lib/inits/charged_hash.rb
|
65
65
|
- lib/inits/charged_string.rb
|
66
66
|
- lib/inits/print_colors.rb
|
67
67
|
- lib/js/app.js
|
@@ -229,30 +229,55 @@ files:
|
|
229
229
|
- lib/package.json
|
230
230
|
- lib/rubee.rb
|
231
231
|
- lib/rubee/async/asyncable.rb
|
232
|
+
- lib/rubee/async/fiber_queue.rb
|
232
233
|
- lib/rubee/async/sidekiq_async.rb
|
233
234
|
- lib/rubee/async/thread_async.rb
|
234
235
|
- lib/rubee/async/thread_pool.rb
|
236
|
+
- lib/rubee/autoload.rb
|
237
|
+
- lib/rubee/cli/attach.rb
|
238
|
+
- lib/rubee/cli/command.rb
|
239
|
+
- lib/rubee/cli/console.rb
|
240
|
+
- lib/rubee/cli/db.rb
|
241
|
+
- lib/rubee/cli/generate.rb
|
242
|
+
- lib/rubee/cli/project.rb
|
243
|
+
- lib/rubee/cli/react.rb
|
244
|
+
- lib/rubee/cli/routes.rb
|
245
|
+
- lib/rubee/cli/server.rb
|
246
|
+
- lib/rubee/cli/test.rb
|
247
|
+
- lib/rubee/cli/version.rb
|
248
|
+
- lib/rubee/configuration.rb
|
235
249
|
- lib/rubee/controllers/base_controller.rb
|
236
250
|
- lib/rubee/controllers/extensions/auth_tokenable.rb
|
237
251
|
- lib/rubee/controllers/extensions/middlewarable.rb
|
238
252
|
- lib/rubee/controllers/middlewares/auth_token_middleware.rb
|
239
253
|
- lib/rubee/extensions/hookable.rb
|
240
254
|
- lib/rubee/extensions/serializable.rb
|
255
|
+
- lib/rubee/generator.rb
|
256
|
+
- lib/rubee/logger.rb
|
241
257
|
- lib/rubee/models/database_objectable.rb
|
242
258
|
- lib/rubee/models/sequel_object.rb
|
243
|
-
- lib/
|
259
|
+
- lib/rubee/router.rb
|
244
260
|
- lib/tests/async/thread_async_test.rb
|
245
|
-
- lib/tests/
|
246
|
-
- lib/tests/
|
261
|
+
- lib/tests/cli/attach_test.rb
|
262
|
+
- lib/tests/controllers/auth_tokenable_test.rb
|
263
|
+
- lib/tests/controllers/base_controller_test.rb
|
264
|
+
- lib/tests/controllers/hookable_test.rb
|
265
|
+
- lib/tests/controllers/rubeeapp_test.rb
|
247
266
|
- lib/tests/example_models/account.rb
|
267
|
+
- lib/tests/example_models/address.rb
|
248
268
|
- lib/tests/example_models/comment.rb
|
249
269
|
- lib/tests/example_models/post.rb
|
250
270
|
- lib/tests/example_models/user.rb
|
271
|
+
- lib/tests/logger_test.rb
|
272
|
+
- lib/tests/models/account_model_test.rb
|
273
|
+
- lib/tests/models/comment_model_test.rb
|
274
|
+
- lib/tests/models/db_objectable_test.rb
|
275
|
+
- lib/tests/models/seralizable_test.rb
|
276
|
+
- lib/tests/models/user_model_test.rb
|
277
|
+
- lib/tests/rubee_attach_test.rb
|
251
278
|
- lib/tests/rubee_generator_test.rb
|
252
|
-
- lib/tests/rubeeapp_test.rb
|
253
279
|
- lib/tests/test.db
|
254
280
|
- lib/tests/test_helper.rb
|
255
|
-
- lib/tests/user_model_test.rb
|
256
281
|
- readme.md
|
257
282
|
homepage: https://github.com/nucleom42/rubee
|
258
283
|
licenses:
|
data/lib/app/views/apples_.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<h1>apples_ View</h1>
|
data/lib/app/views/s_.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<h1>s_ View</h1>
|
File without changes
|