我想知道 Gemfile 上是否有普遍接受的样式。
我生成新的 Rails 应用程序,打开 Gemifile,然后在适当的组(测试、开发等)下添加我需要的所有 gem。
当我查看 Rails 开源项目时,大多数项目都不是这样构建的。他们将标准安装的 Rails gem 按原样保留或注释掉,然后在其下面有第二个 gem 列表,用于应用程序实际需要的 gem。对我来说,这不太可读,但是很多人似乎这样做是有原因的吗?
最佳答案
没有通用标准或共识,就像没有在 Ruby 文件中保留注释代码的通用标准一样。
一般来说,从我们习惯在没有 version control system 的情况下编写代码的时代起,将内容注释掉的想法就是一个坏习惯。 .
如果您不使用 Gem,则无需将其注释掉。在测试有/没有或出于任何原因暂时的不同行为时暂时将其注释掉是可以的,但是一旦您决定取出 gem ,就可以安全地将其删除。
就个人而言,我通常按以下方式构建 Gemfile:
source 'https://rubygems.org'
# Rails core gems at the top
gem 'rake'
gem 'rails', '4.2.5'
gem 'sass-rails', '~> 5.0'
.
.
.
gem 'responders', '~> 2.0'
# Gems, in alphabetical order
gem 'yajl-ruby', '~> 1.2.0', require: 'yajl'
gem 'bcrypt', '~> 3.1.0', require: 'bcrypt'
.
.
.
# Environment dependent gems, in alphabetical order
group :test do
gem 'database_cleaner', require: false
.
.
end
group :development do
gem 'letter_opener', '~> 1.4.0'
.
.
.
end
group :production do
gem 'clockwork', '~> 1.2.0', require: false
.
.
.
end
group :development, :test do
gem 'byebug', require: false
.
.
.
end
关于ruby-on-rails - Gemfile 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34677349/