2013-07-25 94 views
4

我確定這真的很明顯,但我對ruby比較陌生。我想使用rake/albacore來自動完成一些任務。我想打包使用捆綁器在我的構建服務器上使用。現在我想做一個愚蠢的任務,使用mixlib-shellout模擬sys帳戶。爲此,我有以下的Gemfile:沒有安裝gem dependencies

source 'http://rubygems.org' 
gem 'mixlib-shellout' 
gem '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 

,我只看到正在安裝耙......沒有的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) 

我使用紅寶石2.0和1.3.5打捆

感激地收到任何幫助搞定。

回答

1

我建議用* .gemspec文件設置你的gem。要做到這一點,你的Gemfile變得非常簡單:

source 'https://rubygems.org' 
gemspec 

然後寫一個新文件「GEM_NAME.gemspec」。這裏有一個例子:

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 

您需要添加一個單獨的spec.add_runtime_dependency每個因寶石。上面的例子包括「ruby-terminfo」寶石。

此外,您需要設置spec.files字段以反映您的寶石文件和文件夾結構。

查看RubyGem Guide瞭解更多詳情。