potassium 5.2.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +42 -0
  3. data/.editorconfig +3 -0
  4. data/.node-version +1 -0
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +94 -0
  7. data/README.md +41 -47
  8. data/docs/DSL.md +5 -5
  9. data/lib/potassium/assets/.buildpacks +0 -1
  10. data/lib/potassium/assets/.circleci/config.yml.erb +102 -0
  11. data/lib/potassium/assets/.eslintrc.json +352 -0
  12. data/lib/potassium/assets/.github/pull_request_template.md +9 -0
  13. data/lib/potassium/assets/.pryrc +1 -1
  14. data/lib/potassium/assets/.rubocop.yml +515 -0
  15. data/lib/potassium/assets/.stylelintrc.json +46 -0
  16. data/lib/potassium/assets/Dockerfile.ci +1 -1
  17. data/lib/potassium/assets/Makefile.erb +35 -0
  18. data/lib/potassium/assets/Procfile +1 -0
  19. data/lib/potassium/assets/README.yml +60 -11
  20. data/lib/potassium/assets/active_admin/admin-component.vue +35 -0
  21. data/lib/potassium/assets/active_admin/admin_application.js +14 -0
  22. data/lib/potassium/assets/active_admin/init_activeadmin_vue.rb +10 -0
  23. data/lib/potassium/assets/app/graphql/graphql_controller.rb +55 -0
  24. data/lib/potassium/assets/app/graphql/mutations/login_mutation.rb +23 -0
  25. data/lib/potassium/assets/app/graphql/queries/base_query.rb +4 -0
  26. data/lib/potassium/assets/app/graphql/types/base/base_argument.rb +4 -0
  27. data/lib/potassium/assets/app/graphql/types/base/base_enum.rb +4 -0
  28. data/lib/potassium/assets/app/graphql/types/base/base_field.rb +5 -0
  29. data/lib/potassium/assets/app/graphql/types/base/base_input_object.rb +5 -0
  30. data/lib/potassium/assets/app/graphql/types/base/base_interface.rb +7 -0
  31. data/lib/potassium/assets/app/graphql/types/base/base_object.rb +5 -0
  32. data/lib/potassium/assets/app/graphql/types/base/base_scalar.rb +4 -0
  33. data/lib/potassium/assets/app/graphql/types/base/base_union.rb +4 -0
  34. data/lib/potassium/assets/app/graphql/types/mutation_type.rb +10 -0
  35. data/lib/potassium/assets/app/graphql/types/query_type.rb +13 -0
  36. data/lib/potassium/assets/app/javascript/app.spec.js +14 -0
  37. data/lib/potassium/assets/app/uploaders/base_uploader.rb +11 -0
  38. data/lib/potassium/assets/app/uploaders/image_uploader.rb +5 -0
  39. data/lib/potassium/assets/bin/cibuild.erb +24 -7
  40. data/lib/potassium/assets/bin/release +9 -0
  41. data/lib/potassium/assets/bin/setup.erb +3 -0
  42. data/lib/potassium/assets/config/database_mysql.yml.erb +5 -5
  43. data/lib/potassium/assets/config/database_postgresql.yml.erb +5 -5
  44. data/lib/potassium/assets/config/graphql_playground.rb +20 -0
  45. data/lib/potassium/assets/config/puma.rb +5 -1
  46. data/lib/potassium/assets/config/shrine.rb +36 -0
  47. data/lib/potassium/assets/docker-compose.ci.yml +2 -1
  48. data/lib/potassium/assets/docker-compose.yml +6 -0
  49. data/lib/potassium/assets/lib/tasks/auto_annotate_models.rake +34 -33
  50. data/lib/potassium/assets/package.json +4 -1
  51. data/lib/potassium/assets/redis.yml +1 -2
  52. data/lib/potassium/assets/sidekiq_scheduler.yml +1 -1
  53. data/lib/potassium/assets/testing/rails_helper.rb +4 -2
  54. data/lib/potassium/cli/commands/create.rb +12 -19
  55. data/lib/potassium/cli_options.rb +67 -24
  56. data/lib/potassium/helpers/docker-helpers.rb +14 -5
  57. data/lib/potassium/helpers/gem-helpers.rb +1 -1
  58. data/lib/potassium/helpers/template-helpers.rb +4 -0
  59. data/lib/potassium/newest_version_ensurer.rb +19 -36
  60. data/lib/potassium/node_version_ensurer.rb +30 -0
  61. data/lib/potassium/recipes/admin.rb +3 -3
  62. data/lib/potassium/recipes/annotate.rb +1 -1
  63. data/lib/potassium/recipes/api.rb +93 -21
  64. data/lib/potassium/recipes/background_processor.rb +38 -2
  65. data/lib/potassium/recipes/ci.rb +8 -6
  66. data/lib/potassium/recipes/data_migrate.rb +44 -0
  67. data/lib/potassium/recipes/database.rb +6 -2
  68. data/lib/potassium/recipes/database_container.rb +90 -0
  69. data/lib/potassium/recipes/draper.rb +1 -10
  70. data/lib/potassium/recipes/file_storage.rb +66 -0
  71. data/lib/potassium/recipes/front_end.rb +219 -9
  72. data/lib/potassium/recipes/github.rb +93 -15
  73. data/lib/potassium/recipes/heroku.rb +2 -1
  74. data/lib/potassium/recipes/listen.rb +7 -0
  75. data/lib/potassium/recipes/mailer.rb +14 -4
  76. data/lib/potassium/recipes/node.rb +21 -0
  77. data/lib/potassium/recipes/puma.rb +0 -3
  78. data/lib/potassium/recipes/rack_cors.rb +18 -15
  79. data/lib/potassium/recipes/rails.rb +6 -0
  80. data/lib/potassium/recipes/schedule.rb +1 -1
  81. data/lib/potassium/recipes/style.rb +21 -3
  82. data/lib/potassium/recipes/vue_admin.rb +124 -0
  83. data/lib/potassium/templates/application.rb +10 -9
  84. data/lib/potassium/version.rb +7 -4
  85. data/potassium.gemspec +9 -6
  86. data/spec/features/api_spec.rb +25 -0
  87. data/spec/features/background_processor_spec.rb +12 -1
  88. data/spec/features/data_migrate_spec.rb +14 -0
  89. data/spec/features/database_container_spec.rb +35 -0
  90. data/spec/features/draper_spec.rb +1 -6
  91. data/spec/features/file_storage_spec.rb +75 -0
  92. data/spec/features/front_end_spec.rb +88 -0
  93. data/spec/features/github_spec.rb +53 -8
  94. data/spec/features/graphql_spec.rb +71 -0
  95. data/spec/features/heroku_spec.rb +8 -5
  96. data/spec/features/mailer_spec.rb +42 -0
  97. data/spec/features/new_project_spec.rb +6 -14
  98. data/spec/features/node_spec.rb +28 -0
  99. data/spec/features/power_types_spec.rb +5 -16
  100. data/spec/features/vue_admin_spec.rb +47 -0
  101. data/spec/spec_helper.rb +5 -0
  102. data/spec/support/fake_octokit.rb +31 -0
  103. data/spec/support/potassium_test_helpers.rb +26 -8
  104. metadata +126 -45
  105. data/circle.yml +0 -12
  106. data/lib/potassium/assets/.circleci/config.yml +0 -20
  107. data/lib/potassium/assets/active_admin/active_admin.js.coffee +0 -4
  108. data/lib/potassium/assets/active_admin/init_activeadmin_angular.rb +0 -8
  109. data/lib/potassium/assets/api/api_error_concern.rb +0 -32
  110. data/lib/potassium/assets/api/base_controller.rb +0 -9
  111. data/lib/potassium/assets/api/draper_responder.rb +0 -62
  112. data/lib/potassium/assets/api/responder.rb +0 -41
  113. data/lib/potassium/assets/aws.rb +0 -1
  114. data/lib/potassium/assets/testing/paperclip.rb +0 -59
  115. data/lib/potassium/recipes/active_storage.rb +0 -40
  116. data/lib/potassium/recipes/angular_admin.rb +0 -56
  117. data/lib/potassium/recipes/aws_sdk.rb +0 -7
  118. data/lib/potassium/recipes/paperclip.rb +0 -47
  119. data/spec/features/active_storage_spec.rb +0 -30
  120. data/spec/features/front_end.rb +0 -30
