ru.Bee 1.5.3 → 1.6.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rubee +9 -4
  3. data/lib/config/base_configuration.rb +25 -4
  4. data/lib/config/routes.rb +0 -1
  5. data/lib/db/create_addresses.rb +17 -0
  6. data/lib/inits/charged_string.rb +6 -6
  7. data/lib/package.json +1 -1
  8. data/lib/rubee/async/fiber_queue.rb +27 -0
  9. data/lib/rubee/async/thread_pool.rb +28 -22
  10. data/lib/rubee/autoload.rb +73 -0
  11. data/lib/rubee/configuration.rb +60 -0
  12. data/lib/rubee/extensions/hookable.rb +9 -2
  13. data/lib/rubee/generator.rb +152 -0
  14. data/lib/rubee/logger.rb +83 -0
  15. data/lib/rubee/models/sequel_object.rb +5 -2
  16. data/lib/rubee/router.rb +41 -0
  17. data/lib/rubee.rb +7 -310
  18. data/lib/tests/async/thread_async_test.rb +36 -0
  19. data/lib/tests/{auth_tokenable_test.rb → controllers/auth_tokenable_test.rb} +2 -2
  20. data/lib/tests/controllers/base_controller_test.rb +23 -0
  21. data/lib/tests/controllers/hookable_test.rb +220 -0
  22. data/lib/tests/{rubeeapp_test.rb → controllers/rubeeapp_test.rb} +2 -1
  23. data/lib/tests/example_models/address.rb +5 -0
  24. data/lib/tests/example_models/user.rb +1 -0
  25. data/lib/tests/logger_test.rb +76 -0
  26. data/lib/tests/{account_model_test.rb → models/account_model_test.rb} +1 -1
  27. data/lib/tests/{comment_model_test.rb → models/comment_model_test.rb} +13 -1
  28. data/lib/tests/models/db_objectable_test.rb +21 -0
  29. data/lib/tests/models/seralizable_test.rb +36 -0
  30. data/lib/tests/{user_model_test.rb → models/user_model_test.rb} +32 -1
  31. data/lib/tests/rubee_generator_test.rb +66 -62
  32. data/lib/tests/test.db +0 -0
  33. data/lib/tests/test_helper.rb +28 -0
  34. data/readme.md +77 -11
  35. metadata +20 -8
  36. data/lib/app/views/apples_.erb +0 -1
  37. data/lib/app/views/s_.erb +0 -1
@@ -2,4 +2,5 @@ class User < Rubee::SequelObject
2
2
  attr_accessor :id, :email, :password
3
3
 
4
4
  owns_many :accounts, cascade: true
5
+ owns_one :address, cascade: true
5
6
  end
@@ -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 'Account model' do
4
4
  describe 'holds :user' do
@@ -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
@@ -37,92 +37,95 @@ describe 'Rubee::Generator' do
37
37
  generator = Rubee::Generator.new(nil, nil, nil, nil)
38
38
  generator.call
39
39
 
40
- _(File.exist?('lib/db/create_apples.rb')).must_equal false
40
+ _(File.exist?('lib/db/create_apples.rb')).must_equal(false)
41
41
  end
42
42
 
43
43
  it 'with a model only' do
44
44
  generator = Rubee::Generator.new('apple', nil, 'apples', nil)
45
45
  generator.call
46
46
 
47
- _(File.exist?('lib/db/create_apples.rb')).must_equal true
47
+ _(File.exist?('lib/db/create_apples.rb')).must_equal(true)
48
48
 
49
49
  lines = File.readlines('lib/db/create_apples.rb').map(&:chomp).join("\n")
50
50
 
51
- _(lines.include?('class CreateApples')).must_equal true
52
- _(lines.include?('def call')).must_equal true
53
- _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal true
54
- _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal true
55
- _(lines.include?('String')).must_equal false
56
- _(lines.include?('end')).must_equal true
51
+ _(lines.include?('class CreateApples')).must_equal(true)
52
+ _(lines.include?('def call')).must_equal(true)
53
+ _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal(true)
54
+ _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal(true)
55
+ _(lines.include?('String')).must_equal(false)
56
+ _(lines.include?('end')).must_equal(true)
57
57
  end
