我在捆绑器 1.7 上使用"捆绑 gem gem_name"构建了一个 gem。 我现在使用的是捆绑器 1.9.4。 我使用 1.9.4 创建了一个新 gem,我注意到 gem 模板发生了一些变化。 我决定回到旧的 1.7 gem 并将其升级到新格式; 我在运行新的 bin/console
命令时遇到错误。
我已将 .gemspec 文件更新为:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'basic/version'
Gem::Specification.new do |spec|
...other settings here...
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end
spec.files = `git ls-files -z`.split("x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.9"
spec.add_development_dependency "rake", "~> 10.0"
end
我还创建了bin/console
文件。
当我从命令行运行bin/console
时,出现以下错误
: No such file or directory
当我在使用捆绑器 1.9.4 生成的 gem 中运行 bin/console 时,一切正常。 我错过了什么?
通了。 我在Windows上的Sublime Text中创建了bin/console文件。这导致Windows行尾被添加到文件中,这使得该文件在Linux中无法执行。 以下是我为理清事情所做的工作:
我在 Vim 中打开了 bin/console,以确保文件以 Unix 行结尾保存:
vi bin/console
然后键入
:set fileformat=unix
按回车键。Vim可能看起来什么都不做(即 :set fileformat=unix"
可能仍然出现在行上)
接下来保存并通过键入关闭文件:
:wq!
现在垃圾箱/控制台应该可以工作了。
我还更改了Sublime Text,以强制它默认使用Unix行尾。 单击Preferences/Settings-User
菜单选项。 添加以下设置:
{
"default_line_ending": "unix",
}
在进行上述更改后,您可能可以通过Sublime Text打开并保存文件(如果您使用该编辑器),而不是通过Vim。