Created
January 8, 2014 10:49
-
-
Save archan937/8314966 to your computer and use it in GitHub Desktop.
Override Rake::Task.define_task for cleaner arguments passing
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
require_relative "task" | |
desc "Send an invite" | |
task :invite do |name, email| | |
puts "Invitation sent to '#{name} <#{email}>'" | |
end | |
# Example: | |
# | |
# $ rake invite "Paul Engel" [email protected] | |
# Invitation sent to 'Paul Engel <[email protected]>' | |
# |
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 | |
class Task | |
class << self | |
alias :original_define_task :define_task | |
end | |
def self.define_task(*args, &block) | |
original_define_task *args do |task| | |
if block_given? | |
arguments = ARGV.select do |arg| | |
!arg.include?(task.name) && original_define_task(arg.to_sym) do; end | |
end | |
block.call *arguments | |
end | |
end | |
end | |
end | |
end |
Nicely done, indeed.
Rake::Task['invite'].invoke 'Paul Engel', '[email protected]'
don't work, though. :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nicely done, sir!