Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/generators' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Kreeftmeijer committed Jun 27, 2010
2 parents 932ed7b + aa8ea4a commit 23e9d30
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
14 changes: 10 additions & 4 deletions generators/navvy/navvy_generator.rb
@@ -1,13 +1,19 @@
class NavvyGenerator < Rails::Generator::Base
default_options :orm => 'active_record'

def manifest
record do |m|
options = {
:migration_file_name => 'create_jobs'
}
m.migration_template 'migration.rb', 'db/migrate', options
m.migration_template "#{options[:orm]}_migration.rb", 'db/migrate', {:migration_file_name => 'create_jobs'}
end
end

def add_options!(opt)
opt.separator ''
opt.separator 'Options:'
opt.on('--active_record', 'Generate a migration file for ActiveRecord. (default)') { options[:orm] = 'active_record' }
opt.on('--sequel', 'Generate a migration file for Sequel.') { options[:orm] = 'sequel' }
end

def banner
"Usage: #{$0} #{spec.name}"
end
Expand Down
23 changes: 23 additions & 0 deletions generators/navvy/templates/sequel_migration.rb
@@ -0,0 +1,23 @@
Sequel.migration do
up do
create_table(:jobs) do
primary_key :id, :type => Integer
String :object
String :method_name
String :arguments, :text => true
Integer :priority, :default => 0
String :return
String :exception
Integer :parent_id
DateTime :created_at
DateTime :run_at
DateTime :started_at
DateTime :completed_at
DateTime :failed_at
end
end

down do
drop_table(:jobs)
end
end
14 changes: 13 additions & 1 deletion lib/generators/navvy_generator.rb
Expand Up @@ -2,17 +2,29 @@
class NavvyGenerator < Rails::Generators::Base
include Rails::Generators::Migration

class_option :active_record,
:desc => 'Generate a migration file for ActiveRecord. (default)',
:type => 'boolean'

class_option :sequel,
:desc => 'Generate a migration file for Sequel.',
:type => 'boolean'

def self.source_root
File.join(File.dirname(__FILE__), '..', '..', 'generators', 'navvy', 'templates')
end

def install_navvy
migration_template(
'migration.rb',
"#{orm}_migration.rb",
'db/migrate/create_jobs.rb'
)
end

def orm
options[:sequel] ? 'sequel' : 'active_record'
end

protected
def self.next_migration_number(dirname) #:nodoc:
"%.3d" % (current_migration_number(dirname) + 1)
Expand Down

0 comments on commit 23e9d30

Please sign in to comment.