/
rake_command.rb
53 lines (42 loc) · 1.35 KB
/
rake_command.rb
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
module Rails
module Command
class RakeCommand < Base # :nodoc:
extend Rails::Command::Actions
namespace "rake"
class << self
def printing_commands
formatted_rake_tasks.map(&:first)
end
def perform(task, args, config)
require_rake
Rake.with_application do |rake|
load "rails/tasks.rb"
rake.init("rails", [task, *args])
rake.load_rakefile
if Rails.respond_to?(:root)
rake.options.suppress_backtrace_pattern = /\A(?!#{Regexp.quote(Rails.root.to_s)})/
end
rake.standard_exception_handling { rake.top_level }
end
end
private
def rake_tasks
require_rake
return @rake_tasks if defined?(@rake_tasks)
require_application!
Rake::TaskManager.record_task_metadata = true
Rake.application.instance_variable_set(:@name, "rails")
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
def require_rake
require "rake" # Defer booting Rake until we know it's needed.
end
end
end
end
end