58
58
 
59
59
  it 'with a model with attributes' do
60
- generator = Rubee::Generator.new('apple', [{ name: 'title', type: :string }, {name: 'content', type: :text }], 'apples', nil)
60
+ generator = Rubee::Generator.new('apple', [{ name: 'title', type: :string }, { name: 'content', type: :text }],
61
+ 'apples', nil)
61
62
  generator.call
62
63
 
63
- _(File.exist?('lib/db/create_apples.rb')).must_equal true
64
+ _(File.exist?('lib/db/create_apples.rb')).must_equal(true)
64
65
 
65
66
  lines = File.readlines('lib/db/create_apples.rb').map(&:chomp).join("\n")
66
67
 
67
- _(lines.include?('class CreateApples')).must_equal true
68
- _(lines.include?('def call')).must_equal true
69
- _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal true
70
- _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal true
71
- _(lines.include?('String :title')).must_equal true
72
- _(lines.include?('String :content, text: true')).must_equal true
73
- _(lines.include?('end')).must_equal true
68
+ _(lines.include?('class CreateApples')).must_equal(true)
69
+ _(lines.include?('def call')).must_equal(true)
70
+ _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal(true)
71
+ _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal(true)
72
+ _(lines.include?('String :title')).must_equal(true)
73
+ _(lines.include?('String :content, text: true')).must_equal(true)
74
+ _(lines.include?('end')).must_equal(true)
74
75
  end
75
76
 
76
77
  it 'with a model with different attributes' do
77
- generator = Rubee::Generator.new('apple', [{name: 'id', type: :bigint}, {name: 'colour', type: :string }, {name: 'weight', type: :integer }], 'apples', nil)
78
+ generator = Rubee::Generator.new('apple',
79
+ [{ name: 'id', type: :bigint }, { name: 'colour', type: :string }, { name: 'weight', type: :integer }], 'apples', nil)
78
80
  generator.call
79
81
 
80
- _(File.exist?('lib/db/create_apples.rb')).must_equal true
82
+ _(File.exist?('lib/db/create_apples.rb')).must_equal(true)
81
83
 
82
84
  lines = File.readlines('lib/db/create_apples.rb').map(&:chomp).join("\n")
83
85
 
84
- _(lines.include?('class CreateApples')).must_equal true
85
- _(lines.include?('def call')).must_equal true
86
- _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal true
87
- _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal true
88
- _(lines.include?('Bignum :id')).must_equal true
89
- _(lines.include?('String :colour')).must_equal true
90
- _(lines.include?('Integer :weight')).must_equal true
91
- _(lines.include?('end')).must_equal true
86
+ _(lines.include?('class CreateApples')).must_equal(true)
87
+ _(lines.include?('def call')).must_equal(true)
88
+ _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal(true)
89
+ _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal(true)
90
+ _(lines.include?('Bignum :id')).must_equal(true)
91
+ _(lines.include?('String :colour')).must_equal(true)
92
+ _(lines.include?('Integer :weight')).must_equal(true)
93
+ _(lines.include?('end')).must_equal(true)
92
94
  end
93
95
 
94
96
  it 'with a model with an attribute with multiple names' do
95
- generator = Rubee::Generator.new('apple', [{ name: ['blue_id', 'shoe_id'], type: :foreign_key, table: 'blue_and_shoe_join_tb' }], 'apples', nil)
97
+ generator = Rubee::Generator.new('apple',
98
+ [{ name: ['blue_id', 'shoe_id'], type: :foreign_key, table: 'blue_and_shoe_join_tb' }], 'apples', nil)
96
99
  generator.call
97
100
 
98
- _(File.exist?('lib/db/create_apples.rb')).must_equal true
101
+ _(File.exist?('lib/db/create_apples.rb')).must_equal(true)
99
102
 
