ru.Bee 1.5.3 → 1.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2d3eeef6e3b96839595387ebc209aac312e5d9b5d7759f677242d7e615bdb17
4
- data.tar.gz: 13186d7aef77fb4e1c8c4dd173798c61be2eee5e07bee4280b37cb4f060943b8
3
+ metadata.gz: eb5cbb674c5bfbfd6bc0d577039a3ca53fb46f013b62e5e004ef4a9f2c500514
4
+ data.tar.gz: abd0447b9655b22a85fed893e74c524f97d2d0ecf757eeb3b1730c799ae0e3d4
5
5
  SHA512:
6
- metadata.gz: 3c335127b4999f214b181bdc8e970a969be1b8f54e3ec091184b300cd996f5705bd110f33aab364947af25c61e35b38fcbca39aadbc433bf2721bb69aee5d88a
7
- data.tar.gz: 45c05634109187a1a3b7cd107584e8906024c8ee7e5f295c2f420441a53d112cd6bb3d1ef876385388caa1c86dd5aeeb89456cb43a96a718105cadfea951cb34
6
+ metadata.gz: 53195541a6b75bb6bf98ff8e8d54cc6d9fea4c5a8d5232f79c0e5cbe085b0afa48e06e17e717a314fb44fbac92c6ae375e18cbc8f4cc2aba8152fec568c59545
7
+ data.tar.gz: 193de59c021b3ca2265e816f6c80fc54a0b714c37f02b59194a4dafb6d01b1bc2edf9180d0c932d8a9b2d4dc23954b052926874a691f0a1aaedfbc5870906c34
data/bin/rubee CHANGED
@@ -60,8 +60,8 @@ elsif command == 'react'
60
60
  exec('npm run watch')
61
61
  end
62
62
  else
63
- color_puts "Unknown command: #{command}", color: :red
64
- exit 1
63
+ color_puts("Unknown command: #{command}", color: :red)
64
+ exit(1)
65
65
  end
66
66
  elsif command == 'project'
67
67
  project_name = ARGV[1]
@@ -1,5 +1,6 @@
1
1
  Rubee::Configuration.setup(env = :development) do |config|
2
2
  config.database_url = { url: 'sqlite://db/development.db', env: }
3
+ config.thread_pool_limit = { env:, value: 5 }
3
4
 
4
5
  # Uncomment, if you want to use react
5
6
  # config.react = { on: true, env: }
@@ -7,6 +8,7 @@ end
7
8
 
8
9
  Rubee::Configuration.setup(env = :test) do |config|
9
10
  config.database_url = { url: 'sqlite://db/test.db', env: }
11
+ config.thread_pool_limit = { env:, value: 5 }
10
12
 
11
13
  # Uncomment, if you want to use react
12
14
  # config.react = { on: true, env: } # required if you want to use react
@@ -14,6 +16,7 @@ end
14
16
 
15
17
  Rubee::Configuration.setup(env = :production) do |config|
16
18
  config.database_url = { url: 'sqlite://db/production.db', env: }
19
+ config.thread_pool_limit = { env:, value: 5 }
17
20
 
18
21
  # Uncomment,if you want to use react
19
22
  # config.react = { on: true, env: } # required if you want to use react
data/lib/config/routes.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  Rubee::Router.draw do |router|
2
2
  router.get('/', to: 'welcome#show') # override it for your app
3
3
  end
4
-
@@ -1,9 +1,9 @@
1
1
  module ChargedString
2
2
  refine String do
3
3
  def pluralize
4
- if self.end_with?('y') && !%w[a e i o u].include?(self[-2])
4
+ if end_with?('y') && !%w[a e i o u].include?(self[-2])
5
5
  "#{self[0..-2]}ies" # Replace "y" with "ies"
6
- elsif self.end_with?('s', 'x', 'z', 'ch', 'sh')
6
+ elsif end_with?('s', 'x', 'z', 'ch', 'sh')
7
7
  "#{self}es" # Add "es" for certain endings
8
8
  else
9
9
  "#{self}s" # Default to adding "s"
@@ -11,7 +11,7 @@ module ChargedString
11
11
  end
12
12
 
13
13
  def plural?
14
- return true if self.end_with?('s') && !self.end_with?('ss')
14
+ return true if end_with?('s') && !end_with?('ss')
15
15
 
16
16
  false
17
17
  end
@@ -21,11 +21,11 @@ module ChargedString
21
21
  end
22
22
 
23
23
  def singularize
24
- if self.end_with?('ies') && self.length > 3
24
+ if end_with?('ies') && length > 3
25
25
  "#{self[0..-4]}y" # Convert "ies" to "y"
26
- elsif self.end_with?('es') && %w[s x z ch sh].any? { |ending| self[-(ending.length + 2)..-3] == ending }
26
+ elsif end_with?('es') && %w[s x z ch sh].any? { |ending| self[-(ending.length + 2)..-3] == ending }
27
27
  self[0..-3] # Remove "es" for selfs like "foxes", "buses"
28
- elsif self.end_with?('s') && self.length > 1
28
+ elsif end_with?('s') && length > 1
29
29
  self[0..-2] # Remove "s" for regular plurals
30
30
  else
31
31
  self # Return as-is if no plural form is detected
@@ -3,50 +3,58 @@ require 'singleton'
3
3
  module Rubee
