Class: AuditorGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- AuditorGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/rails/generators/auditor/auditor_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_initializer_file ⇒ Object
-
#create_migration_file ⇒ Object
Every method that is declared below will be automatically executed when the generator is run.
- #update_application_template ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
:nodoc:
11 12 13 14 15 16 17 |
# File 'lib/rails/generators/auditor/auditor_generator.rb', line 11 def self.next_migration_number(dirname) #:nodoc: if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
.source_root ⇒ Object
7 8 9 |
# File 'lib/rails/generators/auditor/auditor_generator.rb', line 7 def self.source_root File.join(File.dirname(__FILE__), 'templates') end |
Instance Method Details
#copy_initializer_file ⇒ Object
42 43 44 |
# File 'lib/rails/generators/auditor/auditor_generator.rb', line 42 def copy_initializer_file copy_file 'initializer.rb', 'config/initializers/auditor.rb' end |
#create_migration_file ⇒ Object
Every method that is declared below will be automatically executed when the generator is run
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rails/generators/auditor/auditor_generator.rb', line 22 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 |
#update_application_template ⇒ Object
46 47 48 |
# File 'lib/rails/generators/auditor/auditor_generator.rb', line 46 def update_application_template end |