views:

165

answers:

1

I'm trying to set up a Rails Template that would allow for comprehensive set-up of a specific Rails app. Using Pratik Naik's overview (http://m.onkey.org/2008/12/4/rails-templates), I was able to set up a couple of scaffolds and models, with a line that looks something like this ...

generate("scaffold", "post", "title:string", "body:string")

I'm now trying to add in Delayed Jobs, which normally has a migration file that looks like this:

create_table :delayed_jobs, :force => true do |table|
  table.integer  :priority, :default => 0      # Allows some jobs to jump to the front of the queue
  table.integer  :attempts, :default => 0      # Provides for retries, but still fail eventually.
  table.text     :handler                      # YAML-encoded string of the object that will do work
  table.text     :last_error                   # reason for last failure (See Note below)
  table.datetime :run_at                       # When to run. Could be Time.now for immediately, or sometime in the future.
  table.datetime :locked_at                    # Set when a client is working on this object
  table.datetime :failed_at                    # Set when all retries have failed (actually, by default, the record is deleted instead)
  table.string   :locked_by                    # Who is working on this object (if locked)
  table.timestamps
end

So, what I'm trying to do with the Rails template, is to add in that :default => 0 into the master template file. I know that the rest of the template's command should look like this:

generate("migration", "createDelayedJobs", "priority:integer", "attempts:integer", "handler:text", "last_error:text", "run_at:datetime", "locked_at:datetime", "failed_at:datetime", "locked_by:string")

Where would I put (or, rather, what is the syntax to add) the :default values in that? And if I wanted to add an index, what's the best way to do that?

+1  A: 

I don't think it is possible to pass that extra information into the template generate calls. The template system isn't particularly extensive. I could be wrong of course... The other option might be to just inject the line you are going to want into the generated migration file instead. Take a look at http://github.com/cyberkni/super%5Fstack/blob/master/templates/ in the helper.rb file for a way to do that, and at the mobile.rb file for an example of using it.

Shane Liebling