4
4
  class ThreadPool
5
5
  include Singleton
6
- THREADS_LIMIT = 4 # adjust as needed
6
+ THREAD_POOL_LIMIT = Rubee::Configuration.get_thread_pool_limit || 10 # adjust as needed
7
7
 
8
8
  def initialize
9
9
  @queue = Queue.new
10
10
  @workers = []
11
11
  @running = true
12
- @mutex = Mutex.new
13
12
  spawn_workers
14
13
  end
15
14
 
16
15
  def enqueue(task, args)
17
16
  @queue << { task: task, args: args }
17
+ run_next
18
18
  end
19
19
 
20
20
  def bulk_enqueue(tasks)
21
21
  @queue << tasks
22
+ run_next
22
23
  end
23
24
 
24
25
  def shutdown
25
26
  @running = false
26
- THREADS_LIMIT.times { @queue << { task: :stop, args: nil } }
27
- @workers.each(&:join)
27
+ @queue.clear
28
28
  end
29
29
 
30
30
  private
31
31
 
32
+ def run_next
33
+ @workers.each do |fiber|
34
+ fiber.resume if fiber.alive? && !@queue.empty?
35
+ end
36
+ end
37
+
32
38
  def spawn_workers
33
- THREADS_LIMIT.times do
34
- @workers << Thread.new do
35
- while @running
36
- task_hash = @mutex.synchronize { @queue.pop }
37
- if task_hash
38
- task = task_hash[:task]
39
- args = task_hash[:args]
40
- end
41
- break if task == :stop
39
+ THREAD_POOL_LIMIT.times do
40
+ fiber = Fiber.new do
41
+ loop do
42
+ Fiber.yield unless @running
43
+ job = @queue.shift
44
+ break unless job
45
+
46
+ task = job[:task]
47
+ args = job[:args]
42
48
 
43
49
  begin
44
50
  task.new.perform(**args)
45
- rescue StandardError => e
51
+ rescue => e
46
52
  puts "ThreadPool Error: #{e.message}"
47
53
  end
48
54
  end
49
55
  end
56
+
57
+ @workers << fiber
50
58
  end
51
59
  end
52
60
  end
@@ -70,6 +70,10 @@ module Rubee
70
70
  nil
71
71
  end
72
72
 
73
+ def count
74
+ dataset.count
75
+ end
76
+
73
77
  def first
74
78
  found_hash = dataset.order(:id).first
75
79
  return new(**found_hash) if found_hash
data/lib/rubee.rb CHANGED
@@ -15,7 +15,7 @@ module Rubee
15
15
  IMAGE_DIR = File.join(APP_ROOT, LIB, 'images') unless defined?(IMAGE_DIR)
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
- VERSION = '1.5.3'
18
+ VERSION = '1.5.4'
19
19
 
20
20
  class Application
21
21
  include Singleton
@@ -80,6 +80,10 @@ module Rubee
80
80
  @configuraiton[args[:env].to_sym][:async_adapter] = args[:async_adapter]
81
81
  end
82
82
 
83
+ def thread_pool_limit=(args)
84
+ @configuraiton[args[:env].to_sym][:thread_pool_limit] = args[:thread_pool_limit]
85
+ end
86
+
83
87
  def react=(args)
84
88
  @configuraiton[args[:env].to_sym][:react] ||= { on: false }
85
89
  @configuraiton[args[:env].to_sym][:react].merge!(on: args[:on])
@@ -0,0 +1,32 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestAsyncRunnner
4
+ include Rubee::Asyncable
5
+
6
+ def perform(options)
7
+ User.create(email: options['email'], password: options['password'])
8
+ end
9
+ end
10
+
11
+ describe 'TestAsyncRunnner' do
12
+ describe 'async' do
13
+ after do
14
+ Rubee::ThreadPool.instance.shutdown
15
+ User.destroy_all
16
+ end
17
+
18
+ subject do
19
+ 5.times do |n|
20
+ TestAsyncRunnner.new.perform_async(options: {"email"=> "new#{n}@new.com", "password"=> "123"})
21
+ end
22
+ end
23
+
24
+ it 'creates 5 users' do
25
+ assert_difference(-> { User.count }, 5) { subject }
26
+ end
27
+
28
+ it 'does it async' do
29
+ # TODO
30
+ end
31
+ end
32
+ 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
@@ -10,3 +10,14 @@ Rubee::Configuration.setup(env = :test) do |config|
10
10
  config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
11
11
  end
12
12
  Rubee::SequelObject.reconnect!
13
+
14
+ def assert_difference(expression, difference = 1)
15
+ before = expression.call
16
+ yield
17
+ after = expression.call
18
+ actual_diff = after - before
19
+
20
+ assert_equal difference, actual_diff,
21
+ "Expected change of #{difference}, but got #{actual_diff}"
22
+ end
23
+
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.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov
@@ -241,6 +241,7 @@ files:
241
241
  - lib/rubee/models/database_objectable.rb
242
242
  - lib/rubee/models/sequel_object.rb
243
243
  - lib/tests/account_model_test.rb
244
+ - lib/tests/async/thread_async_test.rb
244
245
  - lib/tests/auth_tokenable_test.rb
245
246
  - lib/tests/comment_model_test.rb
246
247
  - lib/tests/example_models/account.rb