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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.hound.yml +3 -0
  4. data/.rubocop.yml +7 -0
  5. data/.rubocop_todo.yml +29 -0
  6. data/.travis.yml +7 -9
  7. data/Gemfile +5 -4
  8. data/README.md +49 -25
  9. data/Rakefile +2 -1
  10. data/TODO.txt +3 -3
  11. data/gemfiles/rake10.gemfile +0 -2
  12. data/gemfiles/{rake0.9.gemfile → rake11.gemfile} +2 -3
  13. data/lib/seedbank.rb +15 -6
  14. data/lib/seedbank/dsl.rb +65 -43
  15. data/lib/seedbank/railtie.rb +2 -7
  16. data/lib/seedbank/runner.rb +19 -32
  17. data/lib/seedbank/version.rb +2 -1
  18. data/lib/tasks/seed.rake +16 -20
  19. data/seedbank.gemspec +32 -53
  20. data/test/dummy/Rakefile +1 -0
  21. data/test/dummy/app/controllers/application_controller.rb +1 -0
  22. data/test/dummy/config.ru +2 -1
  23. data/test/dummy/config/application.rb +2 -22
  24. data/test/dummy/config/boot.rb +2 -1
  25. data/test/dummy/config/environment.rb +1 -0
  26. data/test/dummy/config/environments/development.rb +3 -7
  27. data/test/dummy/config/environments/test.rb +4 -9
  28. data/test/dummy/config/initializers/secret_token.rb +1 -0
  29. data/test/dummy/config/initializers/session_store.rb +2 -1
  30. data/test/dummy/config/initializers/wrap_parameters.rb +2 -1
  31. data/test/dummy/config/routes.rb +1 -0
  32. data/test/dummy/db/seeds.rb +1 -0
  33. data/test/dummy/db/seeds/circular1.seeds.rb +2 -1
  34. data/test/dummy/db/seeds/circular2.seeds.rb +2 -1
  35. data/test/dummy/db/seeds/dependency.seeds.rb +1 -0
  36. data/test/dummy/db/seeds/dependency2.seeds.rb +1 -0
  37. data/test/dummy/db/seeds/dependent.seeds.rb +2 -1
  38. data/test/dummy/db/seeds/dependent_on_nested.seeds.rb +2 -1
  39. data/test/dummy/db/seeds/dependent_on_several.seeds.rb +2 -1
  40. data/test/dummy/db/seeds/development/users.seeds.rb +1 -0
  41. data/test/dummy/db/seeds/no_block.seeds.rb +2 -1
  42. data/test/dummy/db/seeds/reference_memos.seeds.rb +2 -1
  43. data/test/dummy/db/seeds/with_block_memo.seeds.rb +2 -1
  44. data/test/dummy/db/seeds/with_inline_memo.seeds.rb +1 -0
  45. data/test/dummy/script/rails +3 -2
  46. data/test/lib/seedbank/dsl_test.rb +56 -73
  47. data/test/lib/seedbank/runner_test.rb +39 -46
  48. data/test/lib/tasks/seed_rake_test.rb +88 -51
  49. data/test/test_helper.rb +13 -11
  50. metadata +76 -23
  51. data/test/dummy/lib/tasks/dsl.rake +0 -4
@@ -1,13 +1,8 @@
1
- require 'seedbank'
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
@@ -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.flatten!
46
- dependencies.map! { |dep| "db:seed:#{dep}"}
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 => dependencies, &block)
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
- private
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
- def __eigenclass
61
- class << self
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Seedbank
2
- VERSION = "0.4.0"
3
+ VERSION = '0.5.0.pre'
3
4
  end
@@ -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 = glob_seed_files_matching('*.seeds.rb').sort.map { |seed_file| seed_task_from_file(seed_file) }
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/*.seeds.rb."
14
- task 'common' => base_dependencies + common_dependencies
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 = glob_seed_files_matching(environment, '*.seeds.rb').sort.map { |seed_file| seed_task_from_file(seed_file) }
25
+ environment_dependencies = seed_tasks_matching(environment, Seedbank.matcher)
22
26
 
23
- desc "Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/#{environment}/*.seeds.rb."
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 'Load the seed data from db/seeds.rb, db/seeds/*.seeds.rb and db/seeds/ENVIRONMENT/*.seeds.rb. ENVIRONMENT is the current environment in Rails.env.'
41
- override_seed_task :seed => override_dependency
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
@@ -1,59 +1,38 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "seedbank/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = %q{seedbank}
7
- s.version = Seedbank::VERSION
8
- s.date = `git log -1 --format="%cd" --date=short lib/seedbank/version.rb`
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">=1.2.0") if s.respond_to?(:required_rubygems_version=)
11
- s.rubygems_version = %q{1.3.5}
12
- s.license = "MIT"
13
-
14
- s.authors = ["James McCarthy"]
15
- s.email = %q{james2mccarthy@gmail.com}
16
- s.homepage = %q{http://github.com/james2m/seedbank}
17
- s.summary = %q{
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
- s.description = %q{
22
- Extends Rails seeds to split out complex seeds into multiple
23
- files and lets each environment have it's own seeds.
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
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.extra_rdoc_files = [
34
- "MIT-LICENSE",
35
- "README.md"
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
- s.add_development_dependency "minitest", "~> 5.0"
39
- s.add_development_dependency "rails", "~> 3.2"
28
+ spec.rdoc_options = ['--charset=UTF-8']
29
+ spec.extra_rdoc_files = ['MIT-LICENSE', 'README.md']
40
30
 
41
- s.post_install_message = %q{
42
- ================================================================================
31
+ spec.add_dependency 'rake', '>= 10.0'
43
32
 
44
- Rails 2.x
45
- ---------
46
- If you are using Seedbank with Rails 2.x you will need to place the following at
47
- the end of your Rakefile so Rubygems can load the seedbank tasks;
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
-
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
2
3
  # Add your own tasks in files placed in lib/tasks ending in .rake,
3
4
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
5
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class ApplicationController < ActionController::Base
2
3
  protect_from_forgery
3
4
  end
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  # This file is used by Rack-based servers to start the application.
2
3
 
3
- require ::File.expand_path('../config/environment', __FILE__)
4
+ require ::File.expand_path('../config/environment', __FILE__)
4
5
  run Dummy::Application
@@ -1,29 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require File.expand_path('../boot', __FILE__)
2
3
 
3
- # Pick the frameworks you want:
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
-
@@ -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
- $:.unshift File.expand_path('../../../../lib', __FILE__)
11
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Load the rails application
2
3
  require File.expand_path('../application', __FILE__)
3
4
 
@@ -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 = true
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 = true
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 = false
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,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
  # Your secret key for verifying the integrity of signed cookies.
@@ -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, :key => '_dummy_session'
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 :format => [:json]
9
+ wrap_parameters format: [:json]
9
10
  end
10
11
 
11
12
  # Disable root element in JSON by default.
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  Dummy::Application.routes.draw do
2
3
  end
@@ -1 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  FakeModel.seed('db/seeds.rb')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  after :circular2 do
2
3
  FakeModel.seed('circular1')
3
- end
4
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  after :circular1 do
2
3
  FakeModel.seed('circular2')
3
- end
4
+ end