Class: DatabaseformalizerGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/rails/generators/databaseformalizer/databaseformalizer_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

:nodoc:



11
12
13
14
15
16
17
# File 'lib/rails/generators/databaseformalizer/databaseformalizer_generator.rb', line 11

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

.source_rootObject



7
8
9
# File 'lib/rails/generators/databaseformalizer/databaseformalizer_generator.rb', line 7

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

Instance Method Details

#add_databaseformalizer_routesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails/generators/databaseformalizer/databaseformalizer_generator.rb', line 31

def add_databaseformalizer_routes
  dbfo_route = "
namespace :databaseformalizer do
resources :attr_defs, :controller => 'databaseformalizer/attr_defs'
resources :entity_defs, :controller => 'databaseformalizer/entity_defs'
resources :entities, :controller => 'databaseformalizer/entities'
end
  
match 'databaseformalizer', :action => 'index', :controller => 'databaseformalizer/dbformahome'"
  route dbfo_route
end

#copy_initializer_fileObject



27
28
29
# File 'lib/rails/generators/databaseformalizer/databaseformalizer_generator.rb', line 27

def copy_initializer_file
  copy_file 'initializer.rb', 'config/initializers/databaseformalizer.rb'
end

#create_migration_fileObject

Every method that is declared below will be automatically executed when the generator is run



22
23
24
25
# File 'lib/rails/generators/databaseformalizer/databaseformalizer_generator.rb', line 22

def create_migration_file
  migration_template  'migration.rb',
                      'db/migrate/create_databaseformalizer_tables.rb'
end