Class: ChangeLog::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Extended by:
Generators::Utils::ClassMethods
Includes:
Generators::Utils::InstanceMethods, Rails::Generators::Migration
Defined in:
lib/generators/change_log/install_generator.rb

Instance Method Summary collapse

Methods included from Generators::Utils::ClassMethods

next_migration_number

Methods included from Generators::Utils::InstanceMethods

#ask_boolean, #ask_for, #ask_wizard, #display, #multiple_choice, #say_custom

Instance Method Details

#installObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/change_log/install_generator.rb', line 22

def install
  routes = File.open(Rails.root.join("config/routes.rb")).try :read
  initializer = (File.open(Rails.root.join("config/initializers/change_log.rb")) rescue nil).try :read

  display "Hello, ChangeLog installer will help you sets things up!", :black
  unless initializer
    #install_generator = ask_boolean("Do you want to install the optional configuration file (to change mappings, locales dump location etc..) ?")
    @orm = multiple_choice "Please select orm", [["ActiveRecord", "activerecord"], ["Mongoid", "mongoid"]]

    _table =  @orm == 'mongoid' ? 'collection' : 'table'
    @table_prefix = ask_for("Do you want to add #{_table} prefix?", nil, table_prefix)
    template "initializer.erb", "config/initializers/change_log.rb"
  else
    display "You already have a config file. generating a new 'change_log.rb.example' that you can review."
    template "initializer.erb", "config/initializers/change_log.rb.example"
  end

  if @orm == 'activerecord'
    display "Adding a migration..."
    migration_template 'migration.rb', 'db/migrate/create_change_log_tables.rb' #rescue display $!.message
  end

  namespace = ask_for("Where do you want to mount change_log?", "change_log", _namespace)
  gsub_file "config/routes.rb", /mount ChangeLog::Engine => \'\/.+\', :as => \'change_log\' if defined\? ChangeLog/, ''
  gsub_file "config/routes.rb", /mount ChangeLog::Engine => \'\/.+\', :as => \'change_log\'/, ''
  gsub_file "config/routes.rb", /mount ChangeLog::Engine => \'\/.+\'/, ''
  route("mount ChangeLog::Engine => '/#{namespace}', :as => 'change_log' if defined? ChangeLog")

  display "Job's done: migrate,now modify initilizer[optional],  start your server and visit '/#{namespace}'!", :blue
end

#table_prefixObject



53
54
55
# File 'lib/generators/change_log/install_generator.rb', line 53

def table_prefix
  @table_prefix
end