Questions tagged [rake]

Ruby build utility similar to make with build commands defined in pure Ruby.

Rake uses Rakefiles (cf. Makefiles) defined in pure Ruby, the build utility created by the late Jim Weirich. Rule patterns to synthesize implicit tasks are supported and developers can easily specify pre- and post-task dependency chains. Rake includes a library of pre-packaged tasks to make creating Rakefiles easier.

Rake uses Ruby's anonymous function blocks to define various tasks, allowing the use of Ruby syntax. It has a library of common tasks: for example, functions to do common file-manipulation tasks and a library to remove compiled files (the "clean" task). Like Make, Rake can also synthesize tasks based on patterns: for example, automatically building a file compilation task based on filename patterns. Rake is now part of the standard library from Ruby version 1.9 onward.

Sample Rake file

    namespace :pick do
      desc "Pick a random user as the winner"
      task :winner => :environment do
        puts "Winner: #{pick(User).name}"
      end

      desc "Pick a random product as the prize"
      task :prize => :environment do
        puts "Prize: #{pick(Product).name}"
      end

      desc "Pick a random prize and winner"
      task :all => [:prize, :winner]

      def pick(model_class)
        model_class.find(:first, :order => 'RAND()')
      end
    end

Useful links

Implementation specific tags

You can specify your question by adding the implementation you used as a tag.

4366 questions
2
votes
1 answer

Rake task not running from within worker

I don't understand why my rake task is not running from within a resque worker. Running rake :send_this_email from the console works fine, I just want to run it as a cron job (as follows) but something is not working proplerly while invoking the…
computer_smile
  • 2,117
  • 2
  • 24
  • 42
2
votes
2 answers

Import spatial CSV data into Postgres/PostGIS database with a rake task

Hi I'm trying to import CSV data into a spatially enabled Postgres database. The data is available here. I'm unsure where I went wrong and any help is greatly appreciated! What I'm attempting to do is visualize that data with D3.js and maybe display…
Matthew Macri
  • 89
  • 2
  • 14
2
votes
2 answers

Rake tasks work on command line, but fail when invoked inside a Rake task

Currently, to rebuild my database for a Rails project, I run the following Rake tasks in the command line: bundle exec rake db:drop bundle exec rake db:create bundle exec rake db:migrate bundle exec rake db:seed I would like to put these inside of…
Eric Heikes
  • 53
  • 1
  • 6
2
votes
1 answer

How to use input filename to generate output filename with Rake?

I've got some input files which I want to encode using Ruby. The output from the encoding should match some pattern based on the filename of the input file. In order to not do this by hand, I want to use Rake as help for automation. Further I'd like…
boutta
  • 24,189
  • 7
  • 34
  • 49
2
votes
0 answers

specs run on an extracted Rails::Engine do not initialize/restore DB to pristine state as before

I've recently extracted a module to a Rails::Engine gem that contains a "dummy application" for running the tests on. rake spec now behaves differently, and is causing some specs to fail. First, running rake spec --trace in the gem directory no…
jordanpg
  • 6,386
  • 4
  • 46
  • 70
2
votes
1 answer

Rails: Assets precompile failure

On one of my linux servers when I run... bundle exec rake assets:precompile RAILS_ENV=production --trace I'm getting the following error... ** Invoke assets:precompile (first_time) ** Execute assets:precompile /usr/local/bin/ruby…
HelloWorld
  • 4,251
  • 8
  • 36
  • 60
2
votes
0 answers

Rake aborted with rspec load error

I am trying to configure rake using rspec, so I required rspec and rspec/core/rake_task on top of the rakefile. I'm sure I have already installed the rspec gem, but then I got the rspec load error. The rakefile: require "rspec" require…
Superalan
  • 21
  • 1
  • 2
2
votes
0 answers

How to get my custom Rake task *args to work like built-in Rake task *args?

I have a custom rake task, implemented as a method, which sits "above" the task method. It works with a custom configuration object to give the whole thing a more declarative feel. Here it is. def robocopy(*args, &block) config =…
Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
2
votes
1 answer

db:reset resets the database; what's the simplest way to do that for one table only?

I'd like to be able to: Clear out one table, including resetting the primary key(s) Use db:seed to refill that table with new data Keep all other tables the same, with data intact I understand this is possible by having a migration that drops the…
2
votes
1 answer

Fail rake task with custom exit code?

I would like to abort a rake task with custom exit code (to communicate to the executing shell script that a specific condition was met). Rake task that succeeds returns 0 and fail always returns 1. Is there a way to make a custom code?
mbdev
  • 6,343
  • 14
  • 46
  • 63
2
votes
1 answer

How to capture command not found with popen4

I'm using popen4 to capture stdout, stderr, and the exit status of a command line. I'm not tied to popen4 as long as I can capture those 3 things above. Currently I've not found a good way to capture command not found errors. I could do a which…
chrisan
  • 4,152
  • 4
  • 28
  • 32
2
votes
1 answer

Installation of redmine with bundler requires root password

I'm trying to install redmine on my CentOS 6.3 server. I created an user to run the program, then I tried to install it with the command bundle install --without development test postgresql sqlite rmagick but it asks me the password Fetching gem…
Stefano
  • 3,213
  • 9
  • 60
  • 101
2
votes
1 answer

VMware Workstation 8 automation with Ruby/Rake?

I'm looking into doing more automation in our build process; We use TeamCity and rake for our build tasks. We build our website into an MSI, and that's the extent of our CI system. I want to add deployment to the automation. We use VMware…
Neil
  • 5,179
  • 8
  • 48
  • 87
2
votes
1 answer

stack level too deep error when running any rake task

I'm upgrading an application from Rails 3.0 to Rails 3.1. The tests run ok, as the unicorn server. However, when I run any rake task (being 'rake routes' or even 'rake about'), it returns 'stack level too deep'. This doesn't happen using Rails…
shadowmaru
  • 141
  • 1
  • 9
2
votes
1 answer

Execute PowerShell from Ruby

This runs fine from the PS command prompt: Get-WmiObject Win32_Share -computer "Server" -filter "Name = 'ShareName'" When added to Ruby I can get this to execute (because it doesn't need quotes): powershell (Get-WmiObject Win32_Share -computer…
Dean8088
  • 21
  • 3
1 2 3
99
100