Last active
March 16, 2017 03:45
-
-
Save ashmckenzie/61424ad16f8433c656c9f14c36f030c9 to your computer and use it in GitHub Desktop.
before_all Rake hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rake one | |
> always_run_before_one | |
> always_run_before_two | |
> one | |
$ rake nested:two | |
> always_run_before_one | |
> always_run_before_two | |
> two | |
$ rake three | |
> three |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rake::DSL | |
def before_all(*args) | |
args.each do |pair| | |
matchers, task_names = pair.to_a.first | |
tasks = [] | |
[ *matchers ].each do |matcher| | |
matcher = matcher.to_s if matcher.is_a?(Symbol) | |
tasks += Rake::Task.tasks.select { |task| !!task.name.match(matcher) } | |
end | |
tasks.each { |task| task.enhance([ *task_names ]) } | |
end | |
end | |
end | |
task :one do | |
puts '> one' | |
end | |
namespace :nested do | |
task :two do | |
puts '> two' | |
end | |
end | |
task :three do | |
puts '> three' | |
end | |
task :always_run_before_one do | |
puts '> always_run_before_one' | |
end | |
task :always_run_before_two do | |
puts '> always_run_before_two' | |
end | |
before_all [ /^one$/, 'nested:two' ] => [ 'always_run_before_one', 'always_run_before_two' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment