Class: Monimoni::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/monimoni/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/generators/monimoni/install_generator.rb', line 10

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
    migration_number += 1
    migration_number.to_s
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#installObject



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

def install
  routes = File.open(Rails.root.join("config/routes.rb")).try :read

  gsub_file "config/routes.rb", /mount Monimoni::Engine => \'\/.+\', :as => \'monimoni\'/, ''
  route("mount Monimoni::Engine => '/monimoni', :as => 'monimoni'")

  migration_template 'migration.rb', 'db/migrate/create_monimonis_table.rb'
end