Gemfile和gemspec中必须有哪些依赖项?

时间:2015-03-06 11:48:06

标签: ruby-on-rails gem

无法确定rails gem必须指定其依赖项的位置?在gemspec中的Gemfile中?生成的Gemfile具有以下描述:

# Declare your gem's dependencies in malibu.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

但我仍然可以理解。你能帮助我吗?谢谢

1 个答案:

答案 0 :(得分:1)

如果您正在开发新的gem,那么您将要使用add_dependency .gemspec 中声明所有生产就绪的宝石。

对于Gemfile本身,正如评论所述,它用于添加仍在开发中的依赖项(即未发布)。例如,如果要使用最新的Rails边缘版本,则必须使用gitgithub选项(例如gem "rails", github: "rails/rails")指定该依赖关系。这些选项仅在 Gemfile 中可用,而不在.gemspec中。

通常,您希望始终将依赖项放在.gemspec中,并且只在需要时才使用Gemfile。