seed_scatter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/seed_scatter/harvest.rb +18 -7
- data/lib/seed_scatter/version.rb +1 -1
- data/lib/tasks/seed_scatter.rake +3 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -35,10 +35,12 @@ To dump all of your models' information from the database to their respective se
|
|
35
35
|
|
36
36
|
$ rake db:harvest
|
37
37
|
|
38
|
+
To re-seed a specific model:
|
39
|
+
|
40
|
+
$ rake db:reseed[MODEL_NAME]
|
38
41
|
|
39
42
|
## Todos
|
40
43
|
|
41
|
-
* Re-seed models one at a time
|
42
44
|
* Support for namespaced models
|
43
45
|
* Support for join tables
|
44
46
|
|
data/lib/seed_scatter/harvest.rb
CHANGED
@@ -6,21 +6,32 @@ module SeedScatter
|
|
6
6
|
|
7
7
|
def init(model)
|
8
8
|
models = if model == :all
|
9
|
-
Dir['app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize
|
9
|
+
Dir['app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
|
10
10
|
else
|
11
|
-
[model]
|
11
|
+
[model.camelize.constantize]
|
12
12
|
end
|
13
13
|
models.each do |m|
|
14
|
-
@model = m
|
14
|
+
@model = m
|
15
15
|
puts "Harvesting seeds for #{class_name}"
|
16
16
|
@harvest_data = []
|
17
17
|
dump_model(m)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def reseed(model)
|
22
|
+
@model = m = model.camelize.constantize
|
23
|
+
truncate(m.table_name)
|
24
|
+
f = File.expand_path(File.join("db","seeds","#{m.table_name}.rb"))
|
25
|
+
puts "Reseeding #{f}"
|
26
|
+
load(f)
|
27
|
+
end
|
28
|
+
|
29
|
+
def truncate(table)
|
30
|
+
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
|
31
|
+
end
|
32
|
+
|
21
33
|
def collect_data(model)
|
22
|
-
|
23
|
-
klass.all.each do |m|
|
34
|
+
model.all.each do |m|
|
24
35
|
@harvest_data << ActiveSupport::JSON.decode(m.attributes.to_json).symbolize_keys
|
25
36
|
end
|
26
37
|
end
|
@@ -35,11 +46,11 @@ module SeedScatter
|
|
35
46
|
end
|
36
47
|
|
37
48
|
def class_name
|
38
|
-
@model.
|
49
|
+
@model.name
|
39
50
|
end
|
40
51
|
|
41
52
|
def destination_path(model)
|
42
|
-
"db/seeds/#{model.
|
53
|
+
"db/seeds/#{model.table_name}.rb"
|
43
54
|
end
|
44
55
|
end
|
45
56
|
|
data/lib/seed_scatter/version.rb
CHANGED
data/lib/tasks/seed_scatter.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_scatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|