Created
February 13, 2012 09:33
-
-
Save fstrozzi/1815481 to your computer and use it in GitHub Desktop.
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
def thor_task(klass, task_name, &block) | |
if program.nil? | |
warn "WARNING: no program is associated with #{class_name.upcase} task, does not make sense to create a thor task." | |
return nil | |
end | |
if klass | |
wrapper = self | |
klass.class_eval do | |
wrapper.options.each_pair do |name, opt| | |
method_option name, opt | |
end #each_pair | |
# Thor's behavior should be respected passing attributes | |
define_method task_name do |*args| | |
#it's mandatory that the first and second parameter are respectively wrapper and task | |
raise ArgumentError, "wrong number of arguments (#{args.size} for #{block.parameters.size-2})" if args.size != block.parameters.size-2 | |
yield wrapper, self, *args | |
end | |
end#class_eval | |
end #klass | |
end #thor_task |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment