seedbank 0.4.0 → 0.5.0.pre
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.
- 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
data/lib/seedbank/railtie.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'rails'
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
4
2
|
module Seedbank
|
5
3
|
class Railtie < Rails::Railtie
|
6
|
-
|
7
4
|
rake_tasks do
|
8
|
-
Seedbank.seeds_root = File.expand_path('db/seeds', Rails.root)
|
9
5
|
Seedbank.load_tasks
|
10
6
|
end
|
11
|
-
|
12
7
|
end
|
13
|
-
end
|
8
|
+
end
|
data/lib/seedbank/runner.rb
CHANGED
@@ -1,33 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Seedbank
|
2
3
|
class Runner
|
3
|
-
|
4
4
|
def initialize
|
5
5
|
@_memoized = {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def let(name, &block)
|
9
|
-
name = String(name)
|
10
|
-
|
11
|
-
raise ArgumentError.new("#{name} is already defined") if respond_to?(name, true)
|
12
|
-
|
13
|
-
__eigenclass.instance_exec(name) do |name|
|
14
|
-
define_method(name) do
|
15
|
-
@_memoized.fetch(name) { |key| @_memoized[key] = instance_eval(&block) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def let!(name, &block)
|
22
|
-
let(name, &block)
|
23
|
-
send name
|
24
|
-
end
|
25
|
-
|
26
|
-
def evaluate(seed_task, seed_file)
|
27
|
-
@_seed_task = seed_task
|
28
|
-
instance_eval(File.read(seed_file), seed_file)
|
29
|
-
end
|
30
|
-
|
31
8
|
# Run this seed after the specified dependencies have run
|
32
9
|
# @param dependencies [Array] seeds to run before the block is executed
|
33
10
|
#
|
@@ -42,26 +19,36 @@ module Seedbank
|
|
42
19
|
#
|
43
20
|
# Would look for a db/seeds/shared/users.seeds.rb seed and execute it.
|
44
21
|
def after(*dependencies, &block)
|
45
|
-
dependencies.
|
46
|
-
|
47
|
-
dependent_task_name = @_seed_task.name + ':body'
|
22
|
+
depends_on = dependencies.flat_map { |dep| "db:seed:#{dep}" }
|
23
|
+
dependent_task_name = @_seed_task.name + ':body'
|
48
24
|
|
49
25
|
if Rake::Task.task_defined?(dependent_task_name)
|
50
26
|
dependent_task = Rake::Task[dependent_task_name]
|
51
27
|
else
|
52
|
-
dependent_task = Rake::Task.define_task(dependent_task_name =>
|
28
|
+
dependent_task = Rake::Task.define_task(dependent_task_name => depends_on, &block)
|
53
29
|
end
|
54
30
|
|
55
31
|
dependent_task.invoke
|
56
32
|
end
|
57
33
|
|
58
|
-
|
34
|
+
def let(name, &block)
|
35
|
+
name = String(name)
|
36
|
+
|
37
|
+
raise ArgumentError, "#{name} is already defined" if respond_to?(name, true)
|
59
38
|
|
60
|
-
|
61
|
-
|
62
|
-
self
|
39
|
+
define_singleton_method(name) do
|
40
|
+
@_memoized.fetch(name) { |key| @_memoized[key] = instance_exec(&block) }
|
63
41
|
end
|
64
42
|
end
|
65
43
|
|
44
|
+
def let!(name, &block)
|
45
|
+
let(name, &block)
|
46
|
+
public_send name
|
47
|
+
end
|
48
|
+
|
49
|
+
def evaluate(seed_task, seed_file)
|
50
|
+
@_seed_task = seed_task
|
51
|
+
instance_eval(File.read(seed_file), seed_file)
|
52
|
+
end
|
66
53
|
end
|
67
54
|
end
|
data/lib/seedbank/version.rb
CHANGED
data/lib/tasks/seed.rake
CHANGED
@@ -1,42 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
namespace :db do
|
2
|
-
|
3
|
-
include Seedbank::DSL
|
4
|
-
|
5
|
-
base_dependencies = ['db:seed:original']
|
3
|
+
using Seedbank::DSL
|
6
4
|
override_dependency = ['db:seed:common']
|
7
5
|
|
8
6
|
namespace :seed do
|
9
7
|
# Create seed tasks for all the seeds in seeds_path and add them to the dependency
|
10
8
|
# list along with the original db/seeds.rb.
|
11
|
-
common_dependencies =
|
9
|
+
common_dependencies = seed_tasks_matching(Seedbank.matcher)
|
10
|
+
|
11
|
+
# Only add the original seeds if db/seeds.rb exists.
|
12
|
+
if original_seeds_file
|
13
|
+
define_seed_task original_seeds_file, :original
|
14
|
+
common_dependencies.unshift('db:seed:original')
|
15
|
+
end
|
12
16
|
|
13
|
-
desc "Load the seed data from db/seeds.rb and db/seeds
|
14
|
-
task 'common' =>
|
17
|
+
desc "Load the seed data from db/seeds.rb and db/seeds/#{Seedbank.matcher}."
|
18
|
+
task 'common' => common_dependencies
|
15
19
|
|
16
20
|
# Glob through the directories under seeds_path and create a task for each adding it to the dependency list.
|
17
21
|
# Then create a task for the environment
|
18
22
|
glob_seed_files_matching('/*/').each do |directory|
|
19
23
|
environment = File.basename(directory)
|
20
24
|
|
21
|
-
environment_dependencies =
|
25
|
+
environment_dependencies = seed_tasks_matching(environment, Seedbank.matcher)
|
22
26
|
|
23
|
-
desc "Load the seed data from db/seeds.rb, db/seeds
|
27
|
+
desc "Load the seed data from db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/#{environment}/#{Seedbank.matcher}."
|
24
28
|
task environment => ['db:seed:common'] + environment_dependencies
|
25
29
|
|
26
30
|
override_dependency << "db:seed:#{environment}" if defined?(Rails) && Rails.env == environment
|
27
31
|
end
|
28
|
-
|
29
|
-
if Rails.version > '4'
|
30
|
-
original_seeds_file = Rails.application.paths["db/seeds.rb"].existent.first
|
31
|
-
elsif Rails.version > '3.1'
|
32
|
-
original_seeds_file = Rails.application.paths["db/seeds"].existent.first
|
33
|
-
else
|
34
|
-
original_seeds_file = Rails.root.join("db","seeds").children.first.to_s
|
35
|
-
end
|
36
|
-
define_seed_task original_seeds_file, :original if original_seeds_file
|
37
32
|
end
|
38
33
|
|
39
34
|
# Override db:seed to run all the common and environments seeds plus the original db:seed.
|
40
|
-
desc
|
41
|
-
|
35
|
+
desc %(Load the seed data from db/seeds.rb, db/seeds/#{Seedbank.matcher} and db/seeds/ENVIRONMENT/#{Seedbank.matcher}.
|
36
|
+
ENVIRONMENT is the current Rails.env.)
|
37
|
+
override_seed_task seed: override_dependency
|
42
38
|
end
|
data/seedbank.gemspec
CHANGED
@@ -1,59 +1,38 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Extends Rails seeds to split out complex seeds into their own file
|
19
|
-
and have different seeds for each environment.
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'seedbank/version'
|
6
|
+
require 'English'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'seedbank'
|
10
|
+
spec.version = Seedbank::VERSION
|
11
|
+
spec.authors = ['James McCarthy']
|
12
|
+
spec.email = ['[james2mccarthy@gmail.com']
|
13
|
+
spec.required_ruby_version = '>= 2.1'
|
14
|
+
spec.summary = 'Generate seeds data for your Ruby application.'
|
15
|
+
spec.description = %{
|
16
|
+
Adds simple rake commands for seeding your database. Simple dependencies let you organise your seeds.
|
17
|
+
If you are using Rails, Seedbank extends Rails seeds and lets you add seeds for each environment.
|
20
18
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
s.license = "MIT"
|
26
|
-
|
27
|
-
s.files = `git ls-files`.split("\n")
|
28
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
29
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
30
|
-
s.require_paths = ["lib"]
|
19
|
+
spec.date = `git log -1 --format="%cd" --date=short lib/seedbank/version.rb`
|
20
|
+
spec.homepage = 'http://github.com/james2m/seedbank'
|
21
|
+
spec.license = 'MIT'
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
]
|
23
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
37
27
|
|
38
|
-
|
39
|
-
|
28
|
+
spec.rdoc_options = ['--charset=UTF-8']
|
29
|
+
spec.extra_rdoc_files = ['MIT-LICENSE', 'README.md']
|
40
30
|
|
41
|
-
|
42
|
-
================================================================================
|
31
|
+
spec.add_dependency 'rake', '>= 10.0'
|
43
32
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
require 'seedbank'
|
50
|
-
Seedbank.load_tasks if defined?(Seedbank)
|
51
|
-
|
52
|
-
Rails 3.x and 4.x
|
53
|
-
---------
|
54
|
-
Your work here is done!
|
55
|
-
|
56
|
-
================================================================================
|
57
|
-
}
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
34
|
+
spec.add_development_dependency 'rails', '~> 4.2'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
spec.add_development_dependency 'm', '~> 1.5'
|
37
|
+
spec.add_development_dependency 'byebug', '~> 9.0'
|
58
38
|
end
|
59
|
-
|
data/test/dummy/Rakefile
CHANGED
data/test/dummy/config.ru
CHANGED
@@ -1,29 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require File.expand_path('../boot', __FILE__)
|
2
3
|
|
3
|
-
|
4
|
-
require "active_record/railtie"
|
5
|
-
|
6
|
-
Bundler.require if defined?(Bundler)
|
7
|
-
require 'seedbank'
|
4
|
+
Bundler.require(:default, Rails.env)
|
8
5
|
|
9
6
|
module Dummy
|
10
7
|
class Application < Rails::Application
|
11
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
12
|
-
config.encoding = "utf-8"
|
13
|
-
|
14
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
15
|
-
config.filter_parameters += [:password]
|
16
|
-
|
17
|
-
# Use SQL instead of Active Record's schema dumper when creating the database.
|
18
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
19
|
-
# like if you have constraints or database-specific column types
|
20
|
-
# config.active_record.schema_format = :sql
|
21
|
-
|
22
|
-
# Enforce whitelist mode for mass assignment.
|
23
|
-
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
24
|
-
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
25
|
-
# parameters by using an attr_accessible or attr_protected declaration.
|
26
|
-
config.active_record.whitelist_attributes = true
|
27
8
|
end
|
28
9
|
end
|
29
|
-
|
data/test/dummy/config/boot.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rubygems'
|
2
3
|
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
3
4
|
|
@@ -7,4 +8,4 @@ if File.exist?(gemfile)
|
|
7
8
|
Bundler.setup
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
+
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Dummy::Application.configure do
|
2
3
|
# Settings specified here will take precedence over those in config/application.rb
|
3
4
|
|
@@ -5,12 +6,13 @@ Dummy::Application.configure do
|
|
5
6
|
# every request. This slows down response time but is perfect for development
|
6
7
|
# since you don't have to restart the web server when you make code changes.
|
7
8
|
config.cache_classes = false
|
9
|
+
config.eager_load = false
|
8
10
|
|
9
11
|
# Log error messages when you accidentally call methods on nil.
|
10
12
|
config.whiny_nils = true
|
11
13
|
|
12
14
|
# Show full error reports and disable caching
|
13
|
-
config.consider_all_requests_local
|
15
|
+
config.consider_all_requests_local = true
|
14
16
|
config.action_controller.perform_caching = false
|
15
17
|
|
16
18
|
# Print deprecation notices to the Rails logger
|
@@ -19,16 +21,10 @@ Dummy::Application.configure do
|
|
19
21
|
# Only use best-standards-support built into browsers
|
20
22
|
config.action_dispatch.best_standards_support = :builtin
|
21
23
|
|
22
|
-
# Raise exception on mass assignment protection for Active Record models
|
23
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
24
|
-
|
25
24
|
# Log the query plan for queries taking more than this (works
|
26
25
|
# with SQLite, MySQL, and PostgreSQL)
|
27
26
|
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
28
27
|
|
29
28
|
# Do not compress assets
|
30
29
|
config.assets.compress = false
|
31
|
-
|
32
|
-
# Expands the lines which load the assets
|
33
|
-
config.assets.debug = true
|
34
30
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Dummy::Application.configure do
|
2
3
|
# Settings specified here will take precedence over those in config/application.rb
|
3
4
|
|
@@ -6,26 +7,20 @@ Dummy::Application.configure do
|
|
6
7
|
# your test database is "scratch space" for the test suite and is wiped
|
7
8
|
# and recreated between test runs. Don't rely on the data there!
|
8
9
|
config.cache_classes = true
|
9
|
-
|
10
|
-
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.serve_static_assets = true
|
12
|
-
config.static_cache_control = "public, max-age=3600"
|
10
|
+
config.eager_load = false
|
13
11
|
|
14
12
|
# Log error messages when you accidentally call methods on nil
|
15
13
|
config.whiny_nils = true
|
16
14
|
|
17
15
|
# Show full error reports and disable caching
|
18
|
-
config.consider_all_requests_local
|
16
|
+
config.consider_all_requests_local = true
|
19
17
|
config.action_controller.perform_caching = false
|
20
18
|
|
21
19
|
# Raise exceptions instead of rendering exception templates
|
22
20
|
config.action_dispatch.show_exceptions = false
|
23
21
|
|
24
22
|
# Disable request forgery protection in test environment
|
25
|
-
config.action_controller.allow_forgery_protection
|
26
|
-
|
27
|
-
# Raise exception on mass assignment protection for Active Record models
|
28
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
23
|
+
config.action_controller.allow_forgery_protection = false
|
29
24
|
|
30
25
|
# Print deprecation notices to the stderr
|
31
26
|
config.active_support.deprecation = :stderr
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Be sure to restart your server when you modify this file.
|
2
3
|
|
3
|
-
Dummy::Application.config.session_store :cookie_store, :
|
4
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
5
|
|
5
6
|
# Use the database for sessions instead of the cookie-based default,
|
6
7
|
# which shouldn't be used to store highly confidential information
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Be sure to restart your server when you modify this file.
|
2
3
|
#
|
3
4
|
# This file contains settings for ActionController::ParamsWrapper which
|
@@ -5,7 +6,7 @@
|
|
5
6
|
|
6
7
|
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
8
|
ActiveSupport.on_load(:action_controller) do
|
8
|
-
wrap_parameters :
|
9
|
+
wrap_parameters format: [:json]
|
9
10
|
end
|
10
11
|
|
11
12
|
# Disable root element in JSON by default.
|
data/test/dummy/config/routes.rb
CHANGED
data/test/dummy/db/seeds.rb
CHANGED