rails_seeds 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: b7c946daca5b604b31220a9f40dfd9cad909bb7806fa0223552cdd6333a741ca
4
- data.tar.gz: 8f4aea96d83938e325256f12321eb706e8da4e65e20dfbd0b11cab3ad68ce1f0
3
+ metadata.gz: 7cbbe2358f4a7c927c64dffe1972ab4356dd466b4e9dd2132de1e2ffd2e49368
4
+ data.tar.gz: 5382da2c48967f5683556c37d36e4c0f293813fd99017af7eada4fa348489adc
5
5
  SHA512:
6
- metadata.gz: 01b0d5934c7fe6195282d2a288b1a51bacfc224d7ebf6a116eb459f2b932e72aaf875a7d9e8bfb7d476912cdd84093287e84f639c49d669b577e52df0a18e483
7
- data.tar.gz: ab9ae8079055ba7241879f04ee6bc751a18c5ce6e83d487e9c45a95bb617085287c8be6368ffbe0b81d35c4c2bd20ad7f47cb9397f72e44a39b8c5e4a1fb939d
6
+ metadata.gz: b1090c82d8ad7adf9f211ca5785dba7fbdf28445b438739a6dd7bd3bf6a3cdf4335e090cc7c76bb3b2b5136888dd7dff912882aea6f7142b6d88e5047ee9f058
7
+ data.tar.gz: 676d3dacc371e103423ea946ce870f45c3efdd9e59b6b07dc2017aee5300f5d26b87e2bc75d96dcd381a3976daf135a11f05a71518c174aa6813dbc26898ac58
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_seeds (0.1.1)
4
+ rails_seeds (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,31 @@
1
+ module RailsSeeds
2
+ class << self
3
+ def retrieve_path(file)
4
+ File.join(seed_folder, file)
5
+ end
6
+
7
+ def valid_file?(file)
8
+ path = retrieve_path(file)
9
+
10
+ return true if File.file?(path)
11
+
12
+ puts "#{path} is invalid."
13
+
14
+ false
15
+ end
16
+
17
+ def run(file, method = :system)
18
+ path = RailsSeeds.retrieve_path(file)
19
+
20
+ puts "Run seed #{path}"
21
+
22
+ send(method, "rails runner #{path}")
23
+ end
24
+
25
+ private
26
+
27
+ def seed_folder
28
+ @seed_folder ||= File.join(Rails.root, 'db', 'seed')
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSeeds
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/rails_seeds.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rails_seeds/version'
2
+ require 'rails_seeds/helpers'
2
3
 
3
4
  module RailsSeeds
4
5
  require 'rails_seeds/railtie' if defined?(Rails)
data/lib/tasks/list.rake CHANGED
@@ -2,7 +2,7 @@ namespace :seeds do
2
2
  desc 'List all current seed files in db/seed'
3
3
  task :list do
4
4
  Dir[File.join(File.join(Rails.root, 'db', 'seed'), '*.rb')].each do |path|
5
- puts path
5
+ puts File.basename(path, '.rb')
6
6
  end
7
7
  end
8
8
  end
data/lib/tasks/seeds.rake CHANGED
@@ -1,39 +1,30 @@
1
1
  namespace :db do
2
2
  desc 'Run specific seed files in folder db/seed'
3
3
  task :seeds do
4
- seed_folder = File.join(Rails.root, 'db', 'seed')
5
4
  _, *files = ARGV
5
+ *files, last_file = files.select { |f| RailsSeeds.valid_file?("#{f}.rb") }
6
6
 
7
7
  files.each do |file|
8
- file = "#{file}.rb"
9
- path = File.join(seed_folder, file)
10
-
11
- unless File.file?(path)
12
- puts "#{path} is invalid."
13
-
14
- next
15
- end
16
-
17
- puts "Run seed #{path}."
18
-
19
- exec "rails runner #{path}"
8
+ Rake::Task['db:seeds:exec'].reenable
9
+ Rake::Task['db:seeds:exec'].invoke(file)
20
10
  end
11
+
12
+ RailsSeeds.run("#{last_file}.rb", :exec) if last_file.present?
21
13
  end
22
14
 
23
15
  namespace :seeds do
24
16
  desc 'Run all seed files in folder db/seed'
25
17
  task :all do
26
18
  Dir[File.join(Rails.root, 'db', 'seed', '*.rb')].each do |path|
27
- unless File.file?(path)
28
- puts "#{path} is invalid."
29
-
30
- next
31
- end
19
+ Rake::Task['db:seeds:exec'].reenable
20
+ Rake::Task['db:seeds:exec'].invoke(File.basename(path, '.rb'))
21
+ end
22
+ end
32
23
 
33
- puts "Run seed #{path}."
24
+ task :exec, :seed do |_, args|
25
+ file = "#{args[:seed]}.rb"
34
26
 
35
- exec "rails runner #{path}"
36
- end
27
+ RailsSeeds.run(file)
37
28
  end
38
29
  end
39
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_seeds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alpha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-03 00:00:00.000000000 Z
11
+ date: 2020-03-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Run seed data from individual file
14
14
  email:
@@ -24,6 +24,7 @@ files:
24
24
  - Rakefile
25
25
  - lib/generators/rails_seeds/seed/seed_generator.rb
26
26
  - lib/rails_seeds.rb
27
+ - lib/rails_seeds/helpers.rb
27
28
  - lib/rails_seeds/railtie.rb
28
29
  - lib/rails_seeds/version.rb
29
30
  - lib/tasks/list.rake