ru.Bee 2.2.8 → 2.3.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/db/create_carrots.rb +13 -0
- data/lib/rubee/autoload.rb +5 -2
- data/lib/rubee/extensions/validatable.rb +7 -1
- data/lib/rubee/models/database_objectable.rb +3 -0
- data/lib/rubee/models/sequel_object.rb +10 -2
- data/lib/rubee.rb +1 -1
- data/lib/tests/example_models/carrots.rb +3 -0
- data/lib/tests/models/carrot_model_test.rb +11 -0
- data/lib/tests/models/comment_model_test.rb +18 -0
- data/lib/tests/test.db +0 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e0cf8da8114b03f7ab38bfb0994fcd93b353f0bffc01c3a38689a28ea1daf15
|
|
4
|
+
data.tar.gz: c650fc422ef9d764e63e683819580cf1faea6daf84ee8d761ebb6199cf0b2546
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd1f34ec5f2335781075b39fe477bf9bc9c98d8f3ba33aad9decb50a58b9202ce54507a8ba36b172625011bac20b87bb9cb022e683555292c5cca2e58ef427b0
|
|
7
|
+
data.tar.gz: 056b9e3ddf0aa83c76f5efe50dd32c0e93fe2b06fdce7474ee08e2a4e77d10c10c598ed5ebb777148ebc523ff167576a6ac89837861465a8cdd1b5aa2c48ffd6
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class CreateCarrots
|
|
2
|
+
def call
|
|
3
|
+
return if Rubee::SequelObject::DB.tables.include?(:carrots)
|
|
4
|
+
|
|
5
|
+
Rubee::SequelObject::DB.create_table(:carrots) do
|
|
6
|
+
primary_key(:id)
|
|
7
|
+
String(:color, null: false)
|
|
8
|
+
# timestamps
|
|
9
|
+
datetime(:created)
|
|
10
|
+
datetime(:updated)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/rubee/autoload.rb
CHANGED
|
@@ -7,9 +7,9 @@ module Rubee
|
|
|
7
7
|
# autoload all rbs
|
|
8
8
|
root_directory = File.join(Rubee::ROOT_PATH, '/lib')
|
|
9
9
|
priority_order_require(root_directory, black_list)
|
|
10
|
+
load_inits(root_directory, black_list)
|
|
10
11
|
# ensure sequel object is connected
|
|
11
12
|
Rubee::SequelObject.reconnect!
|
|
12
|
-
|
|
13
13
|
Dir.glob(File.join(Rubee::APP_ROOT, '**', '*.rb')).sort.each do |file|
|
|
14
14
|
base_name = File.basename(file)
|
|
15
15
|
|
|
@@ -27,7 +27,7 @@ module Rubee
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def
|
|
30
|
+
def load_inits(root_directory, black_list)
|
|
31
31
|
# rubee inits
|
|
32
32
|
Dir[File.join(root_directory, 'inits/**', '*.rb')].each do |file|
|
|
33
33
|
require_relative file unless black_list.include?("#{file}.rb")
|
|
@@ -36,6 +36,9 @@ module Rubee
|
|
|
36
36
|
Dir[File.join(Rubee::APP_ROOT, 'inits/**', '*.rb')].each do |file|
|
|
37
37
|
require_relative file unless black_list.include?("#{file}.rb")
|
|
38
38
|
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def priority_order_require(root_directory, black_list)
|
|
39
42
|
# rubee pub sub
|
|
40
43
|
Dir[File.join(root_directory, 'rubee/pubsub/**', '*.rb')].each do |file|
|
|
41
44
|
require_relative file unless black_list.include?("#{file}.rb")
|
|
@@ -125,7 +125,6 @@ module Rubee
|
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
def errors
|
|
128
|
-
run_validations
|
|
129
128
|
@__validation_state.errors
|
|
130
129
|
end
|
|
131
130
|
|
|
@@ -164,6 +163,13 @@ module Rubee
|
|
|
164
163
|
def validate(&block)
|
|
165
164
|
@validation_block = block
|
|
166
165
|
end
|
|
166
|
+
|
|
167
|
+
def validate_after_setters
|
|
168
|
+
unless respond_to?(:after)
|
|
169
|
+
raise "Can't use validate_after_setters without after hook, please include Rubee::Hookable"
|
|
170
|
+
end
|
|
171
|
+
after(*accessor_names.filter { |name| !name.start_with?("__") }.map { |name| "#{name}=" }, :run_validations)
|
|
172
|
+
end
|
|
167
173
|
end
|
|
168
174
|
end
|
|
169
175
|
end
|
|
@@ -28,13 +28,15 @@ module Rubee
|
|
|
28
28
|
begin
|
|
29
29
|
update(args)
|
|
30
30
|
rescue StandardError => _e
|
|
31
|
+
add_error(:base, sequel_error: e.message)
|
|
31
32
|
return false
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
else
|
|
35
36
|
begin
|
|
36
37
|
created_id = self.class.dataset.insert(args)
|
|
37
|
-
rescue StandardError =>
|
|
38
|
+
rescue StandardError => e
|
|
39
|
+
add_error(:base, sequel_error: e.message)
|
|
38
40
|
return false
|
|
39
41
|
end
|
|
40
42
|
self.id = created_id
|
|
@@ -169,8 +171,14 @@ module Rubee
|
|
|
169
171
|
|
|
170
172
|
def dataset
|
|
171
173
|
@dataset ||= DB[pluralize_class_name.to_sym]
|
|
172
|
-
rescue Exception =>
|
|
174
|
+
rescue Exception => e
|
|
173
175
|
reconnect!
|
|
176
|
+
@__reconnect_count ||= 0
|
|
177
|
+
@__reconnect_count += 1
|
|
178
|
+
if @__reconnect_count > 3
|
|
179
|
+
raise e
|
|
180
|
+
end
|
|
181
|
+
sleep(0.1)
|
|
174
182
|
retry
|
|
175
183
|
end
|
|
176
184
|
|
data/lib/rubee.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Rubee
|
|
|
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
19
|
|
|
20
|
-
VERSION = '2.
|
|
20
|
+
VERSION = '2.3.1'
|
|
21
21
|
|
|
22
22
|
require_relative 'rubee/router'
|
|
23
23
|
require_relative 'rubee/logger'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require_relative '../test_helper'
|
|
2
|
+
|
|
3
|
+
describe 'When sequle raise error' do
|
|
4
|
+
it 'should save error' do
|
|
5
|
+
apple = Carrot.new(updated: Time.now)
|
|
6
|
+
apple.save
|
|
7
|
+
_(apple.errors).must_equal(
|
|
8
|
+
{ base: { sequel_error: "SQLite3::ConstraintException: NOT NULL constraint failed: carrots.color" } }
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -222,5 +222,23 @@ describe 'Comment model' do
|
|
|
222
222
|
_(comment.errors[:text]).must_equal({ message: "Text is a mandatory field" })
|
|
223
223
|
end
|
|
224
224
|
end
|
|
225
|
+
|
|
226
|
+
describe 'when validate_after_setters' do
|
|
227
|
+
it 'validates attribute' do
|
|
228
|
+
Comment.validate_after_setters
|
|
229
|
+
Comment.validate do
|
|
230
|
+
attribute(:text)
|
|
231
|
+
.required("Text is a mandatory field").type(String, "Text must be a string")
|
|
232
|
+
.condition(-> { text.length > 4 }, "Text length must be greater than 4")
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
comment = Comment.new(text: 'testqwe')
|
|
236
|
+
_(comment.valid?).must_equal(true)
|
|
237
|
+
comment.text = 'test'
|
|
238
|
+
|
|
239
|
+
_(comment.errors.empty?).must_equal(false)
|
|
240
|
+
_(comment.errors[:text]).must_equal({ message: "Text length must be greater than 4" })
|
|
241
|
+
end
|
|
242
|
+
end
|
|
225
243
|
end
|
|
226
244
|
end
|
data/lib/tests/test.db
CHANGED
|
Binary file
|
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: 2.
|
|
4
|
+
version: 2.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oleg Saltykov
|
|
@@ -58,6 +58,7 @@ files:
|
|
|
58
58
|
- lib/css/app.css
|
|
59
59
|
- lib/db/create_accounts.rb
|
|
60
60
|
- lib/db/create_addresses.rb
|
|
61
|
+
- lib/db/create_carrots.rb
|
|
61
62
|
- lib/db/create_clients.rb
|
|
62
63
|
- lib/db/create_comments.rb
|
|
63
64
|
- lib/db/create_posts.rb
|
|
@@ -281,12 +282,14 @@ files:
|
|
|
281
282
|
- lib/tests/controllers/users_controller_test.rb
|
|
282
283
|
- lib/tests/example_models/account.rb
|
|
283
284
|
- lib/tests/example_models/address.rb
|
|
285
|
+
- lib/tests/example_models/carrots.rb
|
|
284
286
|
- lib/tests/example_models/client.rb
|
|
285
287
|
- lib/tests/example_models/comment.rb
|
|
286
288
|
- lib/tests/example_models/post.rb
|
|
287
289
|
- lib/tests/example_models/user.rb
|
|
288
290
|
- lib/tests/logger_test.rb
|
|
289
291
|
- lib/tests/models/account_model_test.rb
|
|
292
|
+
- lib/tests/models/carrot_model_test.rb
|
|
290
293
|
- lib/tests/models/comment_model_test.rb
|
|
291
294
|
- lib/tests/models/db_objectable_test.rb
|
|
292
295
|
- lib/tests/models/seralizable_test.rb
|