100
103
  lines = File.readlines('lib/db/create_apples.rb').map(&:chomp).join("\n")
101
104
 
102
- _(lines.include?('class CreateApples')).must_equal true
103
- _(lines.include?('def call')).must_equal true
104
- _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal true
105
- _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal true
106
- _(lines.include?('foreign_key [:blue_id, :shoe_id]')).must_equal true
107
- _(lines.include?(':blue_and_shoe_join_tb')).must_equal true
108
- _(lines.include?('end')).must_equal true
105
+ _(lines.include?('class CreateApples')).must_equal(true)
106
+ _(lines.include?('def call')).must_equal(true)
107
+ _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal(true)
108
+ _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal(true)
109
+ _(lines.include?('foreign_key [:blue_id, :shoe_id]')).must_equal(true)
110
+ _(lines.include?(':blue_and_shoe_join_tb')).must_equal(true)
111
+ _(lines.include?('end')).must_equal(true)
109
112
  end
110
113
 
111
114
  it 'with a model with a foreign_key without table' do
112
115
  generator = Rubee::Generator.new('apple', [{ name: 'blue_id', type: :foreign_key }], 'apples', nil)
113
116
  generator.call
114
117
 
115
- _(File.exist?('lib/db/create_apples.rb')).must_equal true
118
+ _(File.exist?('lib/db/create_apples.rb')).must_equal(true)
116
119
 
117
120
  lines = File.readlines('lib/db/create_apples.rb').map(&:chomp).join("\n")
118
121
 
119
- _(lines.include?('class CreateApples')).must_equal true
120
- _(lines.include?('def call')).must_equal true
121
- _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal true
122
- _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal true
123
- _(lines.include?('foreign_key :blue_id')).must_equal true
124
- _(lines.include?(':replace_with_table_name')).must_equal true
125
- _(lines.include?('end')).must_equal true
122
+ _(lines.include?('class CreateApples')).must_equal(true)
123
+ _(lines.include?('def call')).must_equal(true)
124
+ _(lines.include?('return if Rubee::SequelObject::DB.tables.include?(:apples)')).must_equal(true)
125
+ _(lines.include?('Rubee::SequelObject::DB.create_table(:apples) do')).must_equal(true)
126
+ _(lines.include?('foreign_key :blue_id')).must_equal(true)
127
+ _(lines.include?(':replace_with_table_name')).must_equal(true)
128
+ _(lines.include?('end')).must_equal(true)
126
129
  end
127
130
  end
128
131
 
@@ -136,53 +139,54 @@ describe 'Rubee::Generator' do
136
139
  generator = Rubee::Generator.new(nil, nil, nil, nil)
137
140
  generator.call
138
141
 
139
- _(File.exist?('lib/app/models/apple.rb')).must_equal false
142
+ _(File.exist?('lib/app/models/apple.rb')).must_equal(false)
140
143
  end
141
144
 
142
145
  it 'with a model only' do
143
146
  generator = Rubee::Generator.new('apple', nil, 'apples', nil)
144
147
  generator.call
145
148
 
146
- _(File.exist?('lib/app/models/apple.rb')).must_equal true
149
+ _(File.exist?('lib/app/models/apple.rb')).must_equal(true)
147
150
 
148
151
  lines = File.readlines('lib/app/models/apple.rb').map(&:chomp).join("\n")
149
152
 
150
- _(lines.include?('class Apple < Rubee::SequelObject')).must_equal true
151
- _(lines.include?('attr_accessor')).must_equal false
152
- _(lines.include?('end')).must_equal true
153
+ _(lines.include?('class Apple < Rubee::SequelObject')).must_equal(true)
154
+ _(lines.include?('attr_accessor')).must_equal(false)
155
+ _(lines.include?('end')).must_equal(true)
153
156
  end
154
157
 
155
158
  it 'with a model with attributes' do
156
- generator = Rubee::Generator.new('apple', [{ name: 'title', type: :string }, {name: 'content', type: :text }], 'apples', nil)
159
+ generator = Rubee::Generator.new('apple', [{ name: 'title', type: :string }, { name: 'content', type: :text }],
160
+ 'apples', nil)
157
161
  generator.call
