Permalink
Browse files

Merge branch 'feature/generators' into develop

  • Loading branch information...
2 parents 932ed7b + aa8ea4a commit 23e9d30058f37cf60c8de350965cb4b6b7e80a49 @jeffkreeftmeijer committed Jun 27, 2010
@@ -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
@@ -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
@@ -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)

0 comments on commit 23e9d30

Please sign in to comment.