为什么我必须运行"捆绑执行弹簧"当我有一个bin / spring binstub?

时间:2014-03-21 09:50:32

标签: ruby-on-rails spring-gem

从命令行直接运行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

春天做了bundle exec spring binstub --all修补了。所以我想一切都配置正确吗?那么为什么我一直需要bundle exec

我正在使用Rails 4.0.4。

1 个答案:

答案 0 :(得分:0)

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

  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