@@ -1,7 +1,7 @@
1
1
  class DockerHelpers
2
2
  def initialize(compose_path)
3
3
  @compose_path = compose_path
4
- @compose = YAML.load(File.read(compose_path))
4
+ @compose = YAML.safe_load(File.read(compose_path))
5
5
  end
6
6
 
7
7
  def add_link(target_service, linked_service)
@@ -23,14 +23,23 @@ class DockerHelpers
23
23
  end
24
24
 
25
25
  def add_service(name, definition)
26
- service = {}
27
- service[name] = YAML.load(definition)
28
- @compose['services'].merge!(service)
29
- save
26
+ add_leaf('services', name, definition)
27
+ end
28
+
29
+ def add_volume(name, definition = '')
30
+ add_leaf('volumes', name, definition)
30
31
  end
31
32
 
32
33
  private
33
34
 
35
+ def add_leaf(root_name, leaf_name, definition)
36
+ leaf = {}
37
+ leaf[leaf_name] = YAML.safe_load(definition)
38
+ @compose[root_name] = {} unless @compose[root_name].is_a? Hash
39
+ @compose[root_name].merge!(leaf)
40
+ save
41
+ end
42
+
34
43
  def save
35
44
  File.open(@compose_path, 'w') { |f| f.write @compose.to_yaml }
36
45
  end
@@ -69,7 +69,7 @@ module GemHelpers
69
69
  def add_original_rails_gems
70
70
  gemfile_entries.each do |entry|
71
71
  unless entry.commented_out
72
- gather_gem(entry.name, entry.version)
72
+ gather_gem(entry.name, version: entry[:version])
73
73
  end
74
74
  end
75
75
  end
@@ -3,6 +3,10 @@ module TemplateHelpers
3
3
  @app_name || app_name_from_file
4
4
  end
5
5
 
6
+ def node_version
7
+ "#{Potassium::NODE_VERSION}.x"
8
+ end
9
+
6
10
  def load_recipe(recipe_name)
7
11
  @recipes ||= {}
8
12
  @recipes[recipe_name] ||= get_recipe_class(recipe_name.to_sym).new(self)
@@ -1,51 +1,34 @@
1
- require "term/ansicolor"
2
- require "gems"
3
- require "semantic"
4
- require "potassium/text_spinner"
1
+ require 'gems'
2
+ require 'semantic'
3
+ require 'potassium/text_spinner'
4
+
5
+ class VersionError < StandardError
6
+ end
5
7
 
6
8
  module Potassium
7
9
  class NewestVersionEnsurer
8
- include Term::ANSIColor
9
-
10
- def initialize(current_version = Potassium::VERSION)
11
- self.current_version = Semantic::Version.new(current_version)
10
+ def initialize
11
+ self.installed_version = Semantic::Version.new(Potassium::VERSION)
12
12
  self.text_spinner = Potassium::TextSpinner.new
13
13
  end
14
14
 
15
- def ensure(&success_block)
16
- spin_text("Checking your Potassium installation") { latest_version }
15
+ def ensure!
16
+ spin_text('Checking your Potassium installation') { published_version }
17
17
 
18
- self.latest_version = Semantic::Version.new(
19
- Gems.versions("potassium").first["number"]
20
- )
21
-
22
- if latest_version <= current_version
23
- up_to_date
24
- success_block.call
25
- else
26
- please_update
27
- end
18
+ self.published_version = Semantic::Version.new(Gems.versions('potassium').first['number'])
19
+ raise VersionError.new(update_message) if published_version > installed_version
28
20
  end
29
21
 
30
22
  private
31
23
 
32
- attr_accessor :latest_version, :current_version, :text_spinner
33
-
34
- def up_to_date
35
- puts green("\nYour Potassium installation is up to date.")
36
- end
24
+ attr_accessor :published_version, :installed_version, :text_spinner
37
25
 
38
- def please_update
39
- puts red("\nYour Potassium installation is not up to date.")
40
- puts red("Found: #{current_version}")
41
- puts red("Expected: #{latest_version}\n")
42
- print white("Please run: ")
43
- print green("gem update potassium ")
44
- print white("to upgrade your potassium installation.\n\n")
45
- print white("If you really need to run this outdated version of potassium anyway, ")
46
- print white("re-run this command with the ")
47
- print black("--no-version-check")
48
- puts white(" flag.")
26
+ def update_message
27
+ <<~HERE
28
+ Your potassium installation is not up to date.
29
+ The last available version is #{published_version} while the running version is #{installed_version}.
30
+ If you really need to run this outdated version of potassium, re-run this command with the `--no-version-check` flag.
31
+ HERE
49
32
  end
50
33
 
51
34
  def spin_text(message, &block)
