Sha256: e5660eb50b7eb9e095bc25b5467808a5b074820d4a4611fb8744eb07225882c8
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
require 'rails/generators' require 'rails/generators/migration' class AuditorGenerator < Rails::Generators::Base include Rails::Generators::Migration def self.source_root File.join(File.dirname(__FILE__), 'templates') end 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 # Every method that is declared below will be automatically executed when the generator is run def create_migration_file f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb') schema = f.read; f.close schema.gsub!(/ActiveRecord::Schema.*\n/, '') schema.gsub!(/^end\n*$/, '') f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb') migration = f.read; f.close migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema) tmp = File.open "tmp/~migration_ready.rb", "w" tmp.write migration tmp.close migration_template '../../../tmp/~migration_ready.rb', 'db/migrate/create_auditor_tables.rb' remove_file 'tmp/~migration_ready.rb' end def copy_initializer_file copy_file 'initializer.rb', 'config/initializers/auditor.rb' end def update_application_template end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
request-auditor-0.0.3 | lib/rails/generators/auditor/auditor_generator.rb |
request-auditor-0.0.1 | lib/rails/generators/auditor/auditor_generator.rb |