Class: Tnw::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/tnw/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_migrationsObject



19
20
21
22
23
24
25
26
27
# File 'lib/generators/tnw/install/install_generator.rb', line 19

def copy_migrations
  migration_sources.each_with_index do |source, index|
    migration_name = File.basename(source).sub(/\A\d+_/, "")
    next if migration_installed?(migration_name)

    timestamp = (Time.now.utc + index.seconds).strftime("%Y%m%d%H%M%S")
    copy_file source, "db/migrate/#{timestamp}_#{migration_name}"
  end
end

#create_initializerObject



8
9
10
# File 'lib/generators/tnw/install/install_generator.rb', line 8

def create_initializer
  template "tnw.rb", "config/initializers/tnw.rb"
end

#mount_engineObject



12
13
14
15
16
17
# File 'lib/generators/tnw/install/install_generator.rb', line 12

def mount_engine
  routes_path = destination_root_path.join("config/routes.rb")
  return if routes_path.exist? && routes_path.read.include?("mount Tnw::Engine")

  route 'mount Tnw::Engine => "/tnw"'
end