ru.Bee 1.9.14 → 1.10.1
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/models/user.rb +1 -1
- data/lib/app/views/s_.erb +1 -0
- data/lib/db/create_accounts.rb +3 -0
- data/lib/db/create_addresses.rb +3 -0
- data/lib/db/create_comments.rb +4 -0
- data/lib/db/create_posts.rb +3 -0
- data/lib/db/create_users.rb +3 -0
- data/lib/rubee/cli/test.rb +57 -1
- data/lib/rubee/extensions/hookable.rb +43 -6
- data/lib/rubee/models/sequel_object.rb +19 -3
- data/lib/rubee.rb +1 -1
- data/lib/tests/example_models/account.rb +1 -1
- data/lib/tests/example_models/address.rb +1 -1
- data/lib/tests/example_models/comment.rb +1 -1
- data/lib/tests/example_models/post.rb +1 -1
- data/lib/tests/example_models/user.rb +1 -1
- data/lib/tests/logger_test.rb +6 -0
- data/lib/tests/models/user_model_test.rb +41 -0
- data/lib/tests/test.db +0 -0
- data/readme.md +39 -28
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e34bf9669d522ca579263e0ea388b8157f443f362991a36b7e76b73b69d49467
|
4
|
+
data.tar.gz: a58a62af03a502867bbd61316b4983a2114dc2d5a64e5744941c3bcb03776c70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0e8688ef9c4c8ae50552e5db73964ae477b036383eb10cf7194df7edf31b58f7e9fb143689e61f6445750933d9dec9815ffd7e67d0cd0cf684df96b90fd9df3
|
7
|
+
data.tar.gz: ea6871cf13344b5d235eff69b7fc6df7cd98e9061aeaa593b682b9a35071f73a7dad8a5012778bf55a64b8f1ef49ffdc4ad49cc6bf702cbacfa39410a1f2368c
|
data/lib/app/models/user.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<h1>s_ View</h1>
|
data/lib/db/create_accounts.rb
CHANGED
data/lib/db/create_addresses.rb
CHANGED
@@ -10,6 +10,9 @@ class CreateAddresses
|
|
10
10
|
String(:street)
|
11
11
|
String(:apt)
|
12
12
|
foreign_key(:user_id, :users)
|
13
|
+
# timestamps
|
14
|
+
datetime(:created)
|
15
|
+
datetime(:updated)
|
13
16
|
end
|
14
17
|
|
15
18
|
# Address.create(street: '13th Ave', city: 'NY', state: 'NY', zip: '55555', user_id: User.all.first.id)
|
data/lib/db/create_comments.rb
CHANGED
data/lib/db/create_posts.rb
CHANGED
data/lib/db/create_users.rb
CHANGED
data/lib/rubee/cli/test.rb
CHANGED
@@ -9,15 +9,71 @@ module Rubee
|
|
9
9
|
def test(argv)
|
10
10
|
ENV['RACK_ENV'] = 'test'
|
11
11
|
file_name = argv[1] # Get the first argument
|
12
|
+
line = argv[2]&.start_with?('--line=') ? argv[2].split('=')[1] : nil
|
12
13
|
lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
|
13
|
-
if file_name
|
14
|
+
if file_name && !line
|
14
15
|
color_puts("Running #{file_name} test ...", color: :yellow)
|
15
16
|
exec("ruby -Itest -e \"require '.#{lib}/tests/#{file_name}'\"")
|
17
|
+
elsif file_name && line
|
18
|
+
color_puts("Running #{file_name} test at line #{line} ...", color: :yellow)
|
19
|
+
test_name = find_test_at_line(".#{lib}/tests/#{file_name}", line)
|
20
|
+
exec("ruby -Itest .#{lib}/tests/#{file_name} -n #{test_name}")
|
16
21
|
else
|
17
22
|
color_puts('Running all tests ...', color: :yellow)
|
18
23
|
exec("ruby -Itest -e \"Dir.glob('.#{lib}/tests/**/*_test.rb').each { |file| require file }\"")
|
19
24
|
end
|
20
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def find_test_at_line(file, line)
|
30
|
+
source = File.read(file).lines
|
31
|
+
name = nil
|
32
|
+
kind = nil
|
33
|
+
|
34
|
+
# 1. Look backwards from the line
|
35
|
+
source[0...line.to_i].reverse_each do |l|
|
36
|
+
if l =~ /^\s*def\s+(test_\w+)/
|
37
|
+
name = ::Regexp.last_match(1)
|
38
|
+
kind = :method
|
39
|
+
break
|
40
|
+
elsif l =~ /^\s*describe\s+['"](.*)['"]/
|
41
|
+
name = ::Regexp.last_match(1)
|
42
|
+
kind = :spec
|
43
|
+
break
|
44
|
+
elsif l =~ /^\s*it\s+['"](.*)['"]/
|
45
|
+
name = ::Regexp.last_match(1)
|
46
|
+
kind = :spec
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# 2. If nothing was found, fallback to first def/it in the file
|
52
|
+
if name.nil?
|
53
|
+
source.each do |l|
|
54
|
+
if l =~ /^\s*def\s+(test_\w+)/
|
55
|
+
name = ::Regexp.last_match(1)
|
56
|
+
kind = :method
|
57
|
+
break
|
58
|
+
elsif l =~ /^\s*describe\s+['"](.*)['"]/
|
59
|
+
name = ::Regexp.last_match(1)
|
60
|
+
kind = :spec
|
61
|
+
break
|
62
|
+
elsif l =~ /^\s*it\s+['"](.*)['"]/
|
63
|
+
name = ::Regexp.last_match(1)
|
64
|
+
kind = :spec
|
65
|
+
break
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# 3. Return correct `-n` filter
|
71
|
+
if kind == :spec
|
72
|
+
"/#{Regexp.escape(name)}/"
|
73
|
+
else
|
74
|
+
name
|
75
|
+
end
|
76
|
+
end
|
21
77
|
end
|
22
78
|
end
|
23
79
|
end
|
@@ -7,8 +7,18 @@ module Rubee
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def before(*methods, handler, **options)
|
10
|
+
if options[:class_methods]
|
11
|
+
methods.each do |method|
|
12
|
+
define_method(method) do |*args, &block|
|
13
|
+
self.class.send(method, *args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
private(method)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
methods.each do |method|
|
11
|
-
|
21
|
+
hook = Module.new do
|
12
22
|
define_method(method) do |*args, &block|
|
13
23
|
if conditions_met?(options[:if], options[:unless])
|
14
24
|
handler.respond_to?(:call) ? handler.call : send(handler)
|
@@ -17,13 +27,24 @@ module Rubee
|
|
17
27
|
super(*args, &block)
|
18
28
|
end
|
19
29
|
end
|
20
|
-
|
30
|
+
|
31
|
+
prepend(hook)
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
24
35
|
def after(*methods, handler, **options)
|
36
|
+
if options[:class_methods]
|
37
|
+
methods.each do |method|
|
38
|
+
define_method(method) do |*args, &block|
|
39
|
+
self.class.send(method, *args, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
private(method)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
25
46
|
methods.each do |method|
|
26
|
-
|
47
|
+
hook = Module.new do
|
27
48
|
define_method(method) do |*args, &block|
|
28
49
|
result = super(*args, &block)
|
29
50
|
|
@@ -34,13 +55,24 @@ module Rubee
|
|
34
55
|
result
|
35
56
|
end
|
36
57
|
end
|
37
|
-
|
58
|
+
|
59
|
+
prepend(hook)
|
38
60
|
end
|
39
61
|
end
|
40
62
|
|
41
63
|
def around(*methods, handler, **options)
|
64
|
+
if options[:class_methods]
|
65
|
+
methods.each do |method|
|
66
|
+
define_method(method) do |*args, &block|
|
67
|
+
self.class.send(method, *args, &block)
|
68
|
+
end
|
69
|
+
|
70
|
+
private(method)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
42
74
|
methods.each do |method|
|
43
|
-
|
75
|
+
hook = Module.new do
|
44
76
|
define_method(method) do |*args, &block|
|
45
77
|
if conditions_met?(options[:if], options[:unless])
|
46
78
|
if handler.respond_to?(:call)
|
@@ -60,7 +92,8 @@ module Rubee
|
|
60
92
|
end
|
61
93
|
end
|
62
94
|
end
|
63
|
-
|
95
|
+
|
96
|
+
prepend(hook)
|
64
97
|
end
|
65
98
|
end
|
66
99
|
end
|
@@ -68,6 +101,10 @@ module Rubee
|
|
68
101
|
module InstanceMethods
|
69
102
|
private
|
70
103
|
|
104
|
+
def handle_class_method
|
105
|
+
self.class.send(name, *args, &block)
|
106
|
+
end
|
107
|
+
|
71
108
|
def conditions_met?(if_condition = nil, unless_condition = nil)
|
72
109
|
return true if if_condition.nil? && unless_condition.nil?
|
73
110
|
|
@@ -4,6 +4,8 @@ module Rubee
|
|
4
4
|
using ChargedString
|
5
5
|
using ChargedHash
|
6
6
|
|
7
|
+
before :save, :update, :set_timestamps
|
8
|
+
|
7
9
|
def destroy(cascade: false, **_options)
|
8
10
|
if cascade
|
9
11
|
# find all tables with foreign key
|
@@ -41,14 +43,15 @@ module Rubee
|
|
41
43
|
true
|
42
44
|
end
|
43
45
|
|
44
|
-
def assign_attributes(args
|
45
|
-
|
46
|
+
def assign_attributes(args={})
|
47
|
+
self.class.dataset.columns do |attr|
|
46
48
|
send("#{attr}=", args[attr.to_sym]) if args[attr.to_sym]
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
def update(args
|
52
|
+
def update(args={})
|
51
53
|
assign_attributes(args)
|
54
|
+
args.merge!(updated:)
|
52
55
|
found_hash = self.class.dataset.where(id:)
|
53
56
|
return self.class.find(id) if Rubee::DBTools.with_retry { found_hash&.update(**args) }
|
54
57
|
|
@@ -63,6 +66,15 @@ module Rubee
|
|
63
66
|
self.class.find(id)
|
64
67
|
end
|
65
68
|
|
69
|
+
private
|
70
|
+
|
71
|
+
def set_timestamps
|
72
|
+
return unless respond_to?(:created) && respond_to?(:updated)
|
73
|
+
|
74
|
+
self.created ||= Time.now
|
75
|
+
self.updated = Time.now
|
76
|
+
end
|
77
|
+
|
66
78
|
class << self
|
67
79
|
def last
|
68
80
|
found_hash = dataset.order(:id).last
|
@@ -191,6 +203,10 @@ module Rubee
|
|
191
203
|
end
|
192
204
|
|
193
205
|
def create(attrs)
|
206
|
+
if dataset.columns.include?(:created) && dataset.columns.include?(:updated)
|
207
|
+
attrs.merge!(created: Time.now, updated: Time.now)
|
208
|
+
end
|
209
|
+
|
194
210
|
out_id = Rubee::DBTools.with_retry { dataset.insert(**attrs) }
|
195
211
|
new(**attrs.merge(id: out_id))
|
196
212
|
end
|
data/lib/rubee.rb
CHANGED
@@ -16,7 +16,7 @@ module Rubee
|
|
16
16
|
JS_DIR = File.join(APP_ROOT, LIB, 'js') unless defined?(JS_DIR)
|
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
|
-
VERSION = '1.
|
19
|
+
VERSION = '1.10.1'
|
20
20
|
|
21
21
|
require_relative 'rubee/router'
|
22
22
|
require_relative 'rubee/logger'
|
data/lib/tests/logger_test.rb
CHANGED
@@ -19,12 +19,14 @@ end
|
|
19
19
|
describe 'Rubee::Logger' do
|
20
20
|
describe 'logger' do
|
21
21
|
it 'exists' do
|
22
|
+
puts "logger exists"
|
22
23
|
_(Rubee::Logger).wont_be_nil
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
describe '.warn' do
|
27
28
|
it 'output message' do
|
29
|
+
puts "warn output message"
|
28
30
|
output = capture_stdout { Rubee::Logger.warn(message: 'test') }
|
29
31
|
|
30
32
|
assert_includes(output, "WARN test")
|
@@ -33,6 +35,7 @@ describe 'Rubee::Logger' do
|
|
33
35
|
|
34
36
|
describe '.info' do
|
35
37
|
it 'output message' do
|
38
|
+
puts "info output message"
|
36
39
|
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
37
40
|
|
38
41
|
assert_includes(output, "INFO test")
|
@@ -49,6 +52,7 @@ describe 'Rubee::Logger' do
|
|
49
52
|
|
50
53
|
describe '.critical' do
|
51
54
|
it 'output message' do
|
55
|
+
puts "critical output message"
|
52
56
|
output = capture_stdout { Rubee::Logger.critical(message: 'test') }
|
53
57
|
|
54
58
|
assert_includes(output, "CRITICAL test")
|
@@ -57,6 +61,7 @@ describe 'Rubee::Logger' do
|
|
57
61
|
|
58
62
|
describe '.debug' do
|
59
63
|
it 'output message' do
|
64
|
+
puts "debug output message"
|
60
65
|
output = capture_stdout { Rubee::Logger.debug(object: User.new(email: 'ok@ok.com', password: 123)) }
|
61
66
|
|
62
67
|
assert_includes(output, "DEBUG #<User:")
|
@@ -65,6 +70,7 @@ describe 'Rubee::Logger' do
|
|
65
70
|
|
66
71
|
describe 'when custom logger defined in the configuration' do
|
67
72
|
it 'uses custom logger' do
|
73
|
+
puts "CUSTOM INFO test"
|
68
74
|
Rubee::Configuration.setup(env = :test) { _1.logger = { logger: CustomLogger, env: } }
|
69
75
|
|
70
76
|
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
|
+
|
2
3
|
describe 'User model' do
|
3
4
|
describe '.create' do
|
4
5
|
after do
|
@@ -11,6 +12,18 @@ describe 'User model' do
|
|
11
12
|
|
12
13
|
_(user.persisted?).must_equal(true)
|
13
14
|
end
|
15
|
+
|
16
|
+
it 'set created field' do
|
17
|
+
user = User.create(email: 'ok-test@test.com', password: '123')
|
18
|
+
|
19
|
+
_(user.created.is_a?(Time)).must_equal(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'set updated field' do
|
23
|
+
user = User.create(email: 'ok-test@test.com', password: '123')
|
24
|
+
|
25
|
+
_(user.updated.is_a?(Time)).must_equal(true)
|
26
|
+
end
|
14
27
|
end
|
15
28
|
|
16
29
|
describe 'when data is invalid' do
|
@@ -39,6 +52,15 @@ describe 'User model' do
|
|
39
52
|
|
40
53
|
_(user.persisted?).must_equal(true)
|
41
54
|
end
|
55
|
+
|
56
|
+
it 'updates updated field' do
|
57
|
+
user = User.create(email: 'ok-test@test.com', password: '123')
|
58
|
+
after_create_updated = user.updated
|
59
|
+
|
60
|
+
user.email = 'ok-test2@test.com'
|
61
|
+
user.save
|
62
|
+
_(user.updated > after_create_updated).must_equal(true)
|
63
|
+
end
|
42
64
|
end
|
43
65
|
|
44
66
|
describe 'when save existing user' do
|
@@ -108,6 +130,25 @@ describe 'User model' do
|
|
108
130
|
|
109
131
|
_(user.reload.password).must_equal('1234')
|
110
132
|
end
|
133
|
+
|
134
|
+
it 'updates updated field' do
|
135
|
+
user = User.create(email: 'ok-test@test.com', password: '123')
|
136
|
+
after_create_updated = user.updated
|
137
|
+
|
138
|
+
user.update(email: 'ok-test2@test.com')
|
139
|
+
_(user.updated > after_create_updated).must_equal(true)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'when udpate existing user with no argumants' do
|
144
|
+
it 'update updated field' do
|
145
|
+
user = User.new(email: 'ok-test@test.com', password: '123')
|
146
|
+
user.save
|
147
|
+
updated_field_before_update = user.updated
|
148
|
+
|
149
|
+
user.update
|
150
|
+
_(user.updated > updated_field_before_update).must_equal(true)
|
151
|
+
end
|
111
152
|
end
|
112
153
|
end
|
113
154
|
|
data/lib/tests/test.db
CHANGED
Binary file
|
data/readme.md
CHANGED
@@ -18,7 +18,7 @@ Want to get a quick API server up and runing? You can do it for real quick!
|
|
18
18
|
|
19
19
|
## Production ready
|
20
20
|
|
21
|
-
Take a look on the rubee demo site with all documentation stored in there: https://rubee.
|
21
|
+
Take a look on the rubee demo site with all documentation stored in there: https://rubee.dedyn.io/
|
22
22
|
Want to explore how it built? https://github.com/nucleom42/rubee-site
|
23
23
|
|
24
24
|
## Stress tested
|
@@ -44,7 +44,6 @@ Transfer/sec: 140.07KB
|
|
44
44
|
|
45
45
|
This demonstrates RUBEE’s efficient architecture and suitability for lightweight deployments — even on low-power hardware.
|
46
46
|
|
47
|
-
|
48
47
|
## Content
|
49
48
|
|
50
49
|
- [Installation](#installation)
|
@@ -65,10 +64,10 @@ This demonstrates RUBEE’s efficient architecture and suitability for lightweig
|
|
65
64
|
- [Modular](#modualar-application)
|
66
65
|
- [Logger](#logger)
|
67
66
|
|
68
|
-
|
69
|
-
<summary id="content">📚 Documentation Content — Click to expand!</summary>
|
67
|
+
You can read it on the demo [site](https://rubee.dedyn.io/)
|
70
68
|
|
71
|
-
|
69
|
+
🚧 The doc site is on uodate mode now. We are working on it.
|
70
|
+
Please refer to downbelow documentation.
|
72
71
|
|
73
72
|
## Features
|
74
73
|
|
@@ -165,7 +164,9 @@ rubee test models/user_model_test.rb
|
|
165
164
|
attributes: [
|
166
165
|
{ name: 'id', type: :primary },
|
167
166
|
{ name: 'colour', type: :string },
|
168
|
-
{ name: 'weight', type: :integer }
|
167
|
+
{ name: 'weight', type: :integer },
|
168
|
+
{ name: 'created', type: :datetime },
|
169
|
+
{ name: 'updated', type: :datetime },
|
169
170
|
]
|
170
171
|
}
|
171
172
|
end
|
@@ -252,7 +253,7 @@ irb(main):015> user = User.new(email: "llo@ok.com", password: 543)
|
|
252
253
|
|
253
254
|
Save record in db
|
254
255
|
```Ruby
|
255
|
-
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543>
|
256
|
+
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543, @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
256
257
|
irb(main):018> user.save
|
257
258
|
=> true
|
258
259
|
```
|
@@ -260,7 +261,7 @@ irb(main):018> user.save
|
|
260
261
|
Update record with new value
|
261
262
|
```Ruby
|
262
263
|
irb(main):019> user.update(email: "update@email.com")
|
263
|
-
=> #<User:0x000000010c39b298 @email="update@email.com", @id=3, @password="543">
|
264
|
+
=> #<User:0x000000010c39b298 @email="update@email.com", @id=3, @password="543" @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
264
265
|
```
|
265
266
|
|
266
267
|
Check whether it includes id
|
@@ -274,13 +275,13 @@ irb(main):016> user.persisted?
|
|
274
275
|
Get the record from the database
|
275
276
|
```Ruby
|
276
277
|
irb(main):011> user = User.last
|
277
|
-
=> #<User:0x000000010ccea178 @email="ok23@ok.com", @id=2, @password="123">
|
278
|
+
=> #<User:0x000000010ccea178 @email="ok23@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
278
279
|
irb(main):012> user.email = "new@ok.com"
|
279
280
|
=> "new@ok.com"
|
280
281
|
irb(main):013> user
|
281
|
-
=> #<User:0x000000010ccea178 @email="new@ok.com", @id=2, @password="123">
|
282
|
+
=> #<User:0x000000010ccea178 @email="new@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
282
283
|
irb(main):014> user.reload
|
283
|
-
=> #<User:0x000000010c488548 @email="ok23@ok.com", @id=2, @password="123"> # not persited data was updated from db
|
284
|
+
=> #<User:0x000000010c488548 @email="ok23@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400"> # not persited data was updated from db
|
284
285
|
```
|
285
286
|
|
286
287
|
Assign attributes without persisiting it to db
|
@@ -298,24 +299,24 @@ irb(main):005> User.where(email: "ok23@ok.com")
|
|
298
299
|
Get all record
|
299
300
|
```Ruby
|
300
301
|
irb(main):001> User.all
|
301
|
-
=> [#<User:0x000000010c239a30 @email="ok@ok.com", @id=1, @password="password">]
|
302
|
+
=> [#<User:0x000000010c239a30 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">]
|
302
303
|
```
|
303
304
|
Find by id
|
304
305
|
```Ruby
|
305
306
|
irb(main):002> user = User.find 1
|
306
|
-
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password">
|
307
|
+
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
307
308
|
```
|
308
309
|
|
309
310
|
Get last record
|
310
311
|
```Ruby
|
311
312
|
irb(main):003> User.last
|
312
|
-
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password">
|
313
|
+
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
313
314
|
```
|
314
315
|
|
315
316
|
Create new persited record
|
316
317
|
```Ruby
|
317
318
|
irb(main):004> User.create(email: "ok23@ok.com", password: 123)
|
318
|
-
=> #<User:0x000000010c393818 @email="ok23@ok.com", @id=2, @password=123>
|
319
|
+
=> #<User:0x000000010c393818 @email="ok23@ok.com", @id=2, @password=123, @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
319
320
|
```
|
320
321
|
|
321
322
|
Destroy record and all related records
|
@@ -327,7 +328,7 @@ irb(main):021> user.destroy(cascade: true)
|
|
327
328
|
Destroy all records one by one
|
328
329
|
```Ruby
|
329
330
|
irb(main):022> User.destroy_all
|
330
|
-
=> [#<User:0x000000010d42df98 @email="ok@ok.com", @id=1, @password="password">, #<User:0x000000010d42de80 @email="ok23@ok.com", @id=2, @password="123"
|
331
|
+
=> [#<User:0x000000010d42df98 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">, #<User:0x000000010d42de80 @email="ok23@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">>
|
331
332
|
irb(main):023> User.all
|
332
333
|
=> []
|
333
334
|
```
|
@@ -336,19 +337,19 @@ Use complex queries chains and when ready serialize it back to Rubee object.
|
|
336
337
|
```Ruby
|
337
338
|
# user model
|
338
339
|
class User < Rubee::SequelObject
|
339
|
-
attr_accessor :id, :email, :password
|
340
|
+
attr_accessor :id, :email, :password, :created, :updated
|
340
341
|
owns_many :comments, over: :posts
|
341
342
|
end
|
342
343
|
|
343
344
|
# comment model
|
344
345
|
class Comment < Rubee::SequelObject
|
345
|
-
attr_accessor :id, :text, :user_id
|
346
|
+
attr_accessor :id, :text, :user_id, :created, :updated
|
346
347
|
owns_many :users, over: :posts
|
347
348
|
end
|
348
349
|
|
349
|
-
# join post
|
350
|
+
# join post modenl
|
350
351
|
class Post < Rubee::SequelObject
|
351
|
-
attr_accessor :id, :user_id, :comment_id
|
352
|
+
attr_accessor :id, :user_id, :comment_id, :created, :updated
|
352
353
|
holds :comment
|
353
354
|
holds :user
|
354
355
|
end
|
@@ -363,11 +364,11 @@ irb(main):005> post = Post.new(user_id: user.id, comment_id: comment.id)
|
|
363
364
|
irb(main):006> post.save
|
364
365
|
=> true
|
365
366
|
irb(main):007> comment
|
366
|
-
=> #<Comment:0x000000012281a650 @id=21, @text="test">
|
367
|
+
=> #<Comment:0x000000012281a650 @id=21, @text="test", @created=2025-09-28 22:03:07.011332 -0400, @updated=2025-09-28 22:03:07.011332 -0400>
|
367
368
|
irb(main):008> result = Comment.dataset.join(:posts, comment_id: :id)
|
368
369
|
irb(main):009> .where(comment_id: Comment.where(text: "test").last.id)
|
369
370
|
irb(main):010> .then { |dataset| Comment.serialize(dataset) }
|
370
|
-
=> [#<Comment:0x0000000121889998 @id=30, @text="test", @user_id=702>]
|
371
|
+
=> [#<Comment:0x0000000121889998 @id=30, @text="test", @user_id=702, @created=2025-09-28 22:03:07.011332 -0400, @updated=2025-09-28 22:03:07.011332 -0400>]
|
371
372
|
```
|
372
373
|
This is recommended when you want to run one query and serialize it back to Rubee object only once.
|
373
374
|
So it may safe some resources.
|
@@ -433,7 +434,9 @@ Rubee::Router.draw do |router|
|
|
433
434
|
attributes: [
|
434
435
|
{ name: 'id', type: :primary },
|
435
436
|
{ name: 'colour', type: :string },
|
436
|
-
{ name: 'weight', type: :integer }
|
437
|
+
{ name: 'weight', type: :integer },
|
438
|
+
{ name: 'created', type: :datetime },
|
439
|
+
{ name: 'updated', type: :datetime },
|
437
440
|
]
|
438
441
|
}
|
439
442
|
end
|
@@ -528,7 +531,9 @@ Rubee::Router.draw do |router|
|
|
528
531
|
attributes: [
|
529
532
|
{ name: 'id', type: :primary },
|
530
533
|
{ name: 'colour', type: :string },
|
531
|
-
{ name: 'weight', type: :integer }
|
534
|
+
{ name: 'weight', type: :integer },
|
535
|
+
{ name: 'created', type: :datetime },
|
536
|
+
{ name: 'updated', type: :datetime },
|
532
537
|
]
|
533
538
|
}
|
534
539
|
end
|
@@ -572,7 +577,9 @@ Rubee::Router.draw do |router|
|
|
572
577
|
name: 'cabage',
|
573
578
|
attributes: [
|
574
579
|
{ name: 'id', type: :primary },
|
575
|
-
{ name: 'name', type: :string }
|
580
|
+
{ name: 'name', type: :string },
|
581
|
+
{ name: 'created', type: :datetime },
|
582
|
+
{ name: 'updated', type: :datetime },
|
576
583
|
]
|
577
584
|
},
|
578
585
|
namespace: :admin # mandatory option for supporting namespacing
|
@@ -698,6 +705,9 @@ So that will ensure all cahnges applying instantly.
|
|
698
705
|
|
699
706
|
6. You can generate react view from the route by indicating the view name explicitly
|
700
707
|
|
708
|
+
7. Do not forget to rebuild react app in production by running `rubee react build`. This is unnecessary in development,
|
709
|
+
when you use `rubee react watch` tho. So it does rebuild automatically.
|
710
|
+
|
701
711
|
```ruby
|
702
712
|
# config/routes.rb
|
703
713
|
Rubee::Router.draw do |router|
|
@@ -1025,15 +1035,16 @@ When you trigger the controller action, the logs will look like this:
|
|
1025
1035
|
|
1026
1036
|
[Back to content](#content)
|
1027
1037
|
|
1028
|
-
</details>
|
1029
|
-
|
1030
1038
|
### Contributing
|
1031
1039
|
|
1032
1040
|
If you are interested in contributing to RUBEE,
|
1033
|
-
please read the [Contributing](https://github.com/nucleom42/rubee/blob/main/
|
1041
|
+
please read the [Contributing]()https://github.com/nucleom42/rubee/blob/main/contribution.md) guide.
|
1034
1042
|
Also feel free to open an [issue](https://github.com/nucleom42/rubee/issues) if you apot one.
|
1035
1043
|
Have an idea or you wnat to discuss something?
|
1036
1044
|
Please open a [discussion](https://github.com/nucleom42/rubee/discussions)
|
1037
1045
|
|
1046
|
+
## Roadmap
|
1047
|
+
Please refer the [Roadmap](https://github.com/nucleom42/rubee/blob/main/roadmap.md)
|
1048
|
+
|
1038
1049
|
## License
|
1039
1050
|
This project is released under the [MIT License](https://github.com/nucleom42/rubee/blob/main/LICENSE).
|
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.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Saltykov
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/app/views/apples_.erb
|
48
48
|
- lib/app/views/index.html
|
49
49
|
- lib/app/views/layout.erb
|
50
|
+
- lib/app/views/s_.erb
|
50
51
|
- lib/app/views/utils/redirectToBackend.tsx
|
51
52
|
- lib/app/views/welcome_header.erb
|
52
53
|
- lib/app/views/welcome_show.erb
|