Jul 07 Rake task using methods in modules

tags: rake modules | comments

I normally don’t feel too confortable with the looks and manners of Rake tasks. The code looks a bit anti-DSL, and normally is not clear where to put helper methods, and also how to make them available or not to given tasks. So take a look at what I tried the other day: including modules in tasks and make them dependencies of other tasks:

# some tasks.rake file

# this tasks includes the methods to use them
task :task_using_methods_in_modules => [:extends_modules] do
  file_url = file_url_param ENV
  # and more ...
end

#TODO is this module extend-ing good? are extended by Rake::Task class itself or who?
task :extends_modules do
  extend ParamsFromENV
end

module ParamsFromENV
  def file_url_param(env)
    env['FILE_URL'].blank? ? '/resources' : env['FILE_URL']
  end
end

So, what do you think about it? Is it good? Am I breaking something?

blog comments powered by Disqus