db_cull 0.0.0
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/MIT-LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/db_cull.gemspec +49 -0
- data/init.rb +1 -0
- data/tasks/db_cull_tasks.rake +63 -0
- data/test/db_cull_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +64 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the db_cull plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the db_cull plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'DbCull'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'jeweler'
|
27
|
+
Jeweler::Tasks.new do |gemspec|
|
28
|
+
gemspec.name = "db_cull"
|
29
|
+
gemspec.summary = "Cull seed data from a rails db into a seeds file"
|
30
|
+
gemspec.description = "Copies data from the database into db/seeds.rb"
|
31
|
+
gemspec.email = "mikldt@gmail.com"
|
32
|
+
gemspec.homepage = "http://github.com/mikldt/db_cull"
|
33
|
+
gemspec.authors = ["Mike DiTore"]
|
34
|
+
end
|
35
|
+
Jeweler::GemcutterTasks.new
|
36
|
+
rescue LoadError
|
37
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
38
|
+
end
|
39
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/db_cull.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{db_cull}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mike DiTore"]
|
12
|
+
s.date = %q{2010-01-20}
|
13
|
+
s.description = %q{Copies data from the database into db/seeds.rb}
|
14
|
+
s.email = %q{mikldt@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"db_cull.gemspec",
|
24
|
+
"init.rb",
|
25
|
+
"tasks/db_cull_tasks.rake",
|
26
|
+
"test/db_cull_test.rb",
|
27
|
+
"test/test_helper.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/mikldt/db_cull}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Cull seed data from a rails db into a seeds file}
|
34
|
+
s.test_files = [
|
35
|
+
"test/db_cull_test.rb",
|
36
|
+
"test/test_helper.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
@@ -0,0 +1,63 @@
|
|
1
|
+
def add_to_seeds(lines)
|
2
|
+
File.open ("#{RAILS_ROOT}/db/seeds.rb", 'a') do |f|
|
3
|
+
lines.each do |l|
|
4
|
+
f.puts l
|
5
|
+
end
|
6
|
+
end
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :db do
|
11
|
+
# rake syntax is crazy.
|
12
|
+
# task name: cull
|
13
|
+
# sole argument: table
|
14
|
+
# dependency: environment task
|
15
|
+
# example: rake db:cull[person]
|
16
|
+
# result: in an empty db, you can write rake db:seed to get the data back.
|
17
|
+
desc "Copy all data from table into seeds.rb"
|
18
|
+
task :cull, [:table] => :environment do |t, args|
|
19
|
+
|
20
|
+
begin
|
21
|
+
model = args.table.classify.constantize
|
22
|
+
#model.descends_from_active_record? # no method error if not AR
|
23
|
+
rescue
|
24
|
+
puts "Error: no such ActiveRecord class."
|
25
|
+
end
|
26
|
+
|
27
|
+
unless model.nil?
|
28
|
+
lines = []
|
29
|
+
lines << "# Seeds culled from database using db_cull"
|
30
|
+
lines << "# Table: #{model}"
|
31
|
+
lines << "# Schema: #{ActiveRecord::Migrator.current_version}"
|
32
|
+
lines << "# Added: #{Time.now}"
|
33
|
+
lines << ""
|
34
|
+
|
35
|
+
create = " #{model}.create! ( "
|
36
|
+
indent = Array.new(create.size, ' ').join
|
37
|
+
|
38
|
+
count = 0
|
39
|
+
model.all.each do |record|
|
40
|
+
count += 1
|
41
|
+
prefix = create
|
42
|
+
|
43
|
+
lines << " # Retrieved from organiztion ##{record.id}"
|
44
|
+
record.attributes.each do |att, val|
|
45
|
+
next if att == model.primary_key
|
46
|
+
lines << prefix + ":#{att} = \"#{val}\","
|
47
|
+
prefix = indent
|
48
|
+
end
|
49
|
+
lines.last.chop! # get rid of that last comma
|
50
|
+
lines.last << " )"
|
51
|
+
end
|
52
|
+
lines << ""
|
53
|
+
lines << "# (end of #{model} seeds)"
|
54
|
+
lines << ""
|
55
|
+
if add_to_seeds(lines)
|
56
|
+
puts "Wrote #{count} entries to db/seeds.rb"
|
57
|
+
else
|
58
|
+
puts "Error"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: db_cull
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike DiTore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-20 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Copies data from the database into db/seeds.rb
|
17
|
+
email: mikldt@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- db_cull.gemspec
|
30
|
+
- init.rb
|
31
|
+
- tasks/db_cull_tasks.rake
|
32
|
+
- test/db_cull_test.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/mikldt/db_cull
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Cull seed data from a rails db into a seeds file
|
62
|
+
test_files:
|
63
|
+
- test/db_cull_test.rb
|
64
|
+
- test/test_helper.rb
|