rails_seeds 0.1.1 → 0.1.3

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: 1150c999700f280118cc9e5d1835e8569fd1102f0f6ebea0687b631d74efc47d
4
+ data.tar.gz: 2d5a3aca9919f290c8f70301502a77c019047b39090161cc0add6eedce2434be
5
5
  SHA512:
6
- metadata.gz: 01b0d5934c7fe6195282d2a288b1a51bacfc224d7ebf6a116eb459f2b932e72aaf875a7d9e8bfb7d476912cdd84093287e84f639c49d669b577e52df0a18e483
7
- data.tar.gz: ab9ae8079055ba7241879f04ee6bc751a18c5ce6e83d487e9c45a95bb617085287c8be6368ffbe0b81d35c4c2bd20ad7f47cb9397f72e44a39b8c5e4a1fb939d
6
+ metadata.gz: 80e97ac728814bae27a845fffa65602ac8c31efb4b6296d4e50bfc5462585c265b3d551fc72817aada7c0fb1b0c95d73378a08b6fd39e5ccb053ed27435f6ecb
7
+ data.tar.gz: 2458f994ed29fd2879daa964fef0bd26fcf7febe9c678eeb3cf57470fbec3aea4bab9afc26ed4f3ac7ebc7f4040785bffc8eae57e6152c86f18fa6df039ddbf6
data/Gemfile.lock CHANGED
@@ -1,34 +1,42 @@
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/
8
8
  specs:
9
- ast (2.4.0)
10
- byebug (11.1.1)
11
- childprocess (3.0.0)
9
+ ast (2.4.2)
10
+ byebug (11.1.3)
11
+ childprocess (4.1.0)
12
12
  iniparse (1.5.0)
13
- jaro_winkler (1.5.4)
14
- overcommit (0.52.1)
15
- childprocess (>= 0.6.3, < 4)
13
+ json (2.6.3)
14
+ overcommit (0.60.0)
15
+ childprocess (>= 0.6.3, < 5)
16
16
  iniparse (~> 1.4)
17
- parallel (1.19.1)
18
- parser (2.7.0.4)
19
- ast (~> 2.4.0)
20
- rainbow (3.0.0)
21
- rexml (3.2.4)
22
- rubocop (0.80.1)
23
- jaro_winkler (~> 1.5.1)
17
+ rexml (~> 3.2)
18
+ parallel (1.23.0)
19
+ parser (3.2.2.3)
20
+ ast (~> 2.4.1)
21
+ racc
22
+ racc (1.7.0)
23
+ rainbow (3.1.1)
24
+ regexp_parser (2.8.1)
25
+ rexml (3.2.5)
26
+ rubocop (1.50.2)
27
+ json (~> 2.3)
24
28
  parallel (~> 1.10)
25
- parser (>= 2.7.0.1)
29
+ parser (>= 3.2.0.0)
26
30
  rainbow (>= 2.2.2, < 4.0)
27
- rexml
31
+ regexp_parser (>= 1.8, < 3.0)
32
+ rexml (>= 3.2.5, < 4.0)
33
+ rubocop-ast (>= 1.28.0, < 2.0)
28
34
  ruby-progressbar (~> 1.7)
29
- unicode-display_width (>= 1.4.0, < 1.7)
30
- ruby-progressbar (1.10.1)
31
- unicode-display_width (1.6.1)
35
+ unicode-display_width (>= 2.4.0, < 3.0)
36
+ rubocop-ast (1.29.0)
37
+ parser (>= 3.2.1.0)
38
+ ruby-progressbar (1.13.0)
39
+ unicode-display_width (2.4.2)
32
40
 
33
41
  PLATFORMS
34
42
  ruby
@@ -40,4 +48,4 @@ DEPENDENCIES
40
48
  rubocop
41
49
 
42
50
  BUNDLED WITH
43
- 2.0.1
51
+ 2.1.4
@@ -9,7 +9,7 @@ module RailsSeeds
9
9
 
10
10
  FileUtils.mkdir_p(seed_folder) unless File.exist?(seed_folder)
11
11
 
12
- path = File.join(seed_folder, "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{file.snakecase}.rb")
12
+ path = File.join(seed_folder, "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{file.underscore}.rb")
13
13
  FileUtils.touch(path)
14
14
 
15
15
  puts "Create seed file #{path}"
@@ -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.3'
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alpha
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-03 00:00:00.000000000 Z
11
+ date: 2023-06-14 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
@@ -33,7 +34,7 @@ homepage: https://github.com/zgid123/rails_seeds
33
34
  licenses:
34
35
  - MIT
35
36
  metadata: {}
36
- post_install_message:
37
+ post_install_message:
37
38
  rdoc_options: []
38
39
  require_paths:
39
40
  - lib
@@ -48,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  requirements: []
51
- rubygems_version: 3.1.2
52
- signing_key:
52
+ rubygems_version: 3.0.3.1
53
+ signing_key:
53
54
  specification_version: 4
54
55
  summary: Run seed data from individual file
55
56
  test_files: []