I wrote the following rake task to execute the 'ls' UNIX command using
the 'command' method in the 'FileOperation' module
namespace :test do
task :post_heartrate do
When I run it, I get the following error:
no such file to load -- FileOperations
Then, I get the following error if I take out the 'require' line:
uninitialized constant FileOperations
I know this is a very basic problem. Any suggestions?
I’m guessing you copied the rake from the middle of a Rails app maybe? There is a lot of extra requires that are not “required”.
Here is a rake file that accomplishes what you describe. There were no other requires or anything else. This is the defined “Rake File Format”. Also, Dir.glob is in the Ruby core, so no requires are necessary. :
=== start RakeFile.rb ===
desc “List Files in current dir.”
task :list_files do
Dir.glob("*").each do |d|
=== end RakeFile.rb ===
And the output :
$ ls -l
-rw-r–r-- 1 mlpf mkgroup-l-d 101 Aug 21 09:26 RakeFile.rb
$ rake -T
rake list_files # List Files in current dir.
$ rake list_files
Here are the references I reviewed:
“Rake Users Guide”: http://docs.rubyrake.org/read/book/2
Hope that helps!
FileOperations is part of the guts of Rails.
To run an external command, use the "sh" method which Rake provides:
Rake includes the Ruby standard FileUtils and adds a few handy
extensions, so that's where you should be starting.