Rails 快速执行 Rakefile 指令

hayeah · 2012年04月11日 · 最后由 hayeah 回复于 2012年04月16日 · 4510 次阅读

把这加到 Rakefile 里。然后执行 rake loop

可自己定义每个指令需要重读的脚本

这样一些常用的指令就不用每次都等老半天啦~~~~

task :loop => [:environment] do
  def reload_file(path)
    File.exists?(path)
    File.readlines(path).map do |line|
      Dir[line]
    end.flatten.each do |file|
      load file
    end
  end

  # specify the file paths you want to reload in the reload_file.
  # each line is a Dir glob. e.g.
  #  config/routes.rb
  #  app/models/*.rb
  reload_file = "reload"

  loop do
    reload_file reload_file
    print "rake command:"
    task = $stdin.readline.strip
    Rake::Task[task].reenable
    Rake::Task[task].invoke
  end
end

每个文件都写岂不是很麻烦,有没有更简洁一些的写法?

#1 楼 @huacnlee 现在我暂时放这两个

config/routes.rb
app/**/*.rb

需要 登录 后方可回复, 如果你还没有账号请 注册新账号