Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load rake files and run tasks from other files

Tags:

rake

rakefile

Currently I'm trying split up my rake files to organize them better. For this, I've added a rake folder to my assets dir, that holds one rake file for each group of tasks.

As I'm coming from PHP, I've only very basic knowledge of Ruby/Rake and can't get my namespaces default action running after loading the file.

The commmented out Rake :: Task ...-string inside app:init throws an error at the CL at me:

rake aborted!  uninitialized constant TASK 

Here's the namespace/class (if this is the right word).

task :default => [ 'app:init' ] namespace :app do      rake_dir   = "#{Dir.pwd}/assets/rake/"     rake_files = FileList.new( "#{rake_dir}*" )      desc "Loads rake modules (Default action)"     task :init do         puts "\t Importing rake files for processing"          puts "\t loading..."         rake_files.each() { |rake|             puts "\t #{rake}"             require rake             # @link rubular.com             name = rake.split( rake_dir ).last.gsub( /.rb\z/, '' )             puts "\t #{name}"             #Rake :: Task[ "#{name}:default" ].invoke         }     end end 

Thanks in advance.

Edit: At least, I can be sure the file gets loaded, as the plain puts "file loaded" at the beginning of those files gets echoed. The problem seems to only be that the :default action for the namespace in the loaded rake file isn't loading.

like image 925
kaiser Avatar asked Dec 07 '12 11:12

kaiser


People also ask

What is. rake file?

Rake is a native tool for Ruby, similar to Unix's “make”. Written by Jim Weirich, It is used to handle administrative commands or tasks, which are stored either in a Rakefile or in a . rake file. One can write their own rake tasks, specific to their application.

How do I run a rake task?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.

What is Rakefile in Ruby?

Rake is a tool you can use with Ruby projects. It allows you to use ruby code to define "tasks" that can be run in the command line. Rake can be downloaded and included in ruby projects as a ruby gem. Once installed, you define tasks in a file named "Rakefile" that you add to your project.


1 Answers

You can either put your tasks into rakelib/ folder which rake loads by default or add a specific folder in your Rakefile via:

Rake.add_rakelib 'lib/tasks' 
like image 88
splattael Avatar answered Nov 11 '22 05:11

splattael