seeding_utils 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/seeding_utils.rb +5 -4
- data/lib/seeding_utils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1632bb5e3f79c6ce545c09e2582ee1375b83f955
|
4
|
+
data.tar.gz: a28eb9d72d4fa1b427349abf969f7c773f61cc38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81a9708709fe316ef4369a03746a1fc87407c1b1b19b6cb7b1ab908b661e355622d8b88f1aab58f28f6cba07bea6ec458c20849a95e15ef424a046beeafba4ae
|
7
|
+
data.tar.gz: 0a17c42831976d762de43f5fe4ac4b45b5bfb2d71598dafb092819786b154a0c48e4c2e7ff017e9ac61ebf5a0dfb030e1143f7fda98c938f46debb50dddbf280
|
data/lib/seeding_utils.rb
CHANGED
@@ -22,19 +22,20 @@ module SeedingUtils
|
|
22
22
|
|
23
23
|
class Table
|
24
24
|
|
25
|
-
attr_accessor :name, :quoted_name
|
25
|
+
attr_accessor :name, :quoted_name, :prefix
|
26
26
|
|
27
|
-
def initialize(name)
|
27
|
+
def initialize(name, prefix = ' ->')
|
28
28
|
@conn = SeedingUtils.connection
|
29
29
|
self.name = name
|
30
30
|
self.quoted_name = PG::Connection.quote_ident(name)
|
31
|
+
self.prefix = prefix
|
31
32
|
end
|
32
33
|
|
33
34
|
def seed(cache_file = nil, &block)
|
34
35
|
path = Pathname(cache_file.to_s)
|
35
36
|
return seed_uncached(&block) if cache_file.nil?
|
36
37
|
if path.file?
|
37
|
-
puts %{
|
38
|
+
puts %{#{prefix} loading #{name} seeds from cache}
|
38
39
|
@conn.exec %{DELETE FROM #{quoted_name}}
|
39
40
|
load path.open 'r:binary'
|
40
41
|
elsif block_given?
|
@@ -46,7 +47,7 @@ module SeedingUtils
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def seed_uncached(&block)
|
49
|
-
puts %{
|
50
|
+
puts %{#{prefix} loading #{name} seeds without cache}
|
50
51
|
yield
|
51
52
|
end
|
52
53
|
|