How to quickly initialize ruby project development environment?

与世无争的帅哥 提交于 2019-12-08 09:39:27

问题


How to specify gem dependencies in a way that user with only ruby, rake and rubygems installed could issue a single rake command to install all the dependencies required? Is it possible to use the same dependency specification when building gem with GemBuildTask?


回答1:


It's actually pretty easy to set up a rake task that installs a bunch of gems:

task :install_gems do
  require "rubygems"
  require "rubygems/dependency_installer"

  installer = Gem::DependencyInstaller.new

  [["rack"], ["merb-core", "1.0.12"]].each do |args|
    installer.install(*args)
  end
end

Of course, you could extract this into a method and write a prettier way to specify your dependencies, but this should work great.




回答2:


I think currently you'd have to write a custom rake task that talked to the Gem library.

It's possible that rip, the (very) new kid on the block, will make it all easier, but it's very early days.

But someone else may have a better way...




回答3:


If your app is packaged as a gem, you could add the dependencies to the gemspec and rubygems will attempt to install them for you when you install the gem.

There are a bunch of ways to make a gem out of some ruby code. Recently I have taken to using jeweler.

With it, you can install a project as a gem by running rake install. There are some instructions on how to do dependencies on its github wiki.



来源:https://stackoverflow.com/questions/1000749/how-to-quickly-initialize-ruby-project-development-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!