【问题标题】:Why do I have to run "bundle exec spring" when I have a bin/spring binstub?当我有一个 bin/spring binstub 时,为什么我必须运行“bundle exec spring”?
【发布时间】:2014-04-02 16:56:47
【问题描述】:

当从命令行直接运行spring(没有bundle exec)时,什么也没有发生!只有在运行bundle exec spring 时才有效:

$ spring status
$ bundle exec spring status
Spring is running:

21990 spring server | synaesthesia | started 1 min ago 
22046 spring app    | synaesthesia | started 43 secs ago | test mode    

我的bin/spring binstub 看起来像这样:

#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast
# It gets overwritten when you run the `spring binstub` command

unless defined?(Spring)
  require "rubygems"
  require "bundler"

  if match = Bundler.default_lockfile.read.match(/^GEM$.*?^    spring \((.*?)\)$.*?^$/m)
    ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
    ENV["GEM_HOME"] = ""
    Gem.paths = ENV

    gem "spring", match[1]
    require "spring/binstub"
  end
end

它已被 spring 修补,执行 bundle exec spring binstub --all。所以我猜一切都配置正确?那么为什么我一直需要bundle exec

我使用的是 Rails 4.0.4。

【问题讨论】:

    标签: ruby-on-rails spring-gem


    【解决方案1】:

    原来我在github上使用了一个特定的分支,所以bin/spring可执行文件中spring创建的正则表达式不匹配:

      if match = Bundler.default_lockfile.read.match(/^GEM$.*?^    spring \((.*?)\)$.*?^$/m)
    

    我将这一行更改为:

    如果匹配 = Bundler.default_lockfile.read.match(/^GEM|GIT$.?^ spring ((.?))$.*?^$/m)

    现在可以了。很奇怪,当正则表达式不匹配时至少没有抛出一些错误?!

    更新

    我在 GitHub Spring 项目中添加了一个关于这个的问题:https://github.com/rails/spring/issues/277

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 2014-02-16
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 2015-05-25
      • 1970-01-01
      • 2018-07-13
      相关资源
      最近更新 更多