seedbank 0.4.0 → 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.hound.yml +3 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +29 -0
- data/.travis.yml +7 -9
- data/Gemfile +5 -4
- data/README.md +49 -25
- data/Rakefile +2 -1
- data/TODO.txt +3 -3
- data/gemfiles/rake10.gemfile +0 -2
- data/gemfiles/{rake0.9.gemfile → rake11.gemfile} +2 -3
- data/lib/seedbank.rb +15 -6
- data/lib/seedbank/dsl.rb +65 -43
- data/lib/seedbank/railtie.rb +2 -7
- data/lib/seedbank/runner.rb +19 -32
- data/lib/seedbank/version.rb +2 -1
- data/lib/tasks/seed.rake +16 -20
- data/seedbank.gemspec +32 -53
- data/test/dummy/Rakefile +1 -0
- data/test/dummy/app/controllers/application_controller.rb +1 -0
- data/test/dummy/config.ru +2 -1
- data/test/dummy/config/application.rb +2 -22
- data/test/dummy/config/boot.rb +2 -1
- data/test/dummy/config/environment.rb +1 -0
- data/test/dummy/config/environments/development.rb +3 -7
- data/test/dummy/config/environments/test.rb +4 -9
- data/test/dummy/config/initializers/secret_token.rb +1 -0
- data/test/dummy/config/initializers/session_store.rb +2 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/seeds.rb +1 -0
- data/test/dummy/db/seeds/circular1.seeds.rb +2 -1
- data/test/dummy/db/seeds/circular2.seeds.rb +2 -1
- data/test/dummy/db/seeds/dependency.seeds.rb +1 -0
- data/test/dummy/db/seeds/dependency2.seeds.rb +1 -0
- data/test/dummy/db/seeds/dependent.seeds.rb +2 -1
- data/test/dummy/db/seeds/dependent_on_nested.seeds.rb +2 -1
- data/test/dummy/db/seeds/dependent_on_several.seeds.rb +2 -1
- data/test/dummy/db/seeds/development/users.seeds.rb +1 -0
- data/test/dummy/db/seeds/no_block.seeds.rb +2 -1
- data/test/dummy/db/seeds/reference_memos.seeds.rb +2 -1
- data/test/dummy/db/seeds/with_block_memo.seeds.rb +2 -1
- data/test/dummy/db/seeds/with_inline_memo.seeds.rb +1 -0
- data/test/dummy/script/rails +3 -2
- data/test/lib/seedbank/dsl_test.rb +56 -73
- data/test/lib/seedbank/runner_test.rb +39 -46
- data/test/lib/tasks/seed_rake_test.rb +88 -51
- data/test/test_helper.rb +13 -11
- metadata +76 -23
- data/test/dummy/lib/tasks/dsl.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c3bc57dd874c51ca32bccb50bba4e967882bafe
|
4
|
+
data.tar.gz: a836593c5f0ef3b9f678f6cca0161011121ec041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01bdcdf660b8633a6415e429cea98b3d9a35ff4a511d893d9f5f0bcca0e98df62645c27b6f9a37a738a862f005ebb978021d4a5fa53e18da9a58135e24ff1339
|
7
|
+
data.tar.gz: a6a6accab1ca5d1e3ff34448f5bb9bde4efbfc2af8d062f0a692ded5e1609481bdc5cb7fb3ae997bc61d84a8fe1694e836d459e87a0ebbf17c0f1fb7d168d6be
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-02-12 18:38:59 +0700 using RuboCop version 0.47.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 6
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Max: 124
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
16
|
+
# SupportedStyles: nested, compact
|
17
|
+
Style/ClassAndModuleChildren:
|
18
|
+
Exclude:
|
19
|
+
- 'test/test_helper.rb'
|
20
|
+
|
21
|
+
# Offense count: 4
|
22
|
+
Style/Documentation:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/**/*'
|
25
|
+
- 'test/**/*'
|
26
|
+
- 'lib/seedbank.rb'
|
27
|
+
- 'lib/seedbank/dsl.rb'
|
28
|
+
- 'lib/seedbank/railtie.rb'
|
29
|
+
- 'lib/seedbank/runner.rb'
|
data/.travis.yml
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
7
|
-
- 2.0.0
|
8
|
-
- 2.1.0
|
9
|
-
- jruby-18mode # JRuby in 1.8 mode
|
10
|
-
- jruby-19mode # JRuby in 1.9 mode
|
11
|
-
- rbx-2
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
6
|
+
- 2.3.1
|
12
7
|
|
13
8
|
gemfile:
|
14
|
-
- gemfiles/rake0.9.gemfile
|
15
9
|
- gemfiles/rake10.gemfile
|
10
|
+
- gemfiles/rake11.gemfile
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- gem install bundler -v '~> 1.11' --no-ri --no-rdoc
|
data/Gemfile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
source 'http://rubygems.org'
|
2
3
|
|
3
4
|
# Specify your gem's dependencies in seedbank.gemspec
|
4
5
|
gemspec
|
5
6
|
|
6
|
-
gem '
|
7
|
+
gem 'rubocop', group: :development
|
7
8
|
|
8
9
|
# for CRuby, Rubinius, including Windows and RubyInstaller
|
9
|
-
gem
|
10
|
+
gem 'sqlite3', platform: [:ruby, :mswin, :mingw]
|
10
11
|
|
11
12
|
# for JRuby
|
12
|
-
gem 'activerecord-jdbcsqlite3-adapter', :
|
13
|
+
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Seedbank
|
2
2
|
========
|
3
3
|
|
4
|
-
Seedbank allows you to structure your
|
4
|
+
Seedbank allows you to structure your apps seed data instead of having it all dumped into one large file. I find my seed data tended to fall into two categories:
|
5
5
|
|
6
6
|
1. Stuff that the entire application requires.
|
7
7
|
2. Stuff to populate my development and staging environments.
|
@@ -14,6 +14,10 @@ The reason behind Seedbank is laziness. When I checkout or re-visit a project I
|
|
14
14
|
|
15
15
|
To achieve this slothful aim, Seedbank renames the original db:seed rake task to db:seed:original, makes it a dependency for all the Seedbank seeds and adds a new db:seed task that loads all the common seeds in db/seeds plus all the seeds for the current Rails environment.
|
16
16
|
|
17
|
+
Although originally built for Rails, Seedbank can work stand alone thanks to Aleksey Ivanov.
|
18
|
+
|
19
|
+
[![Build Status](https://travis-ci.org/james2m/seedbank.svg?branch=master)](https://travis-ci.org/james2m/seedbank)
|
20
|
+
|
17
21
|
Example
|
18
22
|
=======
|
19
23
|
|
@@ -46,12 +50,16 @@ will load the seeds in `db/seeds.rb`, `db/seeds/bar.seeds.rb` and `db/seeds/foo.
|
|
46
50
|
|
47
51
|
Installation
|
48
52
|
============
|
53
|
+
|
54
|
+
Seedbank > 0.5.0 uses refinements and no longer supports rubies below 2.x. If you are using an older Ruby you'll have to stick with 0.4.0 and below.
|
55
|
+
|
56
|
+
I have also dropped support for Rubinius and JRuby. I'm happy to accept pull requests for them, but don't have the time to hack together the test environment. If you want to contribute, please ensure that he travis.yml is in line as it's the only way I will test these two environments.
|
57
|
+
|
49
58
|
### Rails 5.x
|
50
59
|
|
51
|
-
Seedbank has not been updated to work with Rails 5. I've
|
52
|
-
people are using it with no problems.
|
60
|
+
Seedbank has not been updated to work with Rails 5. I've used it with 5.x apps and am working on a new version specifically for 5.x. Other people are also reporting using it with no problems.
|
53
61
|
|
54
|
-
### Rails
|
62
|
+
### Rails 4.x and above
|
55
63
|
|
56
64
|
Add the seedbank gem to your Gemfile. In Gemfile:
|
57
65
|
|
@@ -61,21 +69,22 @@ gem "seedbank"
|
|
61
69
|
|
62
70
|
That's it!
|
63
71
|
|
64
|
-
### Rails
|
72
|
+
### Non Rails apps
|
65
73
|
|
66
|
-
|
74
|
+
Although originally built for Rails, Seedbank should work fine in other environments such as Padrino, Grape or the new new hotness. please let us know how you get on.
|
67
75
|
|
68
|
-
|
69
|
-
config.gem 'seedbank'
|
70
|
-
```
|
76
|
+
### Rails 3.x
|
71
77
|
|
72
|
-
|
78
|
+
Seedbank 0.5.0 onwards is no longer tested against Rails 3.x, that isn't to say it will not work. I
|
79
|
+
will not fix issues against Rails 3.x, but will accept tested pull requests.
|
73
80
|
|
74
|
-
|
81
|
+
### Rails 2.x
|
75
82
|
|
76
|
-
|
83
|
+
Seedbank hasn't supported Rails 2.x for some time. You'll need to use the 0.2.1 version. In your Gemfile:
|
77
84
|
|
78
|
-
|
85
|
+
```ruby
|
86
|
+
gem "seedbank", '~> 0.2.1'
|
87
|
+
```
|
79
88
|
|
80
89
|
Then in the bottom of your application's Rakefile:
|
81
90
|
|
@@ -89,7 +98,7 @@ If you vendor the gem you'll need to change the require to the specific path.
|
|
89
98
|
Usage
|
90
99
|
=====
|
91
100
|
|
92
|
-
Seeds files are just plain old Ruby executed in your
|
101
|
+
Seeds files are just plain old Ruby executed in your application environment so anything you could type into the console will work in your seeds. Seeds files have to be named with the '.seeds.rb' extension.
|
93
102
|
|
94
103
|
db/seeds/companies.seeds.rb
|
95
104
|
```ruby
|
@@ -134,24 +143,39 @@ after "development:companies" do
|
|
134
143
|
end
|
135
144
|
```
|
136
145
|
|
146
|
+
*Note* - If you experience any errors like `Don't know how to build task 'db:seed:users'`. Ensure you are specifying `after 'development:companies'` like the above example. This is the usual culprit (YMMV).
|
147
|
+
|
137
148
|
### Defining and using methods
|
138
149
|
|
139
|
-
As seed files are evaluated within
|
150
|
+
As seed files are evaluated within a single runner in dependency order, any methods defined earlier in the run will be available across dependent tasks. I
|
151
|
+
recommend keeping method definitions in the seed file that uses them. Alternatively if you have many common methods, put them into a module and extend the
|
152
|
+
runner with the module.
|
140
153
|
|
154
|
+
db/seeds/support.rb
|
141
155
|
```ruby
|
142
|
-
|
143
|
-
def
|
144
|
-
|
145
|
-
# ...
|
156
|
+
module Support
|
157
|
+
def notify(filename)
|
158
|
+
puts "Seeding: #{filename}"
|
146
159
|
end
|
147
160
|
end
|
161
|
+
```
|
148
162
|
|
149
|
-
|
150
|
-
|
151
|
-
|
163
|
+
db/seeds/common.seeds.rb
|
164
|
+
```ruby
|
165
|
+
require_relative 'support'
|
166
|
+
extend Support
|
167
|
+
|
168
|
+
notify(__FILE__)
|
152
169
|
```
|
153
170
|
|
154
|
-
|
171
|
+
To keep this dry you could make the seeds dependent on a support seed that extends the runner.
|
172
|
+
|
173
|
+
db/seeds/users.seeds.rb
|
174
|
+
```ruby
|
175
|
+
after :common do
|
176
|
+
notify(__FILE__)
|
177
|
+
end
|
178
|
+
```
|
155
179
|
|
156
180
|
Contributors
|
157
181
|
============
|
@@ -171,7 +195,7 @@ git log | grep Author | sort | uniq
|
|
171
195
|
* lulalala
|
172
196
|
* pivotal-cloudplanner
|
173
197
|
* vkill
|
174
|
-
|
198
|
+
* Aleksey Ivanov
|
175
199
|
|
176
200
|
Note on Patches/Pull Request
|
177
201
|
============================
|
@@ -185,4 +209,4 @@ Note on Patches/Pull Request
|
|
185
209
|
|
186
210
|
Copyright
|
187
211
|
=========
|
188
|
-
Copyright (c) 2011-
|
212
|
+
Copyright (c) 2011-2017 James McCarthy, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'rake'
|
3
4
|
require 'rake/testtask'
|
@@ -19,4 +20,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
19
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
20
21
|
end
|
21
22
|
|
22
|
-
task :
|
23
|
+
task default: ['test']
|
data/TODO.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
* Add generator for seeds directories
|
2
|
-
* Add
|
3
|
-
* Add
|
4
|
-
*
|
2
|
+
* Add platform independent test environment
|
3
|
+
* Add generator for seeds data?
|
4
|
+
* Add ability to add or update records in place?
|
data/gemfiles/rake10.gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in seedbank.gemspec
|
4
|
-
gemspec :path
|
4
|
+
gemspec :path=>"../"
|
5
5
|
|
6
|
-
gem 'rake', '~>
|
6
|
+
gem 'rake', '~>11.0', :group => :test
|
7
7
|
|
8
8
|
# for CRuby, Rubinius, including Windows and RubyInstaller
|
9
9
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
@@ -11,4 +11,3 @@ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
|
11
11
|
# for JRuby
|
12
12
|
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
|
13
13
|
|
14
|
-
gem 'seedbank', :path => '../'
|
data/lib/seedbank.rb
CHANGED
@@ -1,22 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'seedbank/dsl'
|
2
3
|
require 'seedbank/runner'
|
3
4
|
|
4
5
|
module Seedbank
|
5
|
-
|
6
6
|
class << self
|
7
|
+
attr_writer :application_root, :seeds_root, :nesting, :matcher
|
7
8
|
|
8
|
-
|
9
|
+
def application_root
|
10
|
+
@application_root ||= Pathname.new(Rake.application.original_dir)
|
11
|
+
end
|
9
12
|
|
10
13
|
def seeds_root
|
11
|
-
@seeds_root ||= 'db
|
14
|
+
@seeds_root ||= File.join(application_root, 'db', 'seeds')
|
15
|
+
end
|
16
|
+
|
17
|
+
def nesting
|
18
|
+
@nesting ||= 2
|
12
19
|
end
|
13
20
|
|
21
|
+
def matcher
|
22
|
+
@matcher ||= '*.seeds.rb'
|
23
|
+
end
|
14
24
|
end
|
15
25
|
|
16
26
|
def self.load_tasks
|
17
|
-
Dir[File.expand_path(
|
27
|
+
Dir[File.expand_path('../tasks/*.rake', __FILE__)].each { |ext| load ext }
|
18
28
|
end
|
19
29
|
|
20
30
|
require 'seedbank/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
|
21
|
-
|
22
|
-
end
|
31
|
+
end
|
data/lib/seedbank/dsl.rb
CHANGED
@@ -1,64 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Seedbank
|
2
3
|
module DSL
|
4
|
+
refine Object do
|
5
|
+
def override_seed_task(*args)
|
6
|
+
task_name, _, deps = Rake.application.resolve_args(args)
|
7
|
+
seed_task = Rake::Task.task_defined?(task_name) ? Rake::Task[task_name].clear : Rake::Task.define_task(task_name)
|
8
|
+
add_comment_to(seed_task, Rake.application.last_description)
|
9
|
+
add_environment_dependency(seed_task)
|
10
|
+
seed_task.enhance deps
|
11
|
+
end
|
3
12
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
13
|
+
def seed_tasks_matching(*pattern)
|
14
|
+
glob_seed_files_matching(*pattern)
|
15
|
+
.sort
|
16
|
+
.map { |seed_file| seed_task_from_file(seed_file) }
|
17
|
+
end
|
10
18
|
|
11
|
-
|
12
|
-
|
13
|
-
|
19
|
+
def seed_task_from_file(seed_file)
|
20
|
+
scopes = scope_from_seed_file(seed_file)
|
21
|
+
fq_name = scopes.push(File.basename(seed_file, '.seeds.rb')).join(':')
|
14
22
|
|
15
|
-
|
16
|
-
|
23
|
+
define_seed_task(seed_file, fq_name)
|
24
|
+
end
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
def glob_seed_files_matching(*args, &block)
|
27
|
+
Dir.glob(File.join(seeds_root, *args), &block)
|
28
|
+
end
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
def define_seed_task(seed_file, *args)
|
31
|
+
task = Rake::Task.define_task(*args) do |seed_task|
|
32
|
+
runner.evaluate(seed_task, seed_file) if File.exist?(seed_file)
|
33
|
+
end
|
25
34
|
|
26
|
-
|
27
|
-
|
28
|
-
|
35
|
+
relative_file = Pathname.new(seed_file).relative_path_from(Seedbank.application_root)
|
36
|
+
|
37
|
+
task.add_description "Load the seed data from #{relative_file}"
|
38
|
+
add_environment_dependency(task)
|
39
|
+
task.name
|
29
40
|
end
|
30
41
|
|
31
|
-
|
42
|
+
def original_seeds_file
|
43
|
+
@_seedbank_original ||= existent(Pathname.new('../seeds.rb').expand_path(seeds_root))
|
44
|
+
end
|
32
45
|
|
33
|
-
|
34
|
-
|
35
|
-
elsif Rake::Task.task_defined?(':environment')
|
36
|
-
task.enhance([':environment'])
|
46
|
+
def seeds_root
|
47
|
+
Pathname.new Seedbank.seeds_root
|
37
48
|
end
|
38
49
|
|
39
|
-
|
40
|
-
end
|
50
|
+
private
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
relative = dirname.relative_path_from(seeds_root)
|
46
|
-
relative.to_s.split(File::Separator)
|
47
|
-
end
|
52
|
+
def existent(path)
|
53
|
+
String(path) if path.exist?
|
54
|
+
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
def scope_from_seed_file(seed_file)
|
57
|
+
dirname = Pathname.new(seed_file).dirname
|
58
|
+
return [] if dirname == seeds_root
|
59
|
+
dirname
|
60
|
+
.relative_path_from(seeds_root)
|
61
|
+
.to_s
|
62
|
+
.split(File::Separator)
|
63
|
+
end
|
52
64
|
|
53
|
-
|
65
|
+
def add_environment_dependency(task)
|
66
|
+
if Rake::Task.task_defined?('db:abort_if_pending_migrations')
|
67
|
+
task.enhance(['db:abort_if_pending_migrations'])
|
68
|
+
elsif defined?(Rails)
|
69
|
+
task.enhance([:environment])
|
70
|
+
end
|
71
|
+
end
|
54
72
|
|
55
|
-
|
56
|
-
|
57
|
-
seed_task.comment = comment
|
58
|
-
else
|
59
|
-
seed_task.send :instance_variable_set, '@full_comment', comment
|
73
|
+
def runner
|
74
|
+
@_seedbank_runner ||= Seedbank::Runner.new
|
60
75
|
end
|
61
|
-
end
|
62
76
|
|
77
|
+
def add_comment_to(seed_task, comment)
|
78
|
+
if seed_task.respond_to?(:clear_comments)
|
79
|
+
seed_task.comment = comment
|
80
|
+
else
|
81
|
+
seed_task.send :instance_variable_set, '@full_comment', comment
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
63
85
|
end
|
64
86
|
end
|