Skip to content

Instantly share code, notes, and snippets.

@asaaki
Last active January 3, 2016 10:19
Show Gist options
  • Save asaaki/8448269 to your computer and use it in GitHub Desktop.
Save asaaki/8448269 to your computer and use it in GitHub Desktop.
rask — Simple stupid rake task runner if you need to call them within another task
# can be loaded via `import`:
module Rake
module DSL
class Rask
def initialize
@stack = []
end
def method_missing name, *_args
name == :run! ?
Rake::Task[@stack.join(":").to_sym].invoke :
self.tap{ @stack << name }
end
end
def rask
Rask.new
end
end
end
# usable in `Rakefile`:
rask = Class.new do
def initialize
@stack = []
end
def method_missing name, *_args
name == :run! ?
Rake::Task[@stack.join(":").to_sym].invoke :
self.tap{ @stack << name }
end
def self.method_missing name, *_args
self.new.send name
end
end
# demo
namespace :a do
namespace :deeply do
task :nested do
puts "I am `a:deeply:nested` task."
end
end
end
task :a do
puts "I am :a!"
end
task :b do
puts "I am :b and will call some other rake tasks now ..."
rask.a.run!
rask.a.deeply.nested.run!
puts "Back in :b and done."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment