fixture_seed 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fixture_seed/loader.rb +10 -24
- data/lib/fixture_seed/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eac99125111c4643c61c6fb9a8437ff32efe5b5e695e241565078de54b46526
|
4
|
+
data.tar.gz: 3fc03ab1f49b6723ef304bbd7ea4a892150e474080c70d6182b069013b02eec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 248a11f90920c9fd60fc0e6931fd3adf29baa427eb9fd42a275e27e789cf58f35341786d93051e916409e765df6d341c0f3a6aeb6c8ec911816e6bcc7d491a34
|
7
|
+
data.tar.gz: cc63888523cab5b38d0fd4c4b72b5f03f1b478884895d6da29c4fee8b51c8f274bcc931d80f37bf65f3d986307b696b440080596a24e77c4444c98945d7f2659
|
data/lib/fixture_seed/loader.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_record"
|
4
|
+
require "active_record/fixtures"
|
4
5
|
|
5
6
|
module FixtureSeed
|
6
7
|
class Loader
|
@@ -8,37 +9,22 @@ module FixtureSeed
|
|
8
9
|
|
9
10
|
class << self
|
10
11
|
def load_fixtures(fixtures_path = nil)
|
11
|
-
fixtures_path ||= ENV["FIXTURES_PATH"] ||
|
12
|
+
fixtures_path ||= ENV["FIXTURES_PATH"] || "db/fixtures"
|
12
13
|
fixtures_dir = Rails.root.join(fixtures_path)
|
14
|
+
fixture_names = discover_fixture_names(fixtures_dir)
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
ActiveRecord::Base.connection.disable_referential_integrity do
|
17
|
+
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir.to_s, fixture_names)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
false
|
26
|
-
end
|
27
|
-
|
28
|
-
def load_fixture_files(fixtures_dir, fixtures_path)
|
29
|
-
Rails.logger&.info "[FixtureSeed] Loading fixtures from #{fixtures_path}"
|
30
|
-
|
31
|
-
fixture_files = Dir.glob("#{fixtures_dir}/*.yml")
|
32
|
-
return if fixture_files.empty?
|
33
|
-
|
34
|
-
table_names = fixture_files.map { |f| File.basename(f, ".yml") }
|
35
|
-
Rails.logger&.info "[FixtureSeed] Found tables: #{table_names.join(', ')}"
|
36
|
-
|
37
|
-
ActiveRecord::Base.connection.disable_referential_integrity do
|
38
|
-
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir.to_s, table_names)
|
23
|
+
def discover_fixture_names(fixtures_dir)
|
24
|
+
fixture_files = Dir[File.join(fixtures_dir, "**/*.yml")]
|
25
|
+
fixture_files.map do |file|
|
26
|
+
file[fixtures_dir.to_s.size..-5].delete_prefix("/")
|
39
27
|
end
|
40
|
-
|
41
|
-
Rails.logger&.info "[FixtureSeed] Finished loading fixtures"
|
42
28
|
end
|
43
29
|
end
|
44
30
|
end
|
data/lib/fixture_seed/version.rb
CHANGED