Skip to content

Instantly share code, notes, and snippets.

@asierba
Last active August 29, 2015 14:01
Show Gist options
  • Save asierba/1b56ab1e21322e2fe147 to your computer and use it in GitHub Desktop.
Save asierba/1b56ab1e21322e2fe147 to your computer and use it in GitHub Desktop.
How to use :symbols when defining task dependencies
# defined the '+' method of Symbol so we can do things like :build+:update_version in the task dependencies and get 'build:update_vesion'
# Instead of using strings which are hard to refactor
class Symbol
def method_missing(m, *args, &block)
if (m == :+)
return "#{self.to_s}:#{args[0]}"
else
super
end
end
end
namespace :namespace1 do
desc "task1"
task :task1 do
puts "task1 in namespace1"
end
desc "task2"
task :task2 do
puts "task2 in namespace1"
end
end
namespace :namespace2 do
desc "task1"
task :task1 do
puts "task1 in namespace2"
end
end
desc 'Run all task'
task :run_all => [:namespace1+:task1, :namespace1+:task2, :namespace2+:task1]
namespace :namespace1 do
desc "task1"
task :task1 do
puts "task1 in namespace1"
end
desc "task2"
task :task2 do
puts "task2 in namespace1"
end
end
namespace :namespace2 do
desc "task1"
task :task1 do
puts "task1 in namespace2"
end
end
desc 'Run all task'
task :run_all => ['namespace1:task1', 'namespace1:task2', 'namespace2:task1']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment