Renaming Ruby on Rails application

前端 未结 6 1180
感情败类
感情败类 2020-12-05 10:34

Is there a way to rename the application in Rails 2?

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 10:56

    I've written the following script to do just that. You can see it also at https://gist.github.com/danielpclark/8dfcdd7ac63149323bbc

    #!/usr/bin/ruby
    # Rename Rails Project (File: rename_rails)
    # Copyright 6ft Dan(TM) / MIT License
    # Check the config/application.rb for capital usage in project name by model OldProjectName
    # Usage: rename_rails OldProjectName NewAwesomeName
    
    # Replace string instances of project name   
    `grep -lR #{ARGV[0]} | xargs sed -i 's/#{ARGV[0]}/#{ARGV[1]}/g'`
    `grep -lR #{ARGV[0].downcase} | xargs sed -i 's/#{ARGV[0].downcase}/#{ARGV[1].downcase}/g'`
    
    # Rename Rails directory if it exists
    if File.directory?(ARGV[0])
        `mv #{ARGV[0]} #{ARGV[1]}`
        drc = ARGV[1]
    elsif File.directory?(ARGV[0].downcase)
        `mv #{ARGV[0].downcase} #{ARGV[1]}`
        drc = ARGV[1]
    end
    
    # Delete temporary files (helps prevent errors)
    drc ||= ''
    if ['cache','pids','sessions','sockets'].all? {
            |direc| File.directory?(File.join(drc,'tmp', direc)) }
        FileUtils.rm_rf(File.join(drc,'tmp'))
    end
    

    And I've created a howto video on YouTube. http://youtu.be/dDw2RmczcDA

提交回复
热议问题