Sha256: edf3ca5448627f8d0bd32764cb575be16739431ec0c43493ba2fa53d19111cf8

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

# These tasks are added to the project if you install annotate as a Rails plugin.
# (They are not used to build annotate itself.)

# Append annotations to Rake tasks for ActiveRecord, so annotate automatically gets
# run after doing db:migrate.

# Migration tasks are tasks that we'll "hook" into
migration_tasks = %w[db:migrate db:migrate:up db:migrate:down db:migrate:reset db:migrate:redo db:rollback]

# Support for data_migrate gem (https://github.com/ilyakatz/data-migrate)
migration_tasks_with_data = migration_tasks.map { |task| "#{task}:with_data" }
migration_tasks += migration_tasks_with_data

if defined?(Rails::Application) && Rails.version.split(".").first.to_i >= 6
  require "active_record"

  databases = ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml

  # If there's multiple databases, this appends database specific rake tasks to `migration_tasks`
  ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |database_name|
    migration_tasks.concat(%w[db:migrate db:migrate:up db:migrate:down].map { |task| "#{task}:#{database_name}" })
  end
end

migration_tasks.each do |task|
  next unless Rake::Task.task_defined?(task)

  Rake::Task[task].enhance do # This block is ran after `task` completes
    task_name = Rake.application.top_level_tasks.last # The name of the task that was run, e.g. "db:migrate"

    Rake::Task[task_name].enhance do
      ::AnnotateRb::Runner.run(["models"])
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
annotaterb-4.13.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.12.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.11.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.10.2 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.10.1 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.10.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.9.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.7.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.6.0 lib/annotate_rb/tasks/annotate_models_migrate.rake