aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/rake_proxy.rb
blob: f7d5df6b2f7b4c02170b0c68e2ad08b93cfea8b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'rake'
require 'active_support'

module Rails
  module RakeProxy #:nodoc:
    private
      def run_rake_task(command)
        ARGV.unshift(command) # Prepend the command, so Rake knows how to run it.

        Rake.application.standard_exception_handling do
          Rake.application.init('rails')
          Rake.application.load_rakefile
          Rake.application.top_level
        end
      end

      def rake_tasks
        return @rake_tasks if defined?(@rake_tasks)

        ActiveSupport::Deprecation.silence do
          require_application_and_environment!
        end

        Rake::TaskManager.record_task_metadata = true
        Rake.application.instance_variable_set(:@name, 'rails')
        Rails.application.load_tasks
        @rake_tasks = Rake.application.tasks.select(&:comment)
      end

      def formatted_rake_tasks
        rake_tasks.map { |t| [ t.name_with_args, t.comment ] }
      end
  end
end