【问题标题】:What are the best practices for updating a gemspec's file list?更新 gemspec 文件列表的最佳实践是什么?
【发布时间】:2013-04-24 22:15:48
【问题描述】:

关于 gemspecs 的文件列表。

我注意到,jeweler 使用项目中的文件列表手动更新此列表。例如

Gem::Specification.new do |s|
  # stuff

  s.files = [
    "lib/somegem.rb",
    "README.md"
  ]
  # ... more stuff

end

是否有任何证据表明使用git ls-filesDir.glob('**/*') 为gemspec 动态生成文件列表会导致在项目(尤其是rails 项目)中使用gem 时出现性能问题?比如?

Gem::Specification.new do |s|
  # stuff

  s.files = `git ls-files`.split("\n")
  # ... more stuff

end

【问题讨论】:

    标签: ruby-on-rails ruby rubygems gem gemspecs


    【解决方案1】:

    动态生成文件列表非常好。事实上,Gemspec Specification docs 展示了几种方法来做到这一点。

    来自 Rubygems 文档:

    require 'rake'
    spec.files = FileList['lib     .rb',
                          'bin/*',
                          '[A-Z]*',
                          'test/   *'].to_a
    
    # or without Rake...
    spec.files = Dir['lib/   *.rb'] + Dir['bin/*']
    spec.files += Dir['[A-Z]*'] + Dir['test/**/*']
    spec.files.reject! { |fn| fn.include? "CVS" }
    

    我会坚持使用上述方法而不使用git ls-files,因为我不会假设每个使用 gem 的系统都会安装 git。

    【讨论】:

    • 唯一需要 git 的系统是那些构建 gem 的系统吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多