seed_dump 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,10 @@ Seed dump is a simple plugin that adds a rake task named db:seed:dump.
5
5
  It allows you to create a db/seeds.rb from your existing data in the database.
6
6
  When there is no data in the database it will generate empty create statements.
7
7
 
8
+ It mainly exists for people who are too lazy writing create statements in db/seeds.rb themselves
9
+ and need something (+seed_dump+) to dump data from the table(s) into seeds.rb
8
10
 
9
- === Example Usage
11
+ == Example Usage
10
12
 
11
13
  Dump all data directly to db/seeds.rb:
12
14
 
@@ -56,7 +58,7 @@ Here is a full example using all of the options above:
56
58
 
57
59
  rake db:seed:dump MODELS=Category LIMIT=10 APPEND=true FILE=db/categories.rb WITH_ID=1 NO_DATA=1
58
60
 
59
- === All environment variables
61
+ == All environment variables
60
62
 
61
63
  APPEND:
62
64
  Append the data to db/seeds.rb instead of overwriting it.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.1
@@ -1,8 +1,4 @@
1
1
  # SeedDump
2
2
  module SeedDump
3
- class Railtie < Rails::Railtie
4
- rake_tasks do
5
- load "seed_dump/railties/tasks.rake"
6
- end
7
- end
3
+ require 'seed_dump/railtie' if defined?(Rails)
8
4
  end
@@ -0,0 +1,9 @@
1
+ module SeedDump
2
+ class Railtie < Rails::Railtie
3
+
4
+ rake_tasks do
5
+ load "tasks/seed_dump.rake"
6
+ end
7
+
8
+ end
9
+ end
@@ -1,22 +1,6 @@
1
1
  namespace :db do
2
-
3
- # tests:
4
- # test empty opt.models
5
- # test populated opt.models
6
- # test no_id option
7
- # test limit option
8
- # test empty table but valid seed
9
- # test no-data
10
- # Write by default to db/seeds.rb
11
- # make filename optional with FILE env variable
12
- # should ignore append if file doesn't exist
13
- #
14
- # rake db:seed:dump WITH_ID=true MODELS=User,Product LIMIT=1 NO_DATA=true APPEND=true INDENT=8 FILE=/tmp/seeds.rb
15
- #
16
- namespace :seed do
17
- desc =<<HERE
18
- Dump records from the database into db/seeds
19
- HERE
2
+ namespace :seed do
3
+ desc "Dump records from the database into db/seeds.rb"
20
4
  task :dump => :environment do
21
5
 
22
6
  # config
@@ -31,7 +15,7 @@ HERE
31
15
 
32
16
  models = opts['models'].split(',').collect {|x| x.underscore.singularize }
33
17
 
34
- new_line = "\r\n"
18
+ new_line = "\n"
35
19
 
36
20
  seed_rb = ""
37
21
  Dir['app/models/*.rb'].each do |f|
@@ -47,15 +31,20 @@ HERE
47
31
  arr.each_with_index { |r,i|
48
32
 
49
33
  attr_s = [];
50
- r.attributes.each { |k,v| attr_s.push("#{k.to_sym.inspect} => #{v.inspect}") unless k == 'id' && !opts['with_id'] }
34
+
35
+ r.attributes.each { |k,v|
36
+ v = v.class == Time ? "\"#{v}\"" : v.inspect
37
+ attr_s.push("#{k.to_sym.inspect} => #{v}") unless k == 'id' && !opts['with_id']
38
+ }
51
39
 
52
40
  create_hash << (i > 0 ? ",#{new_line}" : new_line) << indent << '{ ' << attr_s.join(', ') << ' }'
53
41
 
54
42
  }
55
43
 
56
- seed_rb << "#{new_line}#{model_name.pluralize} = #{model_name.camelize}.create(#{create_hash}#{new_line})#{new_line}"
44
+ seed_rb << "#{new_line}#{model_name.pluralize} = #{model_name.camelize}.create([#{create_hash}#{new_line}])#{new_line}"
57
45
  end
58
46
  end
47
+
59
48
  File.open(opts['file'], (opts['append'] ? "a" : "w")) { |f|
60
49
 
61
50
  unless opts['append']
@@ -74,5 +63,4 @@ HERE
74
63
  }
75
64
  end
76
65
  end
77
-
78
66
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{seed_dump}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.1"
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{2010-07-29}
12
+ s.date = %q{2010-08-01}
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 = [
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
22
22
  "README.rdoc",
23
23
  "Rakefile",
24
24
  "VERSION",
25
- "lib/railties/tasks.rake",
26
25
  "lib/seed_dump.rb",
27
- "lib/version.rb",
26
+ "lib/seed_dump/railtie.rb",
27
+ "lib/tasks/seed_dump.rake",
28
28
  "seed_dump.gemspec",
29
29
  "test/seed_dump_test.rb",
30
30
  "test/test_helper.rb"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 2
7
8
  - 1
8
- - 4
9
- version: 0.1.4
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rob Halff
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-29 00:00:00 +02:00
17
+ date: 2010-08-01 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -33,9 +33,9 @@ files:
33
33
  - README.rdoc
34
34
  - Rakefile
35
35
  - VERSION
36
- - lib/railties/tasks.rake
37
36
  - lib/seed_dump.rb
38
- - lib/version.rb
37
+ - lib/seed_dump/railtie.rb
38
+ - lib/tasks/seed_dump.rake
39
39
  - seed_dump.gemspec
40
40
  - test/seed_dump_test.rb
41
41
  - test/test_helper.rb
@@ -1,9 +0,0 @@
1
- module SeedDump
2
- module VERSION
3
- MAJOR = 0
4
- MINOR = 1
5
- TINY = 1
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end