ru.Bee 1.2.0 → 1.3.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/lib/app/views/layout.erb +46 -0
- data/lib/app/views/welcome_header.erb +1 -0
- data/lib/app/views/welcome_show.erb +3 -43
- data/lib/rubee/controllers/base_controller.rb +22 -4
- data/lib/tests/test.db +0 -0
- data/readme.md +172 -34
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01285afa9a2c3b5f9a08cd5cbd58ddbd300181a1cc4c5b823710c873e84300a
|
4
|
+
data.tar.gz: 241e42bbccbfe0731d83b80d58f5d40f0969c003b067660e53ace470294f2896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dbdeed01d5187c61ebbc3bc5773ce9d6150f6952fe634e76d4c8f22718b3c14091f591b879e9ecf94954672d8f9719ce1994f490966cc2d79aa899baca8e994
|
7
|
+
data.tar.gz: 91eaf06432d1f35f1c1450ea0af9bac800194bfc448bd055e7455294170682965f9e25122e2a6e64d9587049dbe6b91c6b062c6a345381cd11c3f22bb98fd60d
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title><%= @title || '' %></title>
|
7
|
+
<style>
|
8
|
+
body {
|
9
|
+
display: flex;
|
10
|
+
justify-content: center;
|
11
|
+
align-items: center;
|
12
|
+
height: 100vh;
|
13
|
+
margin: 0;
|
14
|
+
background-color: #fdf6a5;
|
15
|
+
text-align: center;
|
16
|
+
font-family: Arial, sans-serif;
|
17
|
+
}
|
18
|
+
.container {
|
19
|
+
padding: 20px;
|
20
|
+
background: white;
|
21
|
+
border-radius: 10px;
|
22
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
23
|
+
}
|
24
|
+
img {
|
25
|
+
width: 50px;
|
26
|
+
height: auto;
|
27
|
+
margin-top: 10px;
|
28
|
+
}
|
29
|
+
h1 {
|
30
|
+
font-size: 1.8rem;
|
31
|
+
margin: 10px 0;
|
32
|
+
}
|
33
|
+
@media (max-width: 600px) {
|
34
|
+
h1 {
|
35
|
+
font-size: 1.5rem;
|
36
|
+
}
|
37
|
+
img {
|
38
|
+
width: 60px;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
</style>
|
42
|
+
</head>
|
43
|
+
<body>
|
44
|
+
<%= _yield_template %>
|
45
|
+
</body>
|
46
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>All set up and running!</h1>
|
@@ -1,48 +1,9 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
|
-
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>Setup Complete</title>
|
7
|
-
<style>
|
8
|
-
body {
|
9
|
-
display: flex;
|
10
|
-
justify-content: center;
|
11
|
-
align-items: center;
|
12
|
-
height: 100vh;
|
13
|
-
margin: 0;
|
14
|
-
background-color: #fdf6a5;
|
15
|
-
text-align: center;
|
16
|
-
font-family: Arial, sans-serif;
|
17
|
-
}
|
18
|
-
.container {
|
19
|
-
padding: 20px;
|
20
|
-
background: white;
|
21
|
-
border-radius: 10px;
|
22
|
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
23
|
-
}
|
24
|
-
img {
|
25
|
-
width: 50px;
|
26
|
-
height: auto;
|
27
|
-
margin-top: 10px;
|
28
|
-
}
|
29
|
-
h1 {
|
30
|
-
font-size: 1.8rem;
|
31
|
-
margin: 10px 0;
|
32
|
-
}
|
33
|
-
@media (max-width: 600px) {
|
34
|
-
h1 {
|
35
|
-
font-size: 1.5rem;
|
36
|
-
}
|
37
|
-
img {
|
38
|
-
width: 60px;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
</style>
|
42
|
-
</head>
|
43
|
-
<body>
|
4
|
+
|
44
5
|
<div class="container">
|
45
|
-
|
6
|
+
<%= render_template :welcome_header %>
|
46
7
|
<br/>
|
47
8
|
<img src="images/rubee.svg" alt="ruBee">
|
48
9
|
<br/>
|
@@ -50,5 +11,4 @@
|
|
50
11
|
<br/>
|
51
12
|
<p>Version: <%= Rubee::VERSION %></p>
|
52
13
|
</div>
|
53
|
-
|
54
|
-
</html>
|
14
|
+
|
@@ -18,7 +18,7 @@ module Rubee
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def response_with type: nil, object: nil, status: 200, mime_type: nil, render_view: nil, headers: {}, to: nil, file: nil, filename: nil
|
21
|
+
def response_with type: nil, object: nil, status: 200, mime_type: nil, render_view: nil, headers: {}, to: nil, file: nil, filename: nil, **options
|
22
22
|
case type&.to_sym
|
23
23
|
in :json
|
24
24
|
rendered_json = object.is_a?(Array) ? object&.map(&:to_h).to_json : object.to_json
|
@@ -42,13 +42,31 @@ module Rubee
|
|
42
42
|
return [302, headers.merge("location" => "#{to}"), ["Unauthentificated"]]
|
43
43
|
else # rendering erb view is a default behavior
|
44
44
|
view_file_name = self.class.name.split("Controller").first.downcase
|
45
|
-
erb_file = render_view ? "#{render_view}
|
45
|
+
erb_file = render_view ? "#{render_view}" : "#{view_file_name}_#{@route[:action]}"
|
46
46
|
lib = Rubee::PROJECT_NAME == 'rubee' ? 'lib/' : ''
|
47
|
-
|
48
|
-
|
47
|
+
view = render_template(erb_file, { object:, **(options[:locals] || {}) })
|
48
|
+
|
49
|
+
whole_erb = if File.exist?(layout_path = "#{lib}app/views/#{options[:layout] || 'layout'}.erb")
|
50
|
+
context = Object.new
|
51
|
+
context.define_singleton_method(:_yield_template) { view }
|
52
|
+
layout = File.read(layout_path)
|
53
|
+
ERB.new(layout).result(context.instance_eval { binding })
|
54
|
+
else
|
55
|
+
ERB.new(view).result(binding)
|
56
|
+
end
|
57
|
+
|
58
|
+
return [status, headers.merge("content-type" => "text/html"), [whole_erb]]
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
62
|
+
def render_template(file_name, locals = {})
|
63
|
+
lib = Rubee::PROJECT_NAME == 'rubee' ? 'lib/' : ''
|
64
|
+
path = "#{lib}app/views/#{file_name}.erb"
|
65
|
+
erb_template = ERB.new(File.read(path))
|
66
|
+
|
67
|
+
erb_template.result(binding)
|
68
|
+
end
|
69
|
+
|
52
70
|
def params
|
53
71
|
inputs = @request.env['rack.input'].read
|
54
72
|
body = JSON.parse(@request.body.read.strip) rescue body = {}
|
data/lib/tests/test.db
CHANGED
Binary file
|
data/readme.md
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|

|
7
7
|
|
8
8
|
|
9
|
-
# <img src="lib/images/rubee.svg" alt="
|
9
|
+
# <img src="lib/images/rubee.svg" alt="ruBee" height="40"> ... ruBee
|
10
10
|
|
11
|
-
|
11
|
+
ruBee is a fast and lightweight Ruby application server designed for minimalism and flexibility .
|
12
12
|
|
13
|
-
The main philosophy of
|
13
|
+
The main philosophy of ruBee is to focus on Ruby language explicit implementation of the MVC web application.
|
14
14
|
|
15
15
|
Want to get a quick API server up and runing? You can do it for real quick!
|
16
16
|
<br />
|
@@ -27,7 +27,7 @@ All greaet features are yet to come!
|
|
27
27
|
- **Router**: Router driven - generates all required files from the routes.
|
28
28
|
- **Databases**: Sqlite3, Postgres, Mysql and many more supported by sequel gem.
|
29
29
|
- **Views**: Json, ERB and plain HTML
|
30
|
-
- **Bundlable** Charge your
|
30
|
+
- **Bundlable** Charge your ruBee with any gem you need and update your project with bundle.
|
31
31
|
- **ORM** All models are natively ORM objects, however you can use it as a blueurpint for any datasources.
|
32
32
|
- **Authentificatable** Add JWT authentification easily to any controller action.
|
33
33
|
- **Hooks** Add logic before, after and around any action.
|
@@ -36,7 +36,7 @@ All greaet features are yet to come!
|
|
36
36
|
|
37
37
|
## Installation
|
38
38
|
|
39
|
-
1. Install
|
39
|
+
1. Install ruBee
|
40
40
|
```bash
|
41
41
|
gem install ru.Bee
|
42
42
|
```
|
@@ -50,7 +50,7 @@ cd my_project
|
|
50
50
|
3. Install dependencies
|
51
51
|
|
52
52
|
***Prerequisites***<br />
|
53
|
-
**
|
53
|
+
**ruBee** is using **Sqlite** as a default database. However you can pick up any other database supported by sequel gem.
|
54
54
|
Aside that, make sure:
|
55
55
|
**Ruby** language (3+) is installed
|
56
56
|
**Bundler** is installed
|
@@ -59,7 +59,7 @@ Aside that, make sure:
|
|
59
59
|
bundle install
|
60
60
|
```
|
61
61
|
|
62
|
-
4. Run
|
62
|
+
4. Run ruBee server. Default port is 7000
|
63
63
|
```bash
|
64
64
|
rubee start
|
65
65
|
```
|
@@ -97,7 +97,7 @@ rubee generate get /apples
|
|
97
97
|
4. Fill those files with the logic you need and run the server again!
|
98
98
|
|
99
99
|
## Model
|
100
|
-
Model in
|
100
|
+
Model in ruBee is just simple ruby object that can be serilalized in the view
|
101
101
|
in the way it required (ie json).
|
102
102
|
|
103
103
|
Here below is a simple example on how it can be used by rendering json from in memory object
|
@@ -128,24 +128,6 @@ However, you can simply turn it to ORM object by extending database class.
|
|
128
128
|
attr_accessor :id, :colour, :weight
|
129
129
|
end
|
130
130
|
```
|
131
|
-
Rubee::SequelObject methods:
|
132
|
-
|
133
|
-
- `apple.save`
|
134
|
-
- `apple.destroy(cascade: true)` # default false
|
135
|
-
- `apple.destroy_all`
|
136
|
-
- `apple.update(colour: 'red')`
|
137
|
-
- `apple.persisted?`
|
138
|
-
- `apple.reload`
|
139
|
-
- `apple.assign_attributes(colour: 'red', weight: '1lb')`
|
140
|
-
- `Apple.last`
|
141
|
-
- `Apple.where(colour: 'red')`
|
142
|
-
- `Apple.last`
|
143
|
-
- `Apple.all`
|
144
|
-
- `Apple.create(colour: 'red', weight: '1lb')`
|
145
|
-
- `Apple.destroy_all`
|
146
|
-
- `Apple.serialize`
|
147
|
-
- `Apple.serialize(Apple.dataset.joins(:trees).where(tree: { colour: 'brown' }))`
|
148
|
-
...
|
149
131
|
|
150
132
|
So in the controller you would need to query your target object now.
|
151
133
|
|
@@ -163,12 +145,144 @@ So in the controller you would need to query your target object now.
|
|
163
145
|
end
|
164
146
|
```
|
165
147
|
|
148
|
+
#### Rubee::SequelObject base methods:
|
149
|
+
|
150
|
+
Initiate new record in memory
|
151
|
+
```Ruby
|
152
|
+
irb(main):015> user = User.new(email: "llo@ok.com", password: 543)
|
153
|
+
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543>
|
154
|
+
```
|
155
|
+
|
156
|
+
Save record in db
|
157
|
+
```Ruby
|
158
|
+
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543>
|
159
|
+
irb(main):018> user.save
|
160
|
+
=> true
|
161
|
+
```
|
162
|
+
|
163
|
+
Update record with new value
|
164
|
+
```Ruby
|
165
|
+
irb(main):019> user.update(email: "update@email.com")
|
166
|
+
=> #<User:0x000000010c39b298 @email="update@email.com", @id=3, @password="543">
|
167
|
+
```
|
168
|
+
|
169
|
+
Check whether it includes id
|
170
|
+
```Ruby
|
171
|
+
irb(main):015> user = User.new(email: "llo@ok.com", password: 543)
|
172
|
+
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543>
|
173
|
+
irb(main):016> user.persisted?
|
174
|
+
=> false
|
175
|
+
```
|
176
|
+
|
177
|
+
Get the record from the database
|
178
|
+
```Ruby
|
179
|
+
irb(main):011> user = User.last
|
180
|
+
=> #<User:0x000000010ccea178 @email="ok23@ok.com", @id=2, @password="123">
|
181
|
+
irb(main):012> user.email = "new@ok.com"
|
182
|
+
=> "new@ok.com"
|
183
|
+
irb(main):013> user
|
184
|
+
=> #<User:0x000000010ccea178 @email="new@ok.com", @id=2, @password="123">
|
185
|
+
irb(main):014> user.reload
|
186
|
+
=> #<User:0x000000010c488548 @email="ok23@ok.com", @id=2, @password="123"> # not persited data was updated from db
|
187
|
+
```
|
188
|
+
|
189
|
+
Assign attributes without persisiting it to db
|
190
|
+
```Ruby
|
191
|
+
irb(main):008> User.last.assign_attributes(email: "bb@ok.com")
|
192
|
+
=> {"id" => 2, "email" => "ok23@ok.com", "password" => "123"
|
193
|
+
```
|
194
|
+
|
195
|
+
Get all records scoped by field
|
196
|
+
```Ruby
|
197
|
+
irb(main):005> User.where(email: "ok23@ok.com")
|
198
|
+
=> [#<User:0x000000010cfaa5c0 @email="ok23@ok.com", @id=2, @password="123">]
|
199
|
+
```
|
200
|
+
|
201
|
+
Get all record
|
202
|
+
```Ruby
|
203
|
+
irb(main):001> User.all
|
204
|
+
=> [#<User:0x000000010c239a30 @email="ok@ok.com", @id=1, @password="password">]
|
205
|
+
```
|
206
|
+
Find by id
|
207
|
+
```Ruby
|
208
|
+
irb(main):002> user = User.find 1
|
209
|
+
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password">
|
210
|
+
```
|
211
|
+
|
212
|
+
Get last record
|
213
|
+
```Ruby
|
214
|
+
irb(main):003> User.last
|
215
|
+
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password">
|
216
|
+
```
|
217
|
+
|
218
|
+
Create new persited record
|
219
|
+
```Ruby
|
220
|
+
irb(main):004> User.create(email: "ok23@ok.com", password: 123)
|
221
|
+
=> #<User:0x000000010c393818 @email="ok23@ok.com", @id=2, @password=123>
|
222
|
+
```
|
223
|
+
|
224
|
+
Destroy record and all related records
|
225
|
+
```Ruby
|
226
|
+
irb(main):021> user.destroy(cascade: true)
|
227
|
+
=> 1
|
228
|
+
```
|
229
|
+
|
230
|
+
Destroy all records one by one
|
231
|
+
```Ruby
|
232
|
+
irb(main):022> User.destroy_all
|
233
|
+
=> [#<User:0x000000010d42df98 @email="ok@ok.com", @id=1, @password="password">, #<User:0x000000010d42de80 @email="ok23@ok.com", @id=2, @password="123">
|
234
|
+
irb(main):023> User.all
|
235
|
+
=> []
|
236
|
+
```
|
237
|
+
|
238
|
+
Use complex queries chains and when ready serialize it back to Rubee object.
|
239
|
+
```Ruby
|
240
|
+
# user model
|
241
|
+
class User < Rubee::SequelObject
|
242
|
+
attr_accessor :id, :email, :password
|
243
|
+
owns_many :comments, over: :posts
|
244
|
+
end
|
245
|
+
|
246
|
+
# comment model
|
247
|
+
class Comment < Rubee::SequelObject
|
248
|
+
attr_accessor :id, :text, :user_id
|
249
|
+
owns_many :users, over: :posts
|
250
|
+
end
|
251
|
+
|
252
|
+
# join post model
|
253
|
+
class Post < Rubee::SequelObject
|
254
|
+
attr_accessor :id, :user_id, :comment_id
|
255
|
+
holds :comment
|
256
|
+
holds :user
|
257
|
+
end
|
258
|
+
```
|
259
|
+
|
260
|
+
```Ruby
|
261
|
+
irb(main):001> comment = Comment.new(text: "test")
|
262
|
+
irb(main):002> comment.save
|
263
|
+
irb(main):003> user = User.new(email: "ok-test@test.com", password: "123")
|
264
|
+
irb(main):004> user.save
|
265
|
+
irb(main):005> post = Post.new(user_id: user.id, comment_id: comment.id)
|
266
|
+
irb(main):006> post.save
|
267
|
+
=> true
|
268
|
+
irb(main):007> comment
|
269
|
+
=> #<Comment:0x000000012281a650 @id=21, @text="test">
|
270
|
+
irb(main):008> result = Comment.dataset.join(:posts, comment_id: :id)
|
271
|
+
irb(main):009> .where(comment_id: Comment.where(text: "test").last.id)
|
272
|
+
irb(main):010> .then { |dataset| Comment.serialize(dataset) }
|
273
|
+
=> [#<Comment:0x0000000121889998 @id=30, @text="test", @user_id=702>]
|
274
|
+
```
|
275
|
+
This is recommended when you want to run one query and serialize it back to Rubee object only once.
|
276
|
+
So it may safe some resources.
|
277
|
+
|
278
|
+
|
279
|
+
|
166
280
|
## Views
|
167
|
-
View in
|
281
|
+
View in ruBee is just a plain html/erb file that can be rendered from the controller.
|
168
282
|
|
169
283
|
## Object hooks
|
170
284
|
|
171
|
-
In
|
285
|
+
In ruBee by extending Hookable module any Ruby object can be charged with hooks (logic),
|
172
286
|
that can be executed before, after and around a specific method execution.
|
173
287
|
|
174
288
|
Here below a controller example. However it can be used in any Ruby object, like Model etc.
|
@@ -286,7 +400,7 @@ rubee console # start the console
|
|
286
400
|
rubee test # run all tests
|
287
401
|
rubee test auth_tokenable_test.rb # run specific tests
|
288
402
|
```
|
289
|
-
If you want to run any
|
403
|
+
If you want to run any ruBee command within a specific ENV make sure you added it before a command.
|
290
404
|
For instance if you want to run console in test environment you need to run the following command
|
291
405
|
|
292
406
|
```bash
|
@@ -367,8 +481,32 @@ end
|
|
367
481
|
TestAsyncRunnner.new.perform_async(options: {"email"=> "new@new.com", "password"=> "123"})
|
368
482
|
```
|
369
483
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
484
|
+
### Contributing
|
485
|
+
|
486
|
+
You are more than welcome to contribute to ruBee! To do so, please follow these steps:
|
487
|
+
|
488
|
+
1. Fork the repository by clicking the "Fork" button on the GitHub page.
|
489
|
+
|
490
|
+
2. Clone your fork:
|
491
|
+
```bash
|
492
|
+
git clone https://github.com/your-username/rubee.git
|
493
|
+
```
|
494
|
+
|
495
|
+
3. Create a new branch for your feature or bug fix:
|
496
|
+
```bash
|
497
|
+
git checkout -b feature/your-feature-name
|
498
|
+
```
|
499
|
+
|
500
|
+
4. Make your changes and commit them with descriptive messages:
|
501
|
+
```bash
|
502
|
+
git commit -m "Add feature: [brief description of feature]"
|
503
|
+
```
|
504
|
+
|
505
|
+
5. Push your changes to your fork:
|
506
|
+
```bash
|
507
|
+
git push origin feature/your-feature-name
|
508
|
+
```
|
509
|
+
|
510
|
+
6. Submit a pull request to the main branch of the original repository.
|
511
|
+
|
512
|
+
Let's make it shine even brighter!
|
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.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Saltykov
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-06 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|
@@ -43,6 +43,8 @@ files:
|
|
43
43
|
- lib/Dockerfile
|
44
44
|
- lib/app/controllers/welcome_controller.rb
|
45
45
|
- lib/app/models/user.rb
|
46
|
+
- lib/app/views/layout.erb
|
47
|
+
- lib/app/views/welcome_header.erb
|
46
48
|
- lib/app/views/welcome_show.erb
|
47
49
|
- lib/config.ru
|
48
50
|
- lib/config/base_configuration.rb
|