seed_dump 0.3.2 → 0.3.3
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.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/contents.yml +22 -0
- data/lib/seed_dump/perform.rb +21 -18
- data/lib/tasks/seed_dump.rake +1 -1
- data/seed_dump.gemspec +4 -2
- data/test/fixtures/samples.yml +10 -0
- data/test/seed_dump_test.rb +1 -1
- metadata +4 -2
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/contents.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
article1:
|
3
|
+
id: 1
|
4
|
+
title: Article one
|
5
|
+
body: body
|
6
|
+
extended: extended content
|
7
|
+
created_at: 2011-06-01 00:00:01
|
8
|
+
updated_at: 2011-06-01 00:00:02
|
9
|
+
some_id: 1
|
10
|
+
author: Johnny Johnson
|
11
|
+
published: true
|
12
|
+
|
13
|
+
article2:
|
14
|
+
id: 2
|
15
|
+
title: This is a very long title and it should not be truncated
|
16
|
+
body: body
|
17
|
+
extended: extended content
|
18
|
+
created_at: 2010-06-01 20:00:01
|
19
|
+
updated_at: 2010-06-01 20:00:02
|
20
|
+
some_id: 2
|
21
|
+
author: Bob
|
22
|
+
published: true
|
data/lib/seed_dump/perform.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
module SeedDump
|
2
2
|
class Perform
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
def initialize
|
5
|
+
@opts = {}
|
6
|
+
@ar_options = {}
|
7
|
+
@indent = ""
|
8
|
+
@models = []
|
9
|
+
@seed_rb = ""
|
10
|
+
@id_set_string = ""
|
11
|
+
@verbose = true
|
12
|
+
@model_dir = 'app/models/*.rb'
|
13
|
+
end
|
11
14
|
|
12
|
-
def
|
15
|
+
def setup(env)
|
13
16
|
# config
|
14
17
|
@opts['with_id'] = !env["WITH_ID"].nil?
|
15
18
|
@opts['no-data'] = !env['NO_DATA'].nil?
|
@@ -18,17 +21,17 @@ module SeedDump
|
|
18
21
|
@opts['append'] = (!env['APPEND'].nil? && File.exists?(@opts['file']) )
|
19
22
|
@ar_options = env['LIMIT'].to_i > 0 ? { :limit => env['LIMIT'].to_i } : {}
|
20
23
|
@indent = " " * (env['INDENT'].nil? ? 2 : env['INDENT'].to_i)
|
21
|
-
@opts['models'] = @opts['models'].split(',').collect {|x| x.underscore.singularize.camelize
|
24
|
+
@opts['models'] = @opts['models'].split(',').collect {|x| x.underscore.singularize.camelize }
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
25
|
-
Dir[
|
26
|
-
model = File.basename(f, '.*').camelize
|
27
|
+
def loadModels
|
28
|
+
Dir[@model_dir].sort.each do |f|
|
29
|
+
model = File.basename(f, '.*').camelize
|
27
30
|
@models.push model if @opts['models'].include?(model) || @opts['models'].empty?
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
34
|
+
def dumpAttribute(a_s,r,k,v)
|
32
35
|
v = r.attribute_for_inspect(k)
|
33
36
|
if k == 'id' && @opts['with_id']
|
34
37
|
@id_set_string = "{ |c| c.#{k} = #{v} }.save"
|
@@ -37,7 +40,7 @@ module SeedDump
|
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
|
-
def
|
43
|
+
def dumpModel(model)
|
41
44
|
@id_set_string = ''
|
42
45
|
create_hash = ""
|
43
46
|
rows = []
|
@@ -60,22 +63,22 @@ module SeedDump
|
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
63
|
-
def
|
66
|
+
def dumpModels
|
64
67
|
@seed_rb = ""
|
65
68
|
@models.sort.each do |model|
|
66
69
|
puts "Adding #{model} seeds." if @verbose
|
67
|
-
@seed_rb << dumpModel(model) << "\n\n"
|
70
|
+
@seed_rb << dumpModel(model.constantize) << "\n\n"
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
def
|
74
|
+
def writeFile
|
72
75
|
File.open(@opts['file'], (@opts['append'] ? "a" : "w")) { |f|
|
73
76
|
f << "# Autogenerated by the db:seed:dump task\n# Do not hesitate to tweak this to your needs\n" unless @opts['append']
|
74
77
|
f << "#{@seed_rb}"
|
75
78
|
}
|
76
79
|
end
|
77
80
|
|
78
|
-
def
|
81
|
+
def run(env)
|
79
82
|
|
80
83
|
setup env
|
81
84
|
|
data/lib/tasks/seed_dump.rake
CHANGED
data/seed_dump.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{seed_dump}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rob Halff"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-14}
|
13
13
|
s.description = %q{Dump (parts) of your database to db/seeds.rb to get a headstart creating a meaningful seeds.rb file}
|
14
14
|
s.email = %q{rob.halff@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,11 +21,13 @@ Gem::Specification.new do |s|
|
|
21
21
|
"README.rdoc",
|
22
22
|
"Rakefile",
|
23
23
|
"VERSION",
|
24
|
+
"contents.yml",
|
24
25
|
"lib/seed_dump.rb",
|
25
26
|
"lib/seed_dump/perform.rb",
|
26
27
|
"lib/seed_dump/railtie.rb",
|
27
28
|
"lib/tasks/seed_dump.rake",
|
28
29
|
"seed_dump.gemspec",
|
30
|
+
"test/fixtures/samples.yml",
|
29
31
|
"test/seed_dump_test.rb",
|
30
32
|
"test/test_helper.rb"
|
31
33
|
]
|
data/test/seed_dump_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
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: 2011-
|
12
|
+
date: 2011-07-14 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: Dump (parts) of your database to db/seeds.rb to get a headstart creating
|
@@ -25,11 +25,13 @@ files:
|
|
25
25
|
- README.rdoc
|
26
26
|
- Rakefile
|
27
27
|
- VERSION
|
28
|
+
- contents.yml
|
28
29
|
- lib/seed_dump.rb
|
29
30
|
- lib/seed_dump/perform.rb
|
30
31
|
- lib/seed_dump/railtie.rb
|
31
32
|
- lib/tasks/seed_dump.rake
|
32
33
|
- seed_dump.gemspec
|
34
|
+
- test/fixtures/samples.yml
|
33
35
|
- test/seed_dump_test.rb
|
34
36
|
- test/test_helper.rb
|
35
37
|
has_rdoc: true
|