在Rails应用程序中处理gem

时间:2022-05-01 22:47:57

What's the easiest way to work on a plain-ole Ruby gem, and then quickly turn around and run it in a Rails app?

什么是最简单的方法来处理普通的Ruby gem,然后快速转向并在Rails应用程序中运行它?

I like to keep application logic out of Rails. Encourages code reuse across projects, and keeps my Rails app clean. It produces, however, an ugly workflow:

我喜欢将应用程序逻辑保留在Rails之外。鼓励跨项目重用代码,并保持我的Rails应用程序清洁。然而,它产生了一个丑陋的工作流程:

  1. Test my gem. rake test
  2. 测试我的宝石。耙试验

  3. Build my gem. gem build ...
  4. 建立我的宝石。宝石建造......

  5. Upload gem to private repository (currently using Gemfury). fury push ...
  6. 将gem上传到私有存储库(目前使用Gemfury)。愤怒推...

  7. Update my gem from within Rails (bundle update ...)
  8. 从Rails中更新我的gem(包更新...)

  9. Run my Rails code.
  10. 运行我的Rails代码。

Yuck. I'd like to simply save my file in the library, and then watch it work in the Rails project.

呸。我想将我的文件保存在库中,然后在Rails项目中观察它。

Clojure's Leiningen has a concept called "checkouts", allowing you to work on several libraries within one.

Clojure的Leiningen有一个名为“checkouts”的概念,允许您在一个库中处理多个库。

Techniques, anyone?

1 个解决方案

#1


3  

Use Bundler's path directive.

使用Bundler的路径指令。

gem 'my_gem', :path => "~/my_gem"

You'll still have to restart the Rails server every time your code changes to reload it, but you won't have to go through the whole build-and-publish step for each revision. Be sure to update your gem reference to something production-worthy before pushing your code.

每次代码更改以重新加载时,您仍然需要重新启动Rails服务器,但是您不必为每个修订完成整个构建和发布步骤。在推送代码之前,请务必将gem引用更新为适合生产的东西。

#1


3  

Use Bundler's path directive.

使用Bundler的路径指令。

gem 'my_gem', :path => "~/my_gem"

You'll still have to restart the Rails server every time your code changes to reload it, but you won't have to go through the whole build-and-publish step for each revision. Be sure to update your gem reference to something production-worthy before pushing your code.

每次代码更改以重新加载时,您仍然需要重新启动Rails服务器,但是您不必为每个修订完成整个构建和发布步骤。在推送代码之前,请务必将gem引用更新为适合生产的东西。