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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rails_seeds/helpers.rb +31 -0
- data/lib/rails_seeds/version.rb +1 -1
- data/lib/rails_seeds.rb +1 -0
- data/lib/tasks/list.rake +1 -1
- data/lib/tasks/seeds.rake +12 -21
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cbbe2358f4a7c927c64dffe1972ab4356dd466b4e9dd2132de1e2ffd2e49368
|
4
|
+
data.tar.gz: 5382da2c48967f5683556c37d36e4c0f293813fd99017af7eada4fa348489adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1090c82d8ad7adf9f211ca5785dba7fbdf28445b438739a6dd7bd3bf6a3cdf4335e090cc7c76bb3b2b5136888dd7dff912882aea6f7142b6d88e5047ee9f058
|
7
|
+
data.tar.gz: 676d3dacc371e103423ea946ce870f45c3efdd9e59b6b07dc2017aee5300f5d26b87e2bc75d96dcd381a3976daf135a11f05a71518c174aa6813dbc26898ac58
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/rails_seeds/version.rb
CHANGED
data/lib/rails_seeds.rb
CHANGED
data/lib/tasks/list.rake
CHANGED
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
|
-
|
9
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
24
|
+
task :exec, :seed do |_, args|
|
25
|
+
file = "#{args[:seed]}.rb"
|
34
26
|
|
35
|
-
|
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.
|
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-
|
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
|