Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a module to a rake namespace in separate files?

I have a module and a child class. Where i have all the functionality inside the module. and inside the child class I just call the methods from the module. I want this module to be linked with a rake task under a namespace, and these two files are in the same directory. RAILS_ROOT/lib. How do I do this? I am running Rails 3.0.3.

like image 770
Maxsy Avatar asked May 23 '11 02:05

Maxsy


2 Answers

create a file under lib/tasks/your_namespace.rake , and write the task:

namespace :your_namespace do
  desc "An optional description of your task"
  task :your_task_name => [:environment] do
    # your code stuff
  end
end

you should be able to use code from modules. In case, just add this line in rake task:

require 'yourfile'
like image 178
Andrea Pavoni Avatar answered Nov 06 '22 04:11

Andrea Pavoni


You need to both require and then include:

require 'your_module'
namespace :your_task do
   include YourModule
   ...
like image 26
cman77 Avatar answered Nov 06 '22 03:11

cman77