@@ -0,0 +1,30 @@
1
+ module Potassium
2
+ class NodeVersionEnsurer
3
+ def ensure!
4
+ raise VersionError.new(install_message) if installed_node_version.nil?
5
+ raise VersionError.new(update_message) if Potassium::NODE_VERSION != installed_node_version
6
+ end
7
+
8
+ private
9
+
10
+ def installed_node_version
11
+ node_version = `node -v 2>&1`
12
+ return node_version.delete('^[0-9\.]').split('.').first if $?.success?
13
+ end
14
+
15
+ def install_message
16
+ <<~HERE
17
+ Node doesn't appear to be installed.
18
+ Please make sure you have node #{Potassium::NODE_VERSION} installed.
19
+ HERE
20
+ end
21
+
22
+ def update_message
23
+ <<~HERE
24
+ An unsupported version of node was found.
25
+ Please make sure you have node #{Potassium::NODE_VERSION} installed. Newer versions may work but potassium only supports that one.
26
+ If you really need to run potassium with a different version of node, re-run this command with the `--no-node-version-check` flag.
27
+ HERE
28
+ end
29
+ end
30
+ end
@@ -32,10 +32,10 @@ class Recipes::Admin < Rails::AppBuilder
32
32
  private
33
33
 
34
34
  def add_active_admin
35
- gather_gem 'activeadmin', '~> 1.3.0'
35
+ gather_gem 'activeadmin', '~> 2.6'
36
36
  gather_gem 'activeadmin_addons'
37
- gather_gem 'active_skin'
38
-
37
+ gather_gem 'active_skin', github: 'SoftwareBrothers/active_skin'
38
+ add_readme_section :internal_dependencies, :active_admin
39
39
  after(:gem_install, wrap_in_action: :admin_install) do
40
40
  generate "active_admin:install"
41
41
  line = "ActiveAdmin.setup do |config|"
@@ -1,7 +1,7 @@
1
1
  class Recipes::Annotate < Rails::AppBuilder
2
2
  def create
3
3
  gather_gems(:development) do
4
- gather_gem('annotate')
4
+ gather_gem('annotate', '~> 3.0')
5
5
  end
6
6
 
7
7
  template '../assets/lib/tasks/auto_annotate_models.rake',
@@ -1,43 +1,115 @@
1
1
  class Recipes::Api < Rails::AppBuilder
2
2
  def ask
3
- api_support = answer(:api) { Ask.confirm("Do you want to enable API support?") }
4
- set(:api_support, api_support)
3
+ api_interfaces = {
4
+ rest: "REST (with Power API)",
5
+ graphql: "GraphQL (beta)",
6
+ none: "None, thanks"
7
+ }
8
+ api_interface = answer(:api) do
9
+ api_interfaces.keys[Ask.list("Which API interface are you using?", api_interfaces.values)]
10
+ end
11
+ set :api, api_interface.to_sym
5
12
  end
6
13
 
7
14
  def create
8
- add_api if get(:api_support)
15
+ if get(:api) == :graphql
16
+ add_graphql
17
+ elsif get(:api) == :rest
18
+ add_power_api
19
+ end
9
20
  end
10
21
 
11
22
  def install
12
- add_api
23
+ ask
24
+ create
13
25
  end
14
26
 
15
27
  def installed?
16
- gem_exists?(/versionist/)
28
+ gem_exists?(/power_api/) || gem_exists?(/graphql/)
17
29
  end
18
30
 
19
31
  private
20
32
 
21
- def add_api
22
- gather_gem 'versionist'
23
- gather_gem 'responders'
24
- gather_gem 'active_model_serializers', '~> 0.9.3'
25
- gather_gem 'simple_token_authentication', '~> 1.0'
33
+ def add_power_api
34
+ gather_gem 'power_api'
35
+
36
+ gather_gems(:development, :test) do
37
+ gather_gem 'rswag-specs'
38
+ end
39
+
40
+ add_readme_section :internal_dependencies, :power_api
41
+
42
+ after(:gem_install) do
43
+ generate "power_api:install"
44
+ end
45
+ end
46
+
47
+ def add_graphql
48
+ gather_gem 'graphql'
49
+ if get(:authentication)
50
+ gather_gem 'jwt'
51
+ end
52
+ gather_gems(:development, :test) do
53
+ gather_gem 'graphql_playground-rails'
54
+ end
26
55
 
27
56
  after(:gem_install) do
28
- line = "Rails.application.routes.draw do\n"
29
- insert_into_file "config/routes.rb", after: line do
30
- <<-HERE.gsub(/^ {8}/, '')
31
- scope path: '/api' do
32
- api_version(module: "Api::V1", path: { value: "v1" }, defaults: { format: 'json' }) do
33
- end
34
- end
35
- HERE
57
+ generate "graphql:install --skip_graphiql"
58
+ playground_route = <<~HEREDOC
59
+ \n
60
+ if Rails.env.development?
61
+ mount GraphqlPlayground::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
62
+ end
63
+ HEREDOC
64
+ inject_into_file(
65
+ 'config/routes.rb',
66
+ playground_route,
67
+ after: 'post "/graphql", to: "graphql#execute"'
68
+ )
69
+ copy_file(
70
+ "../assets/config/graphql_playground.rb",
71
+ "config/initializers/graphql_playground.rb"
72
+ )
73
+ remove_dir 'app/graphql/types'
74
+ directory '../assets/app/graphql/types', 'app/graphql/types'
75
+ gsub_file 'app/graphql/mutations/base_mutation.rb', 'Types::Base', 'Types::Base::Base'
76
+ directory '../assets/app/graphql/queries', 'app/graphql/queries'
77
+ gsub_file 'app/graphql/mutations/base_mutation.rb', 'RelayClassic', ''
78
+ gsub_file(
79
+ 'app/graphql/mutations/base_mutation.rb',
80
+ " input_object_class Types::Base::BaseInputObject\n", ''
81
+ )
82
+
83
+ if get(:authentication)
84
+ copy_file(
85
+ '../assets/app/graphql/graphql_controller.rb',
86
+ 'app/controllers/graphql_controller.rb',
87
+ force: true
88
+ )
89
+ gsub_file(
90
+ 'app/controllers/graphql_controller.rb',
91
+ 'GqlSampleSchema',
92
+ "#{get(:titleized_app_name).delete(' ')}Schema"
93
+ )
94
+ copy_file(
95
+ '../assets/app/graphql/mutations/login_mutation.rb',
96
+ 'app/graphql/mutations/login_mutation.rb'
97
+ )
98
+ inject_into_file(
99
+ 'app/graphql/types/mutation_type.rb',
100
+ "\n field :login, mutation: Mutations::LoginMutation",
101
+ after: 'class MutationType < Types::Base::BaseObject'
102
+ )
103
+ append_to_file(".env.development", "HMAC_SECRET=\n")
36
104
  end
37
105
 
38
- copy_file '../assets/api/base_controller.rb', 'app/controllers/api/v1/base_controller.rb'
39
- copy_file '../assets/api/api_error_concern.rb', 'app/controllers/concerns/api_error_concern.rb'
40
- copy_file '../assets/api/responder.rb', 'app/responders/api_responder.rb'
106
+ inject_into_file(
107
+ 'app/controllers/graphql_controller.rb',
108
+ "\n\n skip_before_action :verify_authenticity_token",
109
+ after: '# protect_from_forgery with: :null_session'
110
+ )
111
+
112
+ add_readme_section :internal_dependencies, :graphql
41
113
  end
42
114
  end
43
115
  end
@@ -12,7 +12,11 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder
12
12
  end
13
13
 
14
14
  def create
15
- add_sidekiq if get(:background_processor)
15
+ if get(:background_processor)
16
+ add_sidekiq
17
+ add_docker_compose_redis_config
18
+ set_redis_dot_env
19
+ end
16
20
  end
17
21
 
18
22
  def install
@@ -26,6 +30,35 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder
26
30
  gem_exists?(/sidekiq/)
27
31
  end
28
32
 
33
+ private
34
+
35
+ def add_docker_compose_redis_config
36
+ compose = DockerHelpers.new('docker-compose.yml')
37
+
38
+ service_definition =
39
+ <<~YAML
40
+ image: redis
41
+ ports:
42
+ - 6379
43
+ volumes:
44
+ - redis_data:/data
45
+ YAML
46
+
47
+ compose.add_service('redis', service_definition)
48
+ compose.add_volume('redis_data')
49
+ end
50
+
51
+ def set_redis_dot_env
52
+ append_to_file(
53
+ '.env.development',
54
+ <<~TEXT
55
+ REDIS_HOST=127.0.0.1
56
+ REDIS_PORT=$(make services-port SERVICE=redis PORT=6379)
57
+ REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}/1
58
+ TEXT
59
+ )
60
+ end
61
+
29
62
  def add_sidekiq
