Sandra Cieseck
Sandra Cieseck

Reputation: 331

Ruby: run rake task to execute ruby scripts

I have a bunch of Ruby scripts and I'd like to start them with a Rake task.

A simplified version to illustrate my issue:

export_stats.rake:

desc 'Export statistics'

task :export_stats do
  puts "executing: export_stats.rb #{START_MONTH} #{END_MONTH} #{OUTPUT} #{ENVIRONMENT}"
  ruby "export_stats.rb #{START_MONTH} #{END_MONTH} #{OUTPUT} #{ENVIRONMENT}"
end

rake aborted! elk-stack/export_stats.rake Don't know how to build task 'export_stats'

the export_stats.rb file is in same directory with export_stats.rake

the rake gem is installed and if I run

rake export_stats

I get an error:

rake aborted!
Don't know how to build task 'export_stats'

What am I missing?

Upvotes: 0

Views: 347

Answers (2)

StandardNerd
StandardNerd

Reputation: 4183

If I understand you correctly you have a folder with some ruby scripts and you are trying to run a rake task that is located in the same folder. I assume you are not using any application framework like Rails (because you did tag the question only with "Ruby").

Do you have a Rakefile in same directory? If so does it contain a statement to load the specific files to run?

# Rakefile
#!/usr/bin/env rake
load 'export_stats.rake'

Upvotes: 2

Tom Lord
Tom Lord

Reputation: 28285

You have a typo.

The code says export_stats, and the error says exports_stats.

There's an extra s.

Read the error message carefully! ;)

Upvotes: 1

Related Questions