ru.Bee 1.6.0 → 1.8.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.
data/readme.md CHANGED
@@ -8,52 +8,67 @@
8
8
 
9
9
  # <img src="lib/images/rubee.svg" alt="ruBee" height="40"> ... ruBee
10
10
 
11
- ruBee is a fast and lightweight Ruby application server designed for minimalism and flexibility .
12
-
13
- The main philosophy of ruBee is to focus on Ruby language explicit implementation of the MVC web application.
11
+ Rubee is a Ruby-based framework designed to streamline the development of modular monolith applications. \
12
+ It offers a structured approach to building scalable, maintainable, and React-ready projects, \
13
+ making it an ideal choice for developers seeking a balance between monolithic simplicity and modular flexibility.
14
14
 
15
15
  Want to get a quick API server up and runing? You can do it for real quick!
16
16
  <br />
17
- [![Video Title](https://img.youtube.com/vi/ko7H70s7qq0/0.jpg)](https://www.youtube.com/watch?v=ko7H70s7qq0)
18
-
19
- All greaet 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
- - [Logger](#Logger)
17
+ [![Watch the demo](https://img.youtube.com/vi/ko7H70s7qq0/hqdefault.jpg)](https://www.youtube.com/watch?v=ko7H70s7qq0)
18
+ ## Content
19
+
20
+ - [Installation](#installation)
21
+ - [Run tests](#run-tests)
22
+ - [Draw contract](#draw-contract)
23
+ - [Model](#model)
24
+ - [Routing](#routing)
25
+ - [Database](#database)
26
+ - [Views](#views)
27
+ - [Hooks](#hooks)
28
+ - [JWT based authentification](#jwt-based-authentification)
29
+ - [Rubee commands](#rubee-commands)
30
+ - [Generate commands](#generate-commands)
31
+ - [Migration commands](#migration-commands)
32
+ - [Rubee console](#rubee-console)
33
+ - [Testing](#testing)
34
+ - [Background jobs](#background-jobs)
35
+ - [Modular](#modualar-application)
36
+ - [Logger](#logger)
39
37
 
40
38
  ## Features
41
39
 
42
- - **Lightweight**: A minimal footprint that focuses on serving Ruby applications efficiently.
43
- - **Contract driven**: Define your API contracts in a simple, declarative manner. And generate the files for you.
44
- - **Fast**: Optimized for speed, providing a quick response to requests. Everything is relative, I know!
45
- - **Rack**: Rack backed. All Rack api is available for integration.
46
- - **Databases**: Sqlite3, Postgres, Mysql and many more supported by sequel gem.
47
- - **Views**: Json, ERB and plain HTML and ..
48
- - **React** is supported out of the box as a rubee view
49
- - **Bundlable** Charge your ruBee with any gem you need and update your project with bundle.
50
- - **ORM** All models are natively ORM objects, however you can use it as a blueurpint for any datasources.
51
- - **Authentificatable** Add JWT authentification easily to any controller action.
52
- - **Hooks** Addlogic before, after and around any action.
53
- - **Test** Run all or selected tests witin minitest.
54
- - **Asyncable** Add async adapter and pick any popular background job queue enginee
55
- - **Console** Start the interactive console and reload it on the fly
56
- - **Background jobs** Add async adapter and pick any popular background job queue engine
40
+ 🐝 Lightweight A minimal footprint focused on serving Ruby applications efficiently.
41
+ <br>
42
+ 🧩 Modular A modular approach to application development. Build modular monoliths with ease by attaching \
43
+ as many subprojects as you need.
44
+ <br>
45
+ 📜 Contract-driven Define your API contracts in a simple, declarative way, then generate all the boilerplate you need.
46
+ <br>
47
+ Fast Optimized for speed, providing quick responses. (Everything is relative, we know! 😄)
48
+ <br>
49
+ 🧱 Rack-powered Built on Rack. The full Rack API is available for easy integration.
50
+ <br>
51
+ 🗄️ Databases Supports SQLite3, PostgreSQL, MySQL, and more via the Sequel gem.
52
+ <br>
53
+ 🖼️ Views JSON, ERB, and plain HTML out of the box.
54
+ <br>
55
+ ⚛️ React Ready – React is supported as a first-class Rubee view engine.
56
+ <br>
57
+ 📦 Bundlable – Charge your Rubee app with any gem you need. Update effortlessly via Bundler.
58
+ <br>
59
+ 🧬 ORM-agnostic – Models are native ORM objects, but you can use them as blueprints for any data source.
60
+ <br>
61
+ 🔐 Authenticatable – Easily add JWT authentication to any controller action.
62
+ <br>
63
+ 🪝 Hooks – Add logic before, after, or around any controller action.
64
+ <br>
65
+ 🧪 Testable – Run all or selected tests using fast, beloved Minitest.
66
+ <br>
67
+ 👷 Asyncable – Plug in async adapters and use any popular background job engine.
68
+ <br>
69
+ ⌨️ Console – Start an interactive console and reload on the fly.
70
+ <br>
71
+ ⚙️ Background Jobs – Schedule and process background jobs using your preferred async stack.
57
72
 
58
73
  ## Installation
59
74
 
@@ -65,14 +80,17 @@ gem install ru.Bee
65
80
  2. Create your first project
66
81
  ```bash
67
82
  rubee project my_project
83
+
68
84
  cd my_project
69
85
  ```
70
86
 
87
+ [Back to content](#content)
88
+
71
89
  3. Install dependencies
72
90
 
73
91
  ***Prerequisites***<br />
74
92
  Make sure:
75
- **Ruby** language (3+) is installed
93
+ **Ruby** language (3.1>) is installed
76
94
  **Bundler** is installed
77
95
 
78
96
  ```bash
@@ -81,7 +99,7 @@ bundle install
81
99
 
82
100
  4. Run ruBee server. Default port is 7000
83
101
  ```bash
84
- rubee start
102
+ rubee start # or rubee start_dev for development
85
103
  ```
86
104
 
87
105
  5. Open your browser and go to http://localhost:7000
@@ -89,9 +107,13 @@ rubee start
89
107
  ## Run tests
90
108
  ```bash
91
109
  rubee test
110
+ # or you can specify specific test file
111
+ rubee test models/user_model_test.rb
92
112
  ```
113
+ [Back to content](#content)
93
114
 
94
115
  ## Draw contract
116
+
95
117
  1. Add the routes to the routes.rb
96
118
  ```ruby
97
119
  Rubee::Router.draw do |router|
@@ -108,6 +130,7 @@ rubee test
108
130
  }
109
131
  end
110
132
  ```
133
+
111
134
  2. generate the files
112
135
  ```bash
113
136
  rubee generate get /apples
@@ -121,16 +144,17 @@ This will generate the following files
121
144
  ```
122
145
 
123
146
  3. Run the initial db migration
124
- ```bash
147
+ ```bash
125
148
  rubee db run:all
126
- ```
149
+ ```
150
+
151
+ 4. Fill the generated files with the logic you need and run the server again!
127
152
 
128
- 5. Fill the generated files with the logic you need and run the server again!
153
+ [Back to content](#content)
129
154
 
130
155
  ## Model
131
156
  Model in ruBee is just simple ruby object that can be serilalized in the view
132
157
  in the way it required (ie json).
133
-
134
158
  Here below is a simple example on how it can be used by rendering json from in memory object
135
159
 
136
160
  ```ruby
@@ -152,6 +176,7 @@ Just make sure Serializable module included in the target class.
152
176
  attr_accessor :id, :colour, :weight
153
177
  end
154
178
  ```
179
+
155
180
  However, you can simply turn it to ORM object by extending database class Rubee::SequelObject.
156
181
  This one is already serializable and charged with hooks.
157
182
  ```Ruby
@@ -175,7 +200,9 @@ So in the controller you would need to query your target object now.
175
200
  end
176
201
  ```
177
202
 
178
- #### Rubee::SequelObject base methods:
203
+ [Back to content](#content)
204
+
205
+ #### Rubee::SequelObject base methods
179
206
 
180
207
  Initiate new record in memory
181
208
  ```Ruby
@@ -305,8 +332,12 @@ irb(main):010> .then { |dataset| Comment.serialize(dataset) }
305
332
  This is recommended when you want to run one query and serialize it back to Rubee object only once.
306
333
  So it may safe some resources.
307
334
 
335
+ [Back to content](#content)
336
+
308
337
  ## Routing
309
- 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`
338
+ Rubee uses explicit routes. In the routes.rb yout can define routes for any of the main HTTP methods. \
339
+ You can also add any matched parameter denoted by a pair of `{ }` in the path of the route. \
340
+ Eg. `/path/to/{a_key}/somewhere`
310
341
 
311
342
  ### Routing methods
312
343
  ``` ruby
@@ -324,10 +355,14 @@ end
324
355
  ```
325
356
 
326
357
  As you see above every route is set up as:\
327
- `route.http_method path, to: "controller#action", model { ...optional }`
358
+ ```ruby
359
+ route.{http_method} {path}, to: "{controller}#{action}",
360
+ model { ...optional }, namespace { ...optional }, react { ...optional }
361
+ ```
328
362
 
329
363
  ### Defining Model attributes in routes
330
- One of Rubee's unique traits is where we can define our models for generation. You've seen above one possible way you can set up.
364
+ One of Rubee's unique traits is where we can define our models for generation. \
365
+ You've seen above one possible way you can set up.
331
366
 
332
367
  ```ruby
333
368
  Rubee::Router.draw do |router|
@@ -345,41 +380,52 @@ Rubee::Router.draw do |router|
345
380
  end
346
381
  ```
347
382
 
348
- There are many other keys supported by us and Sequel to help generate your initial db files. Other supported attribute key types are:
383
+ There are many other types supported by us and Sequel to help generate your initial db files. \
384
+ Other supported attribute key types are:
349
385
  ``` ruby
350
386
  [
351
- { name: 'key1', type: :primary},
352
- { name: 'key2', type: :string },
353
- { name: 'key3', type: :text },
354
- { name: 'key4', type: :integer },
355
- { name: 'key5', type: :date },
356
- { name: 'key6', type: :datetime },
357
- { name: 'key7', type: :time },
358
- { name: 'key8', type: :boolean },
359
- { name: 'key9', type: :bigint },
360
- { name: 'key10', type: :decimal },
361
- { name: 'key11', type: :foreign_key },
362
- { name: 'key12', type: :index },
363
- { name: 'key13', type: :unique }
387
+ { name: 'id', type: :primary},
388
+ { name: 'name', type: :string },
389
+ { name: 'description', type: :text },
390
+ { name: 'quntity', type: :integer },
391
+ { name: 'created', type: :date },
392
+ { name: 'modified', type: :datetime },
393
+ { name: 'exists', type: :time },
394
+ { name: 'active', type: :boolean },
395
+ { name: 'hash', type: :bigint },
396
+ { name: 'price', type: :decimal },
397
+ { name: 'item_id', type: :foreign_key },
398
+ { name: 'item_id_index', type: :index },
399
+ { name: 'item_id_unique', type: :unique }
364
400
  ]
365
401
  ```
366
- Every attribute can have a set of options passed based on their related [Sequel schema definition](https://github.com/jeremyevans/sequel/blob/master/doc/schema_modification.rdoc).
402
+ Every attribute can have a set of options passed based on their related \
403
+ [Sequel schema definition](https://github.com/jeremyevans/sequel/blob/master/doc/schema_modification.rdoc).
367
404
 
368
405
  An example of this would be for the type string: \
369
- `{name: 'key', type: :string, options: { size: 50, fixed: true } }`
406
+ ```ruby
407
+ {name: 'key', type: :string, options: { size: 50, fixed: true } }
408
+ ```
370
409
 
371
410
  Gets translated to:\
372
- `String :key, size: 50, fixed: true`
411
+ ```
412
+ rubyString :key, size: 50, fixed: true
413
+ ```
373
414
 
374
415
  ### Generation from routes
375
- As long as you have a `{ model: 'something' }` passed to your given route you can use it to generate your initial model files. If only a `path` and a `to:` are defined will only generate a controller and a corresponding view.
416
+ As long as you have a `{ model: 'something' }` passed to your given route, \
417
+ you can use it to generate your initial model files. If only a `path` and a `to:` are defined will only generate \
418
+ a controller and a corresponding view.
376
419
 
377
420
  To generate based on a get route for the path /apples:\
378
- `rubee generate get /apples` or `rubee gen get /apples`\
421
+ ```ruby
422
+ rubee generate get /apples # or rubee gen get /apples
423
+ ```
379
424
 
380
425
  To generate base on a patch request for the path /apples/{id}:\
381
- `rubee generate patch /apples/{id}` or `rubee gen patch /apples/{id}`
382
-
426
+ ```ruby
427
+ rubee generate patch /apples/{id} # or rubee gen patch /apples/{id}
428
+ ```
383
429
 
384
430
  Example:
385
431
  ```ruby
@@ -403,6 +449,7 @@ Rubee::Router.draw do |router|
403
449
  router.get "/apples", to: "apples#index", model: { name: 'apple' }
404
450
  end
405
451
  ```
452
+
406
453
  Will generate:
407
454
  ```bash
408
455
  ./app/controllers/apples_controller.rb # Controller with respective action
@@ -436,6 +483,83 @@ Will generate:
436
483
  ./db/create_apples.rb # Database migration file needed for creating repsective table
437
484
  ```
438
485
 
486
+
487
+ ### Modualar application
488
+
489
+ You can also use ruBee to create modular applications.\
490
+ And attach as many subprojects you need.
491
+ Main philosophy of attach functinality is to keep the main project clean and easy to maintain. It will still\
492
+ share data with the main app. So where to define a border between the main app and subprojects is up to developer.
493
+ Howerver by attching new subproject you will get a new folder and files configured and namespaced respectively.
494
+
495
+ So if you need to extend your main app with a separate project, you can do it easily in ruBee.
496
+ 1. Attach new subrpoject
497
+
498
+ ```bash
499
+ rubee attach admin
500
+ ```
501
+ This will create a dedicated folder in the project root called admin and all the MVC setup, route and configuraion \
502
+ files will be created there.
503
+
504
+ 2. Add routes
505
+
506
+ ```ruby
507
+ # admin_routes.rb
508
+ Rubee::Router.draw do |router|
509
+ ...
510
+ # draw the contract
511
+ router.get '/admin/cabages', to: 'cabages#index',
512
+ model: {
513
+ name: 'cabage',
514
+ attributes: [
515
+ { name: 'id', type: :primary },
516
+ { name: 'name', type: :string }
517
+ ]
518
+ },
519
+ namespace: :admin # mandatory option for supporting namespacing
520
+ end
521
+ ```
522
+
523
+ 3. Run gen command
524
+
525
+ ```bash
526
+ rubee gen get /admin/cabages app:admin
527
+ ```
528
+
529
+ This will generate the bolierplate files:
530
+
531
+ ```bash
532
+ ./admin/controllers/cabages_controller.rb
533
+ ./admin/views/cabages_index.erb
534
+ ./admin/models/cabage.rb
535
+ ./db/create_cabages.rb
536
+ ```
537
+
538
+ 4. Perform migrations
539
+
540
+ ```bash
541
+ rubee db run:create_cabages
542
+ ```
543
+
544
+ 5. Fill the views and controller with the content
545
+
546
+ ```ruby
547
+ # ./admin/controllers/cabages_controller.rb
548
+ class Admin::CabagesController < Rubee::BaseController
549
+ def index
550
+ response_with object: Cabage.all, type: :json
551
+ end
552
+ end
553
+ ```
554
+
555
+ 6. Run the rubee server
556
+
557
+ ```bash
558
+ rubee start # or rubee start_dev for development
559
+ ```
560
+
561
+ [Back to content](#content)
562
+
439
563
  ## Views
440
564
  View in ruBee is just a plain html/erb/react file that can be rendered from the controller.
441
565
 
@@ -483,6 +607,7 @@ Prerequisites: Node and NPM are required
483
607
  ```bash
484
608
  rubee react prepare # this will install react related node modules
485
609
  ```
610
+
486
611
  2. Make sure you have configured react in the configuration file
487
612
 
488
613
  ```ruby
@@ -516,7 +641,7 @@ Rubee::Router.draw do |router|
516
641
  router.get('/', to: 'welcome#show') # override it for your app
517
642
 
518
643
  router.get('/api/users', to: 'user#index', react: { view_name: 'users.tsx' })
519
- # Please note /api/users is the backend endpoint
644
+ # Please note /api/users here is the backend endpoint
520
645
  # For rendering generated /app/views/users.tsx file, you need to update react routes
521
646
  end
522
647
  ```
@@ -570,6 +695,7 @@ function Users() {
570
695
  }
571
696
 
572
697
  ```
698
+ [Back to content](#content)
573
699
 
574
700
  ## Object hooks
575
701
 
@@ -613,7 +739,10 @@ after log around
613
739
  127.0.0.1 - - [17/Feb/2025:11:42:14 -0500] "GET /apples HTTP/1.1" 401 - 0.0359
614
740
  ```
615
741
 
742
+ [Back to content](#content)
743
+
616
744
  ## JWT based authentification
745
+
617
746
  Charge you rpoject with token based authentification system and customize it for your needs.
618
747
  include AuthTokenable module to your controller and authentificate any action you need.
619
748
 
@@ -662,6 +791,8 @@ class UsersController < Rubee::BaseController
662
791
  end
663
792
  ```
664
793
 
794
+ [Back to content](#content)
795
+
665
796
  ## Rubee commands
666
797
  ```bash
667
798
  rubee start # start the server
@@ -696,6 +827,9 @@ rubee test # run all tests
696
827
  rubee test auth_tokenable_test.rb # run specific tests
697
828
  ```
698
829
 
830
+ [Back to content](#content)
831
+
832
+
699
833
  If you want to run any ruBee command within a specific ENV make sure you added it before a command.
700
834
  For instance if you want to run console in test environment you need to run the following command
701
835
 
@@ -760,6 +894,7 @@ end
760
894
  ```ruby
761
895
  TestAsyncRunnner.new.perform_async(options: {"email"=> "new@new.com", "password"=> "123"})
762
896
  ```
897
+
763
898
  ### Default engine is ThreadAsync
764
899
  However it is not yet recommended for production. Use it with cautions!
765
900
  1. Do not define any adapter in the /config/base_configuration.rb file, so default ThreadAsync will be taken.
@@ -776,6 +911,9 @@ end
776
911
 
777
912
  TestAsyncRunnner.new.perform_async(options: {"email"=> "new@new.com", "password"=> "123"})
778
913
  ```
914
+
915
+ [Back to content](#content)
916
+
779
917
  ### Logger
780
918
 
781
919
  You can use your own logger by setting it in the /config/base_configuration.rb.
@@ -822,6 +960,8 @@ When you trigger the controller action, the logs will look like this:
822
960
  [2025-04-26 12:32:33] DEBUG [method: show][class_name: WelcomeController] #<User:0x000000012c5c63e0 @id=4545, @email="ok@op.com", @password="123">
823
961
  ```
824
962
 
963
+ [Back to content](#content)
964
+
825
965
  ### Contributing
826
966
 
827
967
  If you are interested in contributing to ruBee,
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.6.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
@@ -43,7 +43,7 @@ files:
43
43
  - lib/Dockerfile
44
44
  - lib/app/controllers/welcome_controller.rb
45
45
  - lib/app/models/user.rb
46
- - lib/app/views/app.tsx
46
+ - lib/app/views/App.tsx
47
47
  - lib/app/views/index.html
48
48
  - lib/app/views/layout.erb
49
49
  - lib/app/views/utils/redirectToBackend.tsx
@@ -61,6 +61,7 @@ files:
61
61
  - lib/db/structure.rb
62
62
  - lib/esbuild.config.js
63
63
  - lib/images/rubee.svg
64
+ - lib/inits/charged_hash.rb
64
65
  - lib/inits/charged_string.rb
65
66
  - lib/inits/print_colors.rb
66
67
  - lib/js/app.js
@@ -233,6 +234,17 @@ files:
233
234
  - lib/rubee/async/thread_async.rb
234
235
  - lib/rubee/async/thread_pool.rb
235
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
236
248
  - lib/rubee/configuration.rb
237
249
  - lib/rubee/controllers/base_controller.rb
238
250
  - lib/rubee/controllers/extensions/auth_tokenable.rb
@@ -246,6 +258,7 @@ files:
246
258
  - lib/rubee/models/sequel_object.rb
247
259
  - lib/rubee/router.rb
248
260
  - lib/tests/async/thread_async_test.rb
261
+ - lib/tests/cli/attach_test.rb
249
262
  - lib/tests/controllers/auth_tokenable_test.rb
250
263
  - lib/tests/controllers/base_controller_test.rb
251
264
  - lib/tests/controllers/hookable_test.rb
@@ -261,6 +274,7 @@ files:
261
274
  - lib/tests/models/db_objectable_test.rb
262
275
  - lib/tests/models/seralizable_test.rb
263
276
  - lib/tests/models/user_model_test.rb
277
+ - lib/tests/rubee_attach_test.rb
264
278
  - lib/tests/rubee_generator_test.rb
265
279
  - lib/tests/test.db
266
280
  - lib/tests/test_helper.rb
@@ -276,7 +290,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
276
290
  requirements:
277
291
  - - ">="
278
292
  - !ruby/object:Gem::Version
279
- version: 3.2.1
293
+ version: 3.4.1
280
294
  required_rubygems_version: !ruby/object:Gem::Requirement
281
295
  requirements:
282
296
  - - ">="
File without changes