如何在.gemspec文件中指定运行时依赖项?

时间:2012-06-06 07:21:36

标签: ruby ruby-on-rails-3 rubygems gem

我创建了一个gem(apple_store_search)。它取决于另外两个宝石(curl和json)。我的.gemspec看起来像

# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "apple_store_search/version"

Gem::Specification.new do |s|
  s.name        = "apple_store_search"
  s.version     = AppleStoreSearch::VERSION
  s.authors     = "Shamith c"
  s.email       = "shamithc@gmail.com"
  s.homepage    = ""
  s.summary     = %q{This is for searching in app in apple store}
  s.description = %q{Exited to watch its progress}

  s.rubyforge_project = "apple_store_search"

  s.files         = `git ls-files`.split("\n")
  s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
  s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
  s.require_paths = ["lib"]

  # specify any dependencies here; for example:
  #s.add_development_dependency "rspec"
  s.add_dependency('curl', '0.0.9')
  s.add_dependency('json', '1.7.3')
  s.add_runtime_dependency('curl', '0.0.9')
  s.add_runtime_dependency('json', '1.7.3')
end

我成功构建了这个gem。然后我试图在irb上加载这个gem,我得到了错误

NameError: uninitialized constant AppleStoreSearch::Search::CURL

此错误是由于curl gem造成的。

如果我需要'curl'和'json',我的宝石正确执行。

如何在加载'apple_store_search'gem时默认加载这些宝石(json和curl)?

1 个答案:

答案 0 :(得分:0)

您需要在code :: CURL而不是CURL

中引用顶级命名空间