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

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

+8
ruby ruby-on-rails
source share
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 the case, just add this line to the rake command:

 require 'yourfile' 
+3
source share

You need as you need, and then enable:

 require 'your_module' namespace :your_task do include YourModule ... 
+3
source share

All Articles