Last active
January 3, 2016 10:19
-
-
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
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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