Class: Jets::Commands::RakeCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/commands/rake_command.rb

Class Method Summary collapse

Class Method Details

.formatted_rake_tasks(all = false) ⇒ Object



26
27
28
29
30
31
# File 'lib/jets/commands/rake_command.rb', line 26

def formatted_rake_tasks(all=false)
  rake_tasks(all).map do |t|
    comment = "# #{t.comment}" if t.comment
    [ t.name_with_args, comment ]
  end
end

.help_message(namespaced_command) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/jets/commands/rake_command.rb', line 44

def help_message(namespaced_command)
  task = rake_tasks(true).find { |t| t.name == namespaced_command }
  message = "Help provided by rake task:\n\n"
  message << "jets #{task.name_with_args.dup}\n"
  message << "    #{task.full_comment}"
  message
end

.namespaced_commandsObject

Useful for CLI.lookup.



22
23
24
# File 'lib/jets/commands/rake_command.rb', line 22

def namespaced_commands
  formatted_rake_tasks(true).map(&:first)
end

.perform(namespaced_command, thor_args) ⇒ Object

Same signature as Jets::Commands::Base.perform.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jets/commands/rake_command.rb', line 4

def perform(namespaced_command, thor_args)
  if thor_args.first == "help"
    puts help_message(namespaced_command)
    return
  end

  require_rake

  ARGV.unshift(namespaced_command) # Prepend the task, so Rake knows how to run it.

  rake.standard_exception_handling do
    rake.init("jets")
    rake.load_rakefile
    rake.top_level
  end
end

.rake_tasks(all = false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/jets/commands/rake_command.rb', line 33

def rake_tasks(all=false)
  require_rake

  Rake::TaskManager. = true
  rake.instance_variable_set(:@name, "jets")
  Jets::Commands::RakeTasks.load!
  tasks = rake.tasks
  tasks = tasks.select(&:comment) unless all
  tasks
end