30
63
  gather_gem("sidekiq")
31
64
  add_adapters("sidekiq")
@@ -44,7 +77,10 @@ class Recipes::BackgroundProcessor < Rails::AppBuilder
44
77
  end
45
78
 
46
79
  def edit_procfile(cmd)
47
- gsub_file("Procfile", /^.*$/m) { |match| "#{match}worker: #{cmd}" } if selected?(:heroku)
80
+ heroku = load_recipe(:heroku)
81
+ if selected?(:heroku) || heroku.installed?
82
+ gsub_file('Procfile', /^.*$/m) { |match| "#{match}worker: #{cmd}" }
83
+ end
48
84
  end
49
85
 
50
86
  def add_adapters(name)
@@ -1,7 +1,7 @@
1
1
  class Recipes::Ci < Rails::AppBuilder
2
2
  def create
3
3
  copy_file '../assets/Dockerfile.ci', 'Dockerfile.ci'
4
- copy_file '../assets/.circleci/config.yml', '.circleci/config.yml'
4
+ template '../assets/.circleci/config.yml.erb', '.circleci/config.yml'
5
5
 
6
6
  template '../assets/bin/cibuild.erb', 'bin/cibuild'
7
7
  run "chmod a+x bin/cibuild"
@@ -17,7 +17,7 @@ class Recipes::Ci < Rails::AppBuilder
17
17
  if selected?(:database, :mysql)
18
18
  srv =
19
19
  <<~YAML
20
- image: "mysql:5.6.23"
20
+ image: mysql:#{Potassium::MYSQL_VERSION}
21
21
  environment:
22
22
  MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
23
23
  YAML
@@ -29,18 +29,20 @@ class Recipes::Ci < Rails::AppBuilder
29
29
  elsif selected?(:database, :postgresql)
30
30
  srv =
31
31
  <<~YAML
32
- image: "postgres:9.4.5"
32
+ image: "postgres:#{Potassium::POSTGRES_VERSION}"
33
33
  environment:
34
34
  POSTGRES_USER: postgres
35
35
  POSTGRES_PASSWORD: ''
36
36
  YAML
37
37
  compose.add_service("postgresql", srv)
38
38
  compose.add_link('test', 'postgresql')
39
- compose.add_env('test', 'POSTGRESQL_USER', 'postgres')
40
- compose.add_env('test', 'POSTGRESQL_HOST', 'postgresql')
41
- compose.add_env('test', 'POSTGRESQL_PORT', '5432')
39
+ compose.add_env('test', 'DB_USER', 'postgres')
40
+ compose.add_env('test', 'DB_HOST', 'postgresql')
41
+ compose.add_env('test', 'DB_PORT', '5432')
42
42
  end
43
43
 
44
+ compose.add_volume('test_data')
45
+
44
46
  add_readme_header :ci
45
47
 
46
48
  application 'config.assets.js_compressor = :uglifier', env: 'test'
@@ -0,0 +1,44 @@
1
+ class Recipes::DataMigrate < Rails::AppBuilder
2
+ def create
3
+ gather_gem('data_migrate')
4
+ annotate_task = 'lib/tasks/auto_annotate_models.rake'
5
+ insert_into_file annotate_task, annotate_config, after: "Annotate.load_tasks\n"
6
+ end
7
+
8
+ def install
9
+ create
10
+ end
11
+
12
+ def installed?
13
+ gem_exists?(/data_migrate/)
14
+ end
15
+
16
+ private
17
+
18
+ def annotate_config
19
+ <<-RUBY
20
+
21
+ data_migrate_tasks = %w(
22
+ db:migrate:with_data
23
+ db:migrate:up:with_data
24
+ db:migrate:down:with_data
25
+ db:migrate:redo:with_data
26
+ db:rollback:with_data
27
+ )
28
+
29
+ data_migrate_tasks.each do |task|
30
+ Rake::Task[task].enhance do
31
+ Rake::Task[Rake.application.top_level_tasks.last].enhance do
32
+ annotation_options_task = if Rake::Task.task_defined?('app:set_annotation_options')
33
+ 'app:set_annotation_options'
34
+ else
35
+ 'set_annotation_options'
36
+ end
37
+ Rake::Task[annotation_options_task].invoke
38
+ Annotate::Migration.update_annotations
39
+ end
40
+ end
41
+ end
42
+ RUBY
43
+ end
44
+ end