我正在创建一个 Rails Web 应用程序,它使用一个共享模型库(作为 Rails 引擎),存储在一个子存储库(Git 子树)中。这个共享库包含对其他 Ruby gem 的依赖项(在我的例子中,HTTParty 和 Dalli),其中我想被包含这个共享库的父项目自动引用。
但是,我的 gem 的依赖项似乎没有在父项目中解析,当我启动我的 web 应用程序时,它缺少对共享库中那些 gem 依赖项的引用。(即NameError: uninitialized constant ApiClient::HTTParty
)如果我明确地将这些引用添加到我的网络应用程序的 Gemfile 中(如取消注释下面的 Gemfile 行),一切正常。
如何让这些依赖项“链”,并让父项目自动解析这些引用?
这是我的项目的样子:
[MyRailsApp]
-- ...
-- [app]
-- [config]
-- [lib]
-- [MyLib]
-- ...
-- [app]
-- [config]
-- [lib]
-- [MyLib]
-- version.rb
-- engine.rb
-- MyLib.gemspec
-- Gemfile
-- Gemfile
MyRailsApp/Gemfile:
source 'https://rubygems.org'
gem 'activesupport', '3.2.13', :require => 'active_support'
gem 'actionpack', '3.2.13', :require => 'action_pack'
gem 'actionmailer', '3.2.13', :require => 'action_mailer'
gem 'railties', '3.2.13', :require => 'rails'
...
# gem 'dalli'
# gem 'httparty'
gem 'MyLib', :path => 'lib/MyLib'
MyLib/MyLib.gemspec:
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "mylib/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "MyLib"
s.version = MyLib::VERSION
s.authors = ["David"]
s.email = ["ops@myemail.com"]
s.homepage = "http://www.mysite.com"
s.summary = "Shared Library"
s.description = "Shared Library"
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.add_dependency "rails", "~> 3.2.13"
s.add_dependency "dalli", ">= 2.6.4"
s.add_dependency "httparty", ">= 0.11.0"
end