未安装gem依赖项

时间:2013-07-25 20:28:18

标签: ruby dependencies rake bundler

我确信这很明显,但我对红宝石很新。我想使用rake / albacore来自动执行某些任务。我想打包它以使用bundler在我的构建服务器上使用。现在我想做一个使用mixlib-shellout冒充sys帐户的哑任务。为此,我有以下Gemfile:

source 'http://rubygems.org'
gem 'mixlib-shellout'
gem 'rake'

和以下rake文件:

require 'rubygems'
require 'bundler/setup'

require 'mixlib/shellout'

task :default do
    whomai = Mixlib::ShellOut.new("whoami.exe", :user => "username", :domain => "DOMAIN", :password => "password")
    whoami.run_command
end

我跑

bundle install

我只看到rake正在安装...... Gemfile.lock dep树中没有其他依赖项......这是正常的吗?

PS C:\Users\Ben\src\ruby_test> bundle install
Fetching gem metadata from http://rubygems.org/...........
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies...
Installing rake (10.1.0)
Using bundler (1.3.5)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
然后我跑

bundle exec rake

我得到了回报

rake aborted!
cannot load such file -- mixlib/shellout
C:/Users/Ben/src/ruby_test/rakefile.rb:4:in `require'
C:/Users/Ben/src/ruby_test/rakefile.rb:4:in `<top (required)>'
(See full trace by running task with --trace)

我正在使用ruby 2.0和bundler 1.3.5

感激不尽的任何帮助。

1 个答案:

答案 0 :(得分:1)

我建议使用* .gemspec文件设置gem。为此,您的Gemfile变得非常简单:

source 'https://rubygems.org'
gemspec

然后写一个新文件&#34; GEM_NAME.gemspec&#34;。这是一个例子:

Gem::Specification.new do |spec|
  spec.name          = GAME_NAME
  spec.version       = VERSION
  spec.authors       = AUTHORS
  spec.email         = EMAILS
  spec.summary       = SUMMARY
  spec.description   = DESCRIPTION
  spec.homepage      = HOMEPAGE

  spec.files         = Dir['rakefile.rb', '*.gemspec']
  spec.files         += Dir['bin/**', 'lib/**/*.rb']

  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
  spec.require_paths = ["lib"]

  spec.add_runtime_dependency "ruby-terminfo", "~> 0.1"

  spec.add_development_dependency "bundler", "~> 1.7"
  spec.add_development_dependency "rake", "~> 10.0"
end

您需要为每个相关的gem添加单独的spec.add_runtime_dependency。上面的例子包括&#34; ruby​​-terminfo&#34;宝石。

此外,您需要设置spec.files字段以反映您的gem的文件和文件夹结构。

有关详细信息,请参阅RubyGem Guide