Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

authr generator

simply generates a basic migration file. the fields defined in the migration are required. Add any others as needed.
  • Loading branch information...
commit ca9c3e8edb99902cd29a09c5a73b0368093f61c0 1 parent bd29e89
jrwest authored
View
24 lib/generators/authr/authr_generator.rb
@@ -0,0 +1,24 @@
+require 'rails/generators'
+require 'rails/generators/migration'
+
+class AuthrGenerator < Rails::Generators::Base
+ include Rails::Generators::Migration
+
+ def self.source_root
+ File.join(File.dirname(__FILE__), 'templates')
+ end
+
+ # Implement the required interface for Rails::Generators::Migration.
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
+ def self.next_migration_number(dirname) #:nodoc:
+ if ActiveRecord::Base.timestamped_migrations
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
+ else
+ "%.3d" % (current_migration_number(dirname) + 1)
+ end
+ end
+
+ def create_migration_file
+ migration_template 'migration.rb', 'db/migrate/create_accounts_table.rb'
+ end
+end
View
15 lib/generators/authr/templates/migration.rb
@@ -0,0 +1,15 @@
+class CreateAccountsTable < ActiveRecord::Migration
+ def self.up
+ create_table :accounts do |t|
+ t.string :uname
+ t.string :hashed_password
+ #Any additional fields here
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :accounts
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.