158
162
 
159
- _(File.exist?('lib/app/models/apple.rb')).must_equal true
163
+ _(File.exist?('lib/app/models/apple.rb')).must_equal(true)
160
164
 
161
165
  lines = File.readlines('lib/app/models/apple.rb').map(&:chomp).join("\n")
162
166
 
163
- _(lines.include?('class Apple < Rubee::SequelObject')).must_equal true
164
- _(lines.include?('attr_accessor')).must_equal true
165
- _(lines.include?(':title, :content')).must_equal true
166
- _(lines.include?('end')).must_equal true
167
+ _(lines.include?('class Apple < Rubee::SequelObject')).must_equal(true)
168
+ _(lines.include?('attr_accessor')).must_equal(true)
169
+ _(lines.include?(':title, :content')).must_equal(true)
170
+ _(lines.include?('end')).must_equal(true)
167
171
  end
168
172
 
169
173
  it 'with a model with different attributes' do
170
- generator = Rubee::Generator.new('apple', [{name: 'id', type: :bigInt}, {name: 'colour', type: :string }, {name: 'weight', type: :integer }], 'apples', nil)
174
+ generator = Rubee::Generator.new('apple',
175
+ [{ name: 'id', type: :bigInt }, { name: 'colour', type: :string }, { name: 'weight', type: :integer }], 'apples', nil)
171
176
  generator.call
172
177
 
173
- _(File.exist?('lib/app/models/apple.rb')).must_equal true
178
+ _(File.exist?('lib/app/models/apple.rb')).must_equal(true)
174
179
 
175
180
  lines = File.readlines('lib/app/models/apple.rb').map(&:chomp).join("\n")
176
181
 
177
- _(lines.include?('class Apple < Rubee::SequelObject')).must_equal true
178
- _(lines.include?('attr_accessor')).must_equal true
179
- _(lines.include?(':id, :colour, :weight')).must_equal true
180
- _(lines.include?('end')).must_equal true
182
+ _(lines.include?('class Apple < Rubee::SequelObject')).must_equal(true)
183
+ _(lines.include?('attr_accessor')).must_equal(true)
184
+ _(lines.include?(':id, :colour, :weight')).must_equal(true)
185
+ _(lines.include?('end')).must_equal(true)
181
186
  end
182
187
  end
183
188
 
184
189
  describe 'generates View file' do
185
-
186
190
  end
187
191
 
188
192
  describe 'generates Controller file' do
data/lib/tests/test.db CHANGED
Binary file
@@ -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
@@ -10,3 +19,22 @@ Rubee::Configuration.setup(env = :test) do |config|
10
19
  config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
11
20
  end
12
21
  Rubee::SequelObject.reconnect!
22
+
23
+ def assert_difference(expression, difference = 1)
24
+ before = expression.call
25
+ yield
26
+ after = expression.call
27
+ actual_diff = after - before
28
+
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
40
+ end
data/readme.md CHANGED
@@ -18,6 +18,25 @@ Want to get a quick API server up and runing? You can do it for real quick!
18
18
 
19
19
  All greaet features are yet to come!
20
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)
39
+
21
40
  ## Features
22
41
 
23
42
  - **Lightweight**: A minimal footprint that focuses on serving Ruby applications efficiently.
@@ -33,6 +52,8 @@ All greaet features are yet to come!
33
52
  - **Hooks** Addlogic before, after and around any action.
34
53
  - **Test** Run all or selected tests witin minitest.
35
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
36
57
 
37
58
  ## Installation
38
59
 
@@ -65,12 +86,12 @@ rubee start
65
86
 
66
87
  5. Open your browser and go to http://localhost:7000
67
88
 
68
- ## Run the tests
89
+ ## Run tests
69
90
  ```bash
70
91
  rubee test
71
92
  ```
72
93
 
