onotole 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/goodies/seeds_organization.md +23 -0
- data/lib/onotole/default_scripts.rb +7 -2
- data/lib/onotole/generators/app_generator.rb +1 -0
- data/lib/onotole/helpers.rb +5 -0
- data/lib/onotole/version.rb +1 -1
- data/templates/seeds.rb +7 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f245dcc20720c5de6905ade961bc61fed8fa124b
|
4
|
+
data.tar.gz: 22316766f8de584587ec4ccd1e24dffd730c686e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850b098c97867b5985fe37a8b68188e8ae3baffe2038feb1646e6886d988f5f3a5248abe2d0ee27adc4b6cdc58ff4acb5c2bfba14991b3887dc743adae7b4fcd
|
7
|
+
data.tar.gz: 74688e6b0f2271ec0368d6d4b63f81b6c031f1987bf65e88300efc0479909b2f870036bf6234247d721d1479397197f134315cc780bb99ed594d78f2b4bc2391
|
data/README.md
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
In some projects I've got a lot of data, which need to be loaded in db and Rails
|
2
|
+
provide simple tool for it: `seeds.rb`. But it can come ugly and hard
|
3
|
+
supportable it few days and you may do simple 1000 strings of code, which will
|
4
|
+
become unsupportable in a moment. Easiest way to prevent it: split seeds.
|
5
|
+
I provide simple way, you add in `seeds.rb` this snippet of code
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
Rails.logger = Logger.new STDOUT
|
10
|
+
seed_files_list = Dir[File.join(Rails.root, "db", "seeds", "*.rb")]
|
11
|
+
seed_files_list.sort.each_with_index do |seed, i|
|
12
|
+
load seed
|
13
|
+
Rails.logger.info "Progress #{i + 1}/#{seed_files_list.length}. Seed #{seed.split('/').last.sub(/.rb$/, '')} loaded"
|
14
|
+
end
|
15
|
+
|
16
|
+
```
|
17
|
+
|
18
|
+
So now you will autoload all files from seeds folder and get pretty notify.
|
19
|
+
Easiest way to organize line it to name files with priority number like:
|
20
|
+
|
21
|
+
> `001_admin_user.rb`
|
22
|
+
> `080_products.rb`
|
23
|
+
> `500_comments.rb`
|
@@ -189,8 +189,7 @@ end
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def configure_support_path
|
192
|
-
|
193
|
-
run 'touch app/support/.keep'
|
192
|
+
mkdir_and_touch 'app/support'
|
194
193
|
copy_file 'support.rb', 'config/initializers/support.rb'
|
195
194
|
|
196
195
|
config = "\n config.autoload_paths << Rails.root.join('app/support')\n"
|
@@ -208,5 +207,11 @@ end
|
|
208
207
|
def provide_kill_postgres_connections_task
|
209
208
|
copy_file 'kill_postgress_conections.rake', 'lib/tasks/kill_postgress_conections.rake'
|
210
209
|
end
|
210
|
+
|
211
|
+
def seeds_organisation
|
212
|
+
remove_file 'db/seeds.rb'
|
213
|
+
copy_file 'seeds.rb', 'db/seeds.rb'
|
214
|
+
mkdir_and_touch 'db/seeds'
|
215
|
+
end
|
211
216
|
end
|
212
217
|
end
|
@@ -112,6 +112,7 @@ module Onotole
|
|
112
112
|
build :raise_on_delivery_errors
|
113
113
|
build :set_test_delivery_method
|
114
114
|
build :raise_on_unpermitted_parameters
|
115
|
+
build :seeds_organisation
|
115
116
|
build :provide_setup_script
|
116
117
|
build :provide_dev_prime_task
|
117
118
|
build :provide_kill_postgres_connections_task
|
data/lib/onotole/helpers.rb
CHANGED
data/lib/onotole/version.rb
CHANGED
data/templates/seeds.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Rails.logger = Logger.new STDOUT
|
3
|
+
seed_files_list = Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')]
|
4
|
+
seed_files_list.sort.each_with_index do |seed, i|
|
5
|
+
load seed
|
6
|
+
Rails.logger.info "Progress #{i + 1}/#{seed_files_list.length}. Seed #{seed.split('/').last.sub(/.rb$/, '')} loaded"
|
7
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onotole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kvokka
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- bin/t
|
86
86
|
- goodies/custom_404_and_others_in_1_minute.md
|
87
87
|
- goodies/mailcatcher_loading_patch.md
|
88
|
+
- goodies/seeds_organization.md
|
88
89
|
- goodies/tests_speed_up_hack.md
|
89
90
|
- lib/onotole.rb
|
90
91
|
- lib/onotole/actions.rb
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- templates/redis.rake
|
173
174
|
- templates/rubocop.yml
|
174
175
|
- templates/secrets.yml
|
176
|
+
- templates/seeds.rb
|
175
177
|
- templates/shoulda_matchers_config_rspec.rb
|
176
178
|
- templates/smtp.rb.erb
|
177
179
|
- templates/spec_helper.rb.erb
|