seedbank 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +71 -0
- data/Rakefile +23 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/seedbank.rb +24 -0
- data/lib/seedbank/dsl.rb +29 -0
- data/lib/seedbank/railtie.rb +12 -0
- data/lib/seedbank/task.rb +9 -0
- data/lib/seedbank/task_manager.rb +10 -0
- data/lib/tasks/seed.rake +31 -0
- data/rails/init.rb +2 -0
- data/seedbank.gemspec +28 -0
- data/test/seedbank_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +107 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 [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.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
Seedbank
|
2
|
+
========
|
3
|
+
|
4
|
+
Seedbank allows you to structure your Rails seed data instead of having it all dumped into one large file.
|
5
|
+
|
6
|
+
Seedbank renames the original db:seed rake task to db:seed:original and makes it a dependency for all the other seeds. A new db:seed task is created that is dependent on db:seed:original, all the seeds in db/seeds plus all the seeds in the current Rails environment.
|
7
|
+
|
8
|
+
Example
|
9
|
+
=======
|
10
|
+
|
11
|
+
Your Seedbank seeds follow this structure;
|
12
|
+
|
13
|
+
db/seeds/
|
14
|
+
bar.seeds.rb
|
15
|
+
develpment/
|
16
|
+
users.seeds.rb
|
17
|
+
foo.seeds.rb
|
18
|
+
|
19
|
+
This would generate the following Rake tasks
|
20
|
+
|
21
|
+
rake db:seed # Loads the original seeds in db/seeds.rb followed by db/seeds/*.seeds.rb then db/seeds/environment/*.seeds.rb
|
22
|
+
rake db:seed:bar # Loads seeds from bar.seeds.rb
|
23
|
+
rake db:seed:development # Load just the seeds for the development environment
|
24
|
+
rake db:seed:development:users # Loads seeds from development/users.seeds.rb
|
25
|
+
rake db:seed:foo # Loads seeds from foo.seeds.rb
|
26
|
+
rake db:seed:original # Load the seed data from db/seeds.rb
|
27
|
+
|
28
|
+
Therefor assuming RAILS_ENV is not set or is 'development'
|
29
|
+
|
30
|
+
$ rake db:seed
|
31
|
+
|
32
|
+
would load the seeds in db/seeds.rb, db/seeds/bar.seeds.rb, db/seeds/foo.seeds/rb and db/seeds/development/users.seeds.rb. Whereas
|
33
|
+
|
34
|
+
$ RAILS_ENV=production db:seed
|
35
|
+
|
36
|
+
would load the seeds in db/seeds.rb, db/seeds/bar.seeds.rb and db/seeds/foo.seeds/rb
|
37
|
+
|
38
|
+
Installation
|
39
|
+
============
|
40
|
+
|
41
|
+
### Rails 3.x
|
42
|
+
|
43
|
+
Add the seedbank gem to your Gemfile. In Gemfile:
|
44
|
+
|
45
|
+
gem "seedbank"
|
46
|
+
|
47
|
+
That's it!
|
48
|
+
|
49
|
+
### Rails 2.x
|
50
|
+
|
51
|
+
Add the seedbank gem to your app. In config/environment.rb:
|
52
|
+
|
53
|
+
config.gem 'seedbamk'
|
54
|
+
|
55
|
+
Then in the bottom of your applications Rakefile:
|
56
|
+
|
57
|
+
Seedbank.load_tasks
|
58
|
+
|
59
|
+
Note on Patches/Pull Request
|
60
|
+
============================
|
61
|
+
|
62
|
+
* Fork the project.
|
63
|
+
* Make your feature addition or bug fix.
|
64
|
+
* Add tests for it (when I have some). This is important so I don't break it in a future version unintentionally.
|
65
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but
|
66
|
+
bump version in a commit by itself I can ignore it when I pull)
|
67
|
+
* Send me a pull request. Bonus points for topic branches.
|
68
|
+
|
69
|
+
Copyright
|
70
|
+
=========
|
71
|
+
Copyright (c) 2011 James McCarthy, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
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 seedbank 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 seedbank plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'Seedbank'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/seedbank.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'seedbank/dsl'
|
2
|
+
require 'seedbank/task'
|
3
|
+
require 'seedbank/task_manager'
|
4
|
+
|
5
|
+
if defined?(Rake)
|
6
|
+
Rake::Task.extend(Seedbank::Task)
|
7
|
+
Rake::Application.send(:include, Seedbank::TaskManager)
|
8
|
+
end
|
9
|
+
|
10
|
+
module Seedbank
|
11
|
+
|
12
|
+
@@seeds_root = 'db/seeds'
|
13
|
+
|
14
|
+
def self.seeds_root
|
15
|
+
@@seeds_root
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.load_tasks
|
19
|
+
Dir[File.expand_path("tasks/*.rake", File.dirname(__FILE__))].each { |ext| load ext }
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'seedbank/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
|
23
|
+
|
24
|
+
end
|
data/lib/seedbank/dsl.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Seedbank
|
2
|
+
module DSL
|
3
|
+
|
4
|
+
def override_task(*args, &block)
|
5
|
+
name, params, deps = Rake.application.resolve_args(args.dup)
|
6
|
+
fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
|
7
|
+
new_name = "#{fq_name}:original"
|
8
|
+
Rake::Task.rename_task(fq_name, new_name)
|
9
|
+
Rake::Task.define_task(*args, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Creates a task namespaced in @seeds_path
|
13
|
+
def define_seed_task(seed_file)
|
14
|
+
relative_root = seed_file.sub(seeds_root + '/', '')
|
15
|
+
scopes = File.dirname(relative_root).gsub(/^\./, '').split('/').unshift('seed')
|
16
|
+
fq_name = scopes.push(File.basename(seed_file, '.seeds.rb')).join(':')
|
17
|
+
|
18
|
+
args = { fq_name => 'db:abort_if_pending_migrations' }
|
19
|
+
task = Rake::Task.define_task(args) { load(seed_file) if File.exist?(seed_file) }
|
20
|
+
task.add_description "Loads seeds from #{relative_root}"
|
21
|
+
fq_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def seeds_root
|
25
|
+
Seedbank.seeds_root
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/tasks/seed.rake
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
namespace :db do
|
2
|
+
|
3
|
+
include Seedbank::DSL
|
4
|
+
|
5
|
+
base_dependencies = ['db:seed:original']
|
6
|
+
|
7
|
+
# Create seed tasks for all the seeds in seeds_path and add them to the dependency
|
8
|
+
# list along with the original db/seeds.rb.
|
9
|
+
Dir.glob(File.join(seeds_root, '*.seeds.rb')).each do |seed_file|
|
10
|
+
base_dependencies << define_seed_task(seed_file)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Change db:seed task to run all the base seeds tasks defined above.
|
14
|
+
desc "Loads the original seeds in db/seeds.rb followed by db/seeds/*.seeds.rb then db/seeds/environment/*.seeds.rb"
|
15
|
+
override_task :seed => base_dependencies + ["db:seed:#{Rails.env}"]
|
16
|
+
|
17
|
+
# Glob through the directories under seeds_path assuming they are all environments
|
18
|
+
# and create a task for each and add it to the dependency list. Then create a task
|
19
|
+
# for the environment
|
20
|
+
Dir[seeds_root + '/*/'].each do |e|
|
21
|
+
environment = File.basename(e)
|
22
|
+
|
23
|
+
environment_dependencies = []
|
24
|
+
Dir.glob(File.join(seeds_root, environment, '*.seeds.rb')).each do |seed_file|
|
25
|
+
environment_dependencies << define_seed_task(seed_file)
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Load just the seeds for the #{environment} environment"
|
29
|
+
task ['seed', environment] => base_dependencies + environment_dependencies
|
30
|
+
end
|
31
|
+
end
|
data/rails/init.rb
ADDED
data/seedbank.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{seedbank}
|
3
|
+
s.version = "0.0.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">=1.2.0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["James McCarthy"]
|
7
|
+
s.date = %q{2011-03-20}
|
8
|
+
s.description = %q{Extends Rails seeds to split out complex seeds into multiple
|
9
|
+
seed files and lets each environment load it's own seeds.}
|
10
|
+
s.email = %q{james2mccarthy@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"MIT-LICENSE",
|
13
|
+
"README.md"
|
14
|
+
]
|
15
|
+
s.files = Dir.glob('**/*') - Dir.glob('seedbank*.gem')
|
16
|
+
s.homepage = %q{http://github.com/james2m/seedbank}
|
17
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubygems_version = %q{1.3.5}
|
20
|
+
s.summary = %q{Extends Rails seeds to split out complex seeds into their own file
|
21
|
+
and have different seeds per environment.}
|
22
|
+
s.test_files = Dir.glob('test/**/*')
|
23
|
+
|
24
|
+
s.add_runtime_dependency('rails', ">=2.3.5")
|
25
|
+
s.add_development_dependency('rails', '>=2.3.5')
|
26
|
+
s.add_development_dependency('test-unit')
|
27
|
+
end
|
28
|
+
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seedbank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James McCarthy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-20 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.3.5
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.3.5
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: test-unit
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
description: |-
|
50
|
+
Extends Rails seeds to split out complex seeds into multiple
|
51
|
+
seed files and lets each environment load it's own seeds.
|
52
|
+
email: james2mccarthy@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- MIT-LICENSE
|
59
|
+
- README.md
|
60
|
+
files:
|
61
|
+
- init.rb
|
62
|
+
- install.rb
|
63
|
+
- lib/seedbank/dsl.rb
|
64
|
+
- lib/seedbank/railtie.rb
|
65
|
+
- lib/seedbank/task.rb
|
66
|
+
- lib/seedbank/task_manager.rb
|
67
|
+
- lib/seedbank.rb
|
68
|
+
- lib/tasks/seed.rake
|
69
|
+
- MIT-LICENSE
|
70
|
+
- rails/init.rb
|
71
|
+
- Rakefile
|
72
|
+
- README.md
|
73
|
+
- seedbank.gemspec
|
74
|
+
- test/seedbank_test.rb
|
75
|
+
- test/test_helper.rb
|
76
|
+
- uninstall.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/james2m/seedbank
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.2.0
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.5.0
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Extends Rails seeds to split out complex seeds into their own file and have different seeds per environment.
|
105
|
+
test_files:
|
106
|
+
- test/seedbank_test.rb
|
107
|
+
- test/test_helper.rb
|