seed_dump 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ end
19
19
  require 'rake/testtask'
20
20
  Rake::TestTask.new(:test) do |test|
21
21
  test.libs << 'lib' << 'test'
22
- test.pattern = 'test/**/test_*.rb'
22
+ test.pattern = 'test/*_test.rb'
23
23
  test.verbose = true
24
24
  end
25
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -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
@@ -1,15 +1,18 @@
1
1
  module SeedDump
2
2
  class Perform
3
3
 
4
- @opts = {}
5
- @ar_options = {}
6
- @indent = ""
7
- @models = []
8
- @seed_rb = ""
9
- @id_set_string = ""
10
- @verbose = true
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 self.setup(env)
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.constantize }
24
+ @opts['models'] = @opts['models'].split(',').collect {|x| x.underscore.singularize.camelize }
22
25
  end
23
26
 
24
- def self.loadModels
25
- Dir['app/models/*.rb'].sort.each do |f|
26
- model = File.basename(f, '.*').camelize.constantize
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 self.dumpAttribute(a_s,r,k,v)
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 self.dumpModel(model)
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 self.dumpModels
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 self.writeFile
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 self.run(env)
81
+ def run(env)
79
82
 
80
83
  setup env
81
84
 
@@ -3,7 +3,7 @@ namespace :db do
3
3
  desc "Dump records from the database into db/seeds.rb"
4
4
  task :dump => :environment do
5
5
 
6
- SeedDump::Perform::run(ENV)
6
+ SeedDump::Perform.new.run(ENV)
7
7
 
8
8
  end
9
9
  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.3.2"
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-05-22}
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
  ]
@@ -0,0 +1,10 @@
1
+ # lo & behold! I am a YAML comment!
2
+ david:
3
+ name: David Heinemeier Hansson
4
+ birthday: 1979-10-15
5
+ profession: Systems development
6
+
7
+ steve:
8
+ name: Steve Ross Kellock
9
+ birthday: 1974-09-27
10
+ profession: guy with keyboard
@@ -3,6 +3,6 @@ require 'test_helper'
3
3
  class SeedDumpTest < ActiveSupport::TestCase
4
4
  # Replace this with your real tests.
5
5
  test "test WITH_ID" do
6
- assert true
6
+ assert false
7
7
  end
8
8
  end
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.2
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-05-22 00:00:00.000000000 +02:00
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