73
- ## Create API contract and generate files from the routes
94
+ ## Draw contract
74
95
  1. Add the routes to the routes.rb
75
96
  ```ruby
76
97
  Rubee::Router.draw do |router|
@@ -88,21 +109,21 @@ rubee test
88
109
  end
89
110
  ```
90
111
  2. generate the files
91
- ```bash
112
+ ```bash
92
113
  rubee generate get /apples
93
- ```
94
- - This will generate the following files
95
- ```bash
114
+ ```
115
+ This will generate the following files
116
+ ```bash
96
117
  ./app/controllers/apples_controller.rb # Controller with respective action
97
118
  ./app/views/apples_index.erb # ERB view that is rendered by the controller right away
98
119
  ./app/models/apple.rb # Model that acts as ORM
99
120
  ./db/create_apples.rb # Database migration file needed for creating repsective table
100
- ```
121
+ ```
101
122
 
102
123
  3. Run the initial db migration
103
124
  ```bash
104
125
  rubee db run:all
105
- ```
126
+ ```
106
127
 
107
128
  5. Fill the generated files with the logic you need and run the server again!
108
129
 
@@ -395,9 +416,9 @@ Example 3:
395
416
  Rubee::Router.draw do |router|
396
417
  ...
397
418
  # draw the contract
398
- router.get "/apples", to: "apples#index",
399
- model: {
400
- name: 'apple',
419
+ router.get "/apples", to: "apples#index",
420
+ model: {
421
+ name: 'apple',
401
422
  attributes: [
402
423
  { name: 'id', type: :primary },
403
424
  { name: 'colour', type: :string },
@@ -755,6 +776,51 @@ end
755
776
 
756
777
  TestAsyncRunnner.new.perform_async(options: {"email"=> "new@new.com", "password"=> "123"})
757
778
  ```
779
+ ### Logger
780
+
781
+ You can use your own logger by setting it in the /config/base_configuration.rb.
782
+
783
+ ```ruby
784
+ # config/base_configuration.rb
785
+ Rubee::Configuration.setup(env=:development) do |config|
786
+ config.database_url = { url: "sqlite://db/development.db", env: }
787
+ config.logger = { logger: MyLogger, env: }
788
+ end
789
+ ```
790
+
791
+ Or you can use the default logger.
792
+ Let's consider example with welcome controller and around hook:
793
+ ```ruby
794
+ # app/controllers/welcome_controller.rb
795
+ class WelcomeController < Rubee::BaseController
796
+ around :show, ->(&target_method) do
797
+ start = Time.now
798
+ Rubee::Logger.warn(message: 'This is a warning message', method: :show, class_name: 'WelcomeController')
799
+ Rubee::Logger.error(message: 'This is a warning message', class_name: 'WelcomeController')
800
+ Rubee::Logger.critical(message: 'We are on fire!')
801
+ target_method.call
802
+ Rubee::Logger.info(
803
+ message: "Execution Time: #{Time.now - start} seconds",
804
+ method: :show,
805
+ class_name: 'WelcomeController'
806
+ )
807
+ Rubee::Logger.debug(object: User.last, method: :show, class_name: 'WelcomeController')
808
+ end
809
+
810
+ def show
811
+ response_with
812
+ end
813
+ end
814
+ ```
815
+ When you trigger the controller action, the logs will look like this:
816
+
817
+ ```bash
818
+ [2025-04-26 12:32:33] WARN [method: show][class_name: WelcomeController] This is a warning message
819
+ [2025-04-26 12:32:33] ERROR [class_name: WelcomeController] This is a warning message
820
+ [2025-04-26 12:32:33] CRITICAL We are on fire!
821
+ [2025-04-26 12:32:33] INFO [method: show][class_name: WelcomeController] Execution Time: 0.000655 seconds
822
+ [2025-04-26 12:32:33] DEBUG [method: show][class_name: WelcomeController] #<User:0x000000012c5c63e0 @id=4545, @email="ok@op.com", @password="123">
823
+ ```
758
824
 
759
825
  ### Contributing
760
826