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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41f3ef736978148e10f7583125f87b2bfa9433af
4
- data.tar.gz: 91c526717b66b76498ab9c97bf62ba0fa148f2fb
3
+ metadata.gz: f245dcc20720c5de6905ade961bc61fed8fa124b
4
+ data.tar.gz: 22316766f8de584587ec4ccd1e24dffd730c686e
5
5
  SHA512:
6
- metadata.gz: 0444ab901be8c5fc53db3b0d269fe500430219193783c59e1bb891694fd33be3ffd19cf65de42be046d3904065bb891fe62af73394c179c7bad4770abfc78dfb
7
- data.tar.gz: 6b904acfb2d9ec82295bc5cf648b856ff6e9c134b01eb43a92e052b0cf7fb966f7650ab1afb5adfd5861d6bb965902a62f5dbfcfc0fc73a59b34024b4ba6276a
6
+ metadata.gz: 850b098c97867b5985fe37a8b68188e8ae3baffe2038feb1646e6886d988f5f3a5248abe2d0ee27adc4b6cdc58ff4acb5c2bfba14991b3887dc743adae7b4fcd
7
+ data.tar.gz: 74688e6b0f2271ec0368d6d4b63f81b6c031f1987bf65e88300efc0479909b2f870036bf6234247d721d1479397197f134315cc780bb99ed594d78f2b4bc2391
data/README.md CHANGED
@@ -347,6 +347,7 @@ coverage.
347
347
  improvement
348
348
  * Rake task for killing PostgreSQL conventions `db:kill_postgres_connections`
349
349
  * Rake task `redis:flushall`
350
+ * Made seeds organization for easy splitting data from scratch
350
351
 
351
352
  ## Heroku
352
353
 
@@ -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
- run 'mkdir app/support'
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
@@ -150,5 +150,10 @@ module Onotole
150
150
  def br(str = nil)
151
151
  str ? "\n" + str : "\n"
152
152
  end
153
+
154
+ def mkdir_and_touch(dir)
155
+ run "mkdir #{dir}"
156
+ touch "#{dir}/.keep"
157
+ end
153
158
  end
154
159
  end
@@ -2,5 +2,5 @@
2
2
  module Onotole
3
3
  RAILS_VERSION = '~> 4.2.0'
4
4
  RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
5
- VERSION = '1.2.3'
5
+ VERSION = '1.2.4'
6
6
  end
@@ -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.3
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