Sha256: c0d110a44dd97c65ca23df0a40933ae838fb36c9026c6276eb4ff817564f5f9f

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 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]
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

6 entries across 6 versions & 1 rubygems

Version Path
annotaterb-4.5.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.4.1 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.4.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.3.1 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.3.0 lib/annotate_rb/tasks/annotate_models_migrate.rake
annotaterb-4.2.0 lib/annotate_rb/tasks/annotate_models_migrate.rake