Skip to content

Instantly share code, notes, and snippets.

@jonforums
Created January 16, 2014 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonforums/8448721 to your computer and use it in GitHub Desktop.
Save jonforums/8448721 to your computer and use it in GitHub Desktop.
rake cmd line task name alchemy
# Safe little monkey patch to Rake...until it isn't ;)
module Rake
class Application
def top_level_tasks=(tasks)
@top_level_tasks = tasks
end
end
end
puts 'Original top level tasks: %s' % Rake.application.top_level_tasks.inspect
Rake.application.top_level_tasks = Rake.application.top_level_tasks.map do |v|
if v =~ /(ruby)(\d{2})/
"#{$1}[#{$2}]"
else
v
end
end
puts 'Monkey patched top level tasks: %s' % Rake.application.top_level_tasks.inspect
desc 'build specifed ruby version'
task :ruby, [:version] do |t, args|
puts "---> building ruby version #{args.version}"
end
task :default do
puts '---> doing something secret by default'
end
C:\>rake ruby18
Original top level tasks: ["ruby18"]
Monkey patched top level tasks: ["ruby[18]"]
---> building ruby version 18
C:\>rake ruby19
Original top level tasks: ["ruby19"]
Monkey patched top level tasks: ["ruby[19]"]
---> building ruby version 19
C:\>rake ruby20
Original top level tasks: ["ruby20"]
Monkey patched top level tasks: ["ruby[20]"]
---> building ruby version 20
C:\>rake ruby21
Original top level tasks: ["ruby21"]
Monkey patched top level tasks: ["ruby[21]"]
---> building ruby version 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment