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
@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' 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
|