ru.Bee 2.7.5 → 2.7.6
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/test.db +0 -0
- data/lib/rubee/cli/db.rb +2 -2
- data/lib/rubee/configuration.rb +14 -2
- data/lib/rubee/generator.rb +2 -1
- data/lib/rubee.rb +1 -1
- data/lib/tests/rubee_generator_test.rb +40 -17
- data/readme.md +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da085a4e506cc4a205ced1b110f39c7992e0fa01b92d58efae763d03fc81e881
|
|
4
|
+
data.tar.gz: 38c1eb9ccd114bcc29c0c3f16b6759edbaf1306c77fd4595a93dbaa762c58f58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31a67bb08b61d35a35fc84d16d27089a2f0512d3003e96f642ad48718e5433c94c7e6e81af275f3d4134cc5020f97d9882fd8f2f938a806c9787e1c540bfe676
|
|
7
|
+
data.tar.gz: baddb5e3958fec54182f1c2a177631231258da5bf6a45c920d8cb87e3c592abe5c029ffa5963901080d2f0d4d47397520c3f8a95ba77cad58a67caeedba27a30
|
data/lib/db/test.db
CHANGED
|
Binary file
|
data/lib/rubee/cli/db.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Rubee
|
|
|
12
12
|
_, file_name = argv[1]&.split(':')
|
|
13
13
|
file_names = if file_name == 'all'
|
|
14
14
|
lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
|
|
15
|
-
Dir.glob(".#{lib}/db/*.rb").map do |file|
|
|
15
|
+
Dir.glob(".#{lib}/db/*.rb").sort.map do |file|
|
|
16
16
|
File.basename(file, '.rb')
|
|
17
17
|
end.reject { |file| file == 'structure' }
|
|
18
18
|
else
|
|
@@ -20,7 +20,7 @@ module Rubee
|
|
|
20
20
|
end
|
|
21
21
|
file_names.each do |file|
|
|
22
22
|
color_puts("Run #{file} file for #{ENV['RACK_ENV']} env", color: :cyan)
|
|
23
|
-
Object.const_get(file.split('_').map(&:capitalize).join).new.call
|
|
23
|
+
Object.const_get(file.gsub(/^\d+_/, '').split('_').map(&:capitalize).join).new.call
|
|
24
24
|
end
|
|
25
25
|
color_puts("Migration for #{file_name} completed", color: :green)
|
|
26
26
|
unless Rubee::PROJECT_NAME == 'rubee'
|
data/lib/rubee/configuration.rb
CHANGED
|
@@ -17,6 +17,10 @@ module Rubee
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
class << self
|
|
20
|
+
def env
|
|
21
|
+
ENV['RACK_ENV']
|
|
22
|
+
end
|
|
23
|
+
|
|
20
24
|
def setup(env, app = :app)
|
|
21
25
|
unless @configuraiton[app.to_sym]
|
|
22
26
|
@configuraiton[app.to_sym] = {
|
|
@@ -29,6 +33,14 @@ module Rubee
|
|
|
29
33
|
end
|
|
30
34
|
end
|
|
31
35
|
|
|
36
|
+
envs.each do |envi|
|
|
37
|
+
next if respond_to? "#{envi}?"
|
|
38
|
+
|
|
39
|
+
define_singleton_method "#{envi}?" do
|
|
40
|
+
envi.to_s == ENV['RACK_ENV']
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
32
44
|
yield(self)
|
|
33
45
|
end
|
|
34
46
|
|
|
@@ -129,8 +141,8 @@ module Rubee
|
|
|
129
141
|
&.[](method_name.to_s.delete_prefix('get_').to_sym)
|
|
130
142
|
end
|
|
131
143
|
|
|
132
|
-
def envs
|
|
133
|
-
@configuraiton.keys
|
|
144
|
+
def envs(app_name = :app)
|
|
145
|
+
@configuraiton[app_name.to_sym].keys
|
|
134
146
|
end
|
|
135
147
|
end
|
|
136
148
|
end
|
data/lib/rubee/generator.rb
CHANGED
|
@@ -100,9 +100,10 @@ module Rubee
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def generate_db_file
|
|
103
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
|
103
104
|
prefix = @namespace == "" ? "" : "#{@app_name.snakeize}_"
|
|
104
105
|
table_name = "#{prefix}#{@plural_name}"
|
|
105
|
-
db_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "db
|
|
106
|
+
db_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "db/#{timestamp}_create_#{table_name}.rb")
|
|
106
107
|
if File.exist?(db_file)
|
|
107
108
|
puts "DB file for #{table_name} already exists. Remove it if you want to regenerate"
|
|
108
109
|
return
|
data/lib/rubee.rb
CHANGED
|
@@ -4,8 +4,10 @@ describe 'Rubee::Generator' do
|
|
|
4
4
|
describe 'generates Sequel schema lines' do
|
|
5
5
|
after do
|
|
6
6
|
File.delete('lib/app/models/apple.rb') if File.exist?('lib/app/models/apple.rb')
|
|
7
|
-
|
|
7
|
+
# Delete any migration file with timestamp prefix
|
|
8
|
+
Dir.glob('lib/db/*_create_apples.rb').each { |f| File.delete(f) }
|
|
8
9
|
end
|
|
10
|
+
|
|
9
11
|
it 'for string with just name' do
|
|
10
12
|
generator = Rubee::Generator.new(nil, nil, nil, nil)
|
|
11
13
|
|
|
@@ -30,23 +32,30 @@ describe 'Rubee::Generator' do
|
|
|
30
32
|
describe 'generates Sequel file' do
|
|
31
33
|
after do
|
|
32
34
|
File.delete('lib/app/models/apple.rb') if File.exist?('lib/app/models/apple.rb')
|
|
33
|
-
|
|
35
|
+
# Delete any migration file with timestamp prefix
|
|
36
|
+
Dir.glob('lib/db/*_create_apples.rb').each { |f| File.delete(f) }
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
it 'not without a model' do
|
|
37
40
|
generator = Rubee::Generator.new(nil, nil, nil, nil)
|
|
38
41
|
generator.call
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
# Check no migration files exist with any timestamp
|
|
44
|
+
_(Dir.glob('lib/db/*_create_apples.rb').empty?).must_equal(true)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
it 'with a model only' do
|
|
44
48
|
generator = Rubee::Generator.new('apple', nil, 'apples', nil)
|
|
45
49
|
generator.call
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
# Find the migration file with timestamp prefix
|
|
52
|
+
migration_files = Dir.glob('lib/db/*_create_apples.rb')
|
|
53
|
+
_(migration_files.size).must_equal(1)
|
|
54
|
+
|
|
55
|
+
migration_file = migration_files.first
|
|
56
|
+
_(File.exist?(migration_file)).must_equal(true)
|
|
48
57
|
|
|
49
|
-
lines = File.readlines(
|
|
58
|
+
lines = File.readlines(migration_file).map(&:chomp).join("\n")
|
|
50
59
|
|
|
51
60
|
_(lines.include?('class CreateApples')).must_equal(true)
|
|
52
61
|
_(lines.include?('def call')).must_equal(true)
|
|
@@ -61,9 +70,11 @@ describe 'Rubee::Generator' do
|
|
|
61
70
|
'apples', nil)
|
|
62
71
|
generator.call
|
|
63
72
|
|
|
64
|
-
|
|
73
|
+
migration_files = Dir.glob('lib/db/*_create_apples.rb')
|
|
74
|
+
_(migration_files.size).must_equal(1)
|
|
65
75
|
|
|
66
|
-
|
|
76
|
+
migration_file = migration_files.first
|
|
77
|
+
lines = File.readlines(migration_file).map(&:chomp).join("\n")
|
|
67
78
|
|
|
68
79
|
_(lines.include?('class CreateApples')).must_equal(true)
|
|
69
80
|
_(lines.include?('def call')).must_equal(true)
|
|
@@ -79,9 +90,9 @@ describe 'Rubee::Generator' do
|
|
|
79
90
|
[{ name: 'id', type: :bigint }, { name: 'colour', type: :string }, { name: 'weight', type: :integer }], 'apples', nil)
|
|
80
91
|
generator.call
|
|
81
92
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
lines = File.readlines(
|
|
93
|
+
migration_files = Dir.glob('lib/db/*_create_apples.rb')
|
|
94
|
+
migration_file = migration_files.first
|
|
95
|
+
lines = File.readlines(migration_file).map(&:chomp).join("\n")
|
|
85
96
|
|
|
86
97
|
_(lines.include?('class CreateApples')).must_equal(true)
|
|
87
98
|
_(lines.include?('def call')).must_equal(true)
|
|
@@ -98,9 +109,9 @@ describe 'Rubee::Generator' do
|
|
|
98
109
|
[{ name: ['blue_id', 'shoe_id'], type: :foreign_key, table: 'blue_and_shoe_join_tb' }], 'apples', nil)
|
|
99
110
|
generator.call
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
lines = File.readlines(
|
|
112
|
+
migration_files = Dir.glob('lib/db/*_create_apples.rb')
|
|
113
|
+
migration_file = migration_files.first
|
|
114
|
+
lines = File.readlines(migration_file).map(&:chomp).join("\n")
|
|
104
115
|
|
|
105
116
|
_(lines.include?('class CreateApples')).must_equal(true)
|
|
106
117
|
_(lines.include?('def call')).must_equal(true)
|
|
@@ -115,9 +126,9 @@ describe 'Rubee::Generator' do
|
|
|
115
126
|
generator = Rubee::Generator.new('apple', [{ name: 'blue_id', type: :foreign_key }], 'apples', nil)
|
|
116
127
|
generator.call
|
|
117
128
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
lines = File.readlines(
|
|
129
|
+
migration_files = Dir.glob('lib/db/*_create_apples.rb')
|
|
130
|
+
migration_file = migration_files.first
|
|
131
|
+
lines = File.readlines(migration_file).map(&:chomp).join("\n")
|
|
121
132
|
|
|
122
133
|
_(lines.include?('class CreateApples')).must_equal(true)
|
|
123
134
|
_(lines.include?('def call')).must_equal(true)
|
|
@@ -126,12 +137,24 @@ describe 'Rubee::Generator' do
|
|
|
126
137
|
_(lines.include?('foreign_key :blue_id')).must_equal(true)
|
|
127
138
|
_(lines.include?('end')).must_equal(true)
|
|
128
139
|
end
|
|
140
|
+
|
|
141
|
+
it 'generates migration file with timestamp prefix' do
|
|
142
|
+
generator = Rubee::Generator.new('apple', nil, 'apples', nil)
|
|
143
|
+
generator.call
|
|
144
|
+
|
|
145
|
+
migration_files = Dir.glob('lib/db/*_create_apples.rb')
|
|
146
|
+
_(migration_files.size).must_equal(1)
|
|
147
|
+
|
|
148
|
+
# Verify timestamp prefix format (YYYYMMDDHHMMSS_create_apples.rb)
|
|
149
|
+
filename = File.basename(migration_files.first)
|
|
150
|
+
_(filename).must_match(/^\d{14}_create_apples\.rb$/)
|
|
151
|
+
end
|
|
129
152
|
end
|
|
130
153
|
|
|
131
154
|
describe 'generates Model file' do
|
|
132
155
|
after do
|
|
133
156
|
File.delete('lib/app/models/apple.rb') if File.exist?('lib/app/models/apple.rb')
|
|
134
|
-
|
|
157
|
+
Dir.glob('lib/db/*_create_apples.rb').each { |f| File.delete(f) }
|
|
135
158
|
end
|
|
136
159
|
|
|
137
160
|
it 'not without a model' do
|
data/readme.md
CHANGED
|
@@ -221,6 +221,12 @@ This will generate the following files:
|
|
|
221
221
|
```bash
|
|
222
222
|
rubee db run:all
|
|
223
223
|
```
|
|
224
|
+
For supporting ordering in migrations, while you create files manually,
|
|
225
|
+
you would benefit by prefixing the migration file with a number.
|
|
226
|
+
So that will ensure that the migration is run in the proper order and won't be interupted
|
|
227
|
+
with related errors.
|
|
228
|
+
In case you create migration file over `rubee generate /{get} {path}` command, the timestamp
|
|
229
|
+
prefix will be added automatically.
|
|
224
230
|
|
|
225
231
|
4. Fill the generated files with the logic you need and run the server again.
|
|
226
232
|
|
|
@@ -719,6 +725,9 @@ Generates:
|
|
|
719
725
|
```bash
|
|
720
726
|
rubee db run:create_cabbages
|
|
721
727
|
```
|
|
728
|
+
If you migration file prefixed with timestamp or mannually added number, you don't need to include It
|
|
729
|
+
in the command `rubee db run:202603101300_create_cabbages`, just `rubee db run:create_cabbages` will be
|
|
730
|
+
sufficient enough
|
|
722
731
|
|
|
723
732
|
5. Fill the controller with content
|
|
724
733
|
```ruby
|
|
@@ -1039,6 +1048,15 @@ Available extensions:
|
|
|
1039
1048
|
"test".plural? # => false
|
|
1040
1049
|
```
|
|
1041
1050
|
|
|
1051
|
+
In the code base, out of the box, you can check current environtment with:
|
|
1052
|
+
```ruby
|
|
1053
|
+
Rubee::Configuration.env
|
|
1054
|
+
# => :development
|
|
1055
|
+
|
|
1056
|
+
Rubee::Configuration.development?
|
|
1057
|
+
# => true
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1042
1060
|
[Back to content](#content)
|
|
1043
1061
|
|
|
1044
1062
|
## JWT based authentication
|