开发具有依赖关系的多个Rails插件

时间:2023-01-21 16:15:33

I'm starting to build a series of plugins and engines in a project I'm developing and I've run into the issue of having to list the paths to dependencies in all of the Gemfiles for the main application and the plugins/engines if I want rake to work.

我开始在我正在开发的项目中构建一系列插件和引擎,并且我遇到了必须在主应用程序和插件/引擎的所有Gemfiles中列出依赖关系路径的问题。我想耙工作。

Rake works fine for the main application because it's Gemfile lists the relative paths to the plugins/engines I want, but when a plugin/engine is dependent on another and does not have the relative paths all listed, using rake rdoc I'll get an error like the following (presumably I'll get the same error trying to run tests/the dummy application/etc):

Rake适用于主应用程序,因为它的Gemfile列出了我想要的插件/引擎的相对路径,但是当插件/引擎依赖于另一个并且没有列出相关路径时,使用rake rdoc我会得到一个像下面这样的错误(大概我会在尝试运行测试/虚拟应用程序/等时遇到同样的错误):

Bundler could not find compatible versions for gem "user":
  In Gemfile:
    auth (>= 0) ruby depends on
      user (>= 0) ruby
Could not find gem 'user (>= 0) ruby', which is required by gem 'auth (>= 0) ruby', in any of the sources.

Rather than having to use paths, I've tried specifying the git repository in the plugins/engines like so:

我没有使用路径,而是尝试在插件/引擎中指定git存储库,如下所示:

# User engine
gem 'user', git: 'https://localhost/git/project/user.git', branch: 'master'

And then using bundler config local.user /path/to/local/repo command to make it point to a local repository for development. This appeared to work perfectly... until I change the version of the plugin in the local repo, then it spits out this error in any dependent plugin/engine/application:

然后使用bundler config local.user / path / to / local / repo命令使其指向本地存储库以进行开发。这似乎完美地工作......直到我在本地仓库中更改插件的版本,然后它在任何依赖的插件/引擎/应用程序中吐出此错误:

Could not find user-0.0.1 in any of the sources
Run `bundle install` to install missing gems.

Whilst that isn't really much of an issue-- the version number will be changed at the end anyway --it also turns out that it will throw the following error if you're on a branch in the local repo instead of master:

虽然这不是什么大问题 - 版本号最终会在最后改变 - 如果你在本地仓库而不是主仓的分支上,它也会抛出以下错误:

Local override for user at /path/to/local/repo is using branch deleteme but Gemfile specifies master

And omitting the branch option from the Gemfile leaves me with this error:

省略Gemfile中的分支选项会给我留下这个错误:

Cannot use local override for user at /path/to/local/repo because :branch is not specified in Gemfile. Specify a branch or use `bundle config --delete` to remove the local override

So am I just stuck with having , path: "../local-repo-directory" strewn about all of the Gemfiles for plugins/engines with dependencies on one another whilst in development or is there a way of developing multiple interdependent plugins/engines for Rails at the same time that doesn't use a really sloppy/inelegant solution?

所以我只是坚持使用路径:“../local-repo-directory”散布所有Gemfiles,因为插件/引擎在开发过程中彼此依赖,或者有一种开发多个相互依赖的插件/引擎的方法对于Rails同时不使用真正草率/不优雅的解决方案?

I'm drawing blanks on other ways to do this, so any help would be greatly appreciated. I hope I've explained this well enough, but if there's anything else I can clarify, let me know.

我正在绘制其他方法的空白,所以任何帮助将不胜感激。我希望我已经很好地解释了这一点,但如果还有什么我可以澄清的,请告诉我。

Thanks!

1 个解决方案

#1


0  

Stick with specifying git repositories in your Gemfile and using bundle local overrides to work on them.

坚持在Gemfile中指定git存储库并使用bundle本地覆盖来处理它们。

Possible problems with solutions: 1. Local override for user at /path/to/local/repo is using branch deleteme but Gemfile specifies master If your Gemfile specifies branch "master" then the local override should have branch "master" checked out. This is because the goal of a local override is so that you can work on a gem in a local folder while running and testing the application. In production it will check out the branch and revision specified in the Gemfile and Gemfile.lock and it should offcourse be exactly what you are running with your local override.

解决方案可能出现的问题:1。/ path / to / local / repo中用户的本地覆盖使用分支deleteme但Gemfile指定master如果您的Gemfile指定分支“master”,则本地覆盖应该检出分支“master”。这是因为本地覆盖的目标是在运行和测试应用程序时可以在本地文件夹中处理gem。在生产中,它将检查Gemfile和Gemfile.lock中指定的分支和修订版本,它应该是您正在运行的本地覆盖。

2. Could not find user-0.0.1 in any of the sources Run `bundle install` to install missing gems. When you run bundle install it places a version number for each gem in the Gemfile.lock. This file is added to git so that other developers and your production server runs the same versions of the gems as you do. Your Gemfile.lock needs to specify the same version of your gem as what is returned in the local override gemspec file. If you incremented the version number in the local override you need to run "bundle update gemname" in the application that uses it so that it updates the Gemfile.lock. Note that bundler caches everything in a gemspec file until you increment the version. Thus you can't add new dependencies or change dependency versions in a gemspec if you don't increase the version number in that gemspec.

2.无法在任何源中找到user-0.0.1运行`bundle install`来安装缺少的gem。当您运行bundle install时,它会为Gemfile.lock中的每个gem设置一个版本号。此文件已添加到git中,以便其他开发人员和您的生产服务器运行与您相同版本的gem。您的Gemfile.lock需要指定与本地覆盖gemspec文件中返回的gem相同的gem版本。如果您在本地覆盖中增加了版本号,则需要在使用它的应用程序中运行“bundle update gemname”,以便更新Gemfile.lock。请注意,在您递增版本之前,bundler会将所有内容缓存在gemspec文件中。因此,如果不增加gemspec中的版本号,则无法在gemspec中添加新依赖项或更改依赖项版本。

The git-bundle gem

git-bundle gem

If you use a git repository in your Gemfile with local overrides bundler will store git revision hashes in your Gemfile.lock as mentioned above. Example:

如果您在Gemfile中使用git存储库并使用本地覆盖,则Bundler将在您的Gemfile.lock中存储git修订版哈希,如上所述。例:

Gemfile: gem 'example', git: 'https://github.com/your_name/example.git', branch: :master

Gemfile:gem'example',git:'https://github.com/your_name/example.git',branch :: master

Bundle config shell command: bundle config local.example /path/to/local/git/repository

Bundle config shell命令:bundle config local.example / path / to / local / git / repository

Gemfile.lock (auto generated): GIT remote: https://github.com/your_name/example.git revision: b9270e61abb89e1ff77fb8cfacb463e4d04388ad branch: master

Gemfile.lock(自动生成):GIT远程:https://github.com/your_name/example.git修订版:b9270e61abb89e1ff77fb8cfacb463e4d04388ad分支:master

After you commit in the local override repository you will need to run bundle install on your main application so that it rebuilds the Gemfile.lock to include the new revision hash and commit it. I recommend using the gem below as it automates this process for you and also aids in other scenarios. See the gem page for exact detail.

在本地覆盖存储库中提交后,您将需要在主应用程序上运行bundle install,以便重新构建Gemfile.lock以包含新的版本哈希并提交它。我建议使用下面的gem,因为它可以为您自动执行此过程,也可以帮助其他方案。有关详细信息,请参阅gem页面。

https://github.com/EPI-USE-Labs/git-bundle

The activesupport-decorators gem

activesupport-decorators gem

As a sidenote, when you need to extend classes between your gems you can use the decorator pattern which is implemented elegantly by the activesupport-decorators gem:

作为旁注,当您需要在宝石之间扩展类时,您可以使用由activesupport-decorators gem优雅实现的装饰器模式:

https://github.com/EPI-USE-Labs/activesupport-decorators

#1


0  

Stick with specifying git repositories in your Gemfile and using bundle local overrides to work on them.

坚持在Gemfile中指定git存储库并使用bundle本地覆盖来处理它们。

Possible problems with solutions: 1. Local override for user at /path/to/local/repo is using branch deleteme but Gemfile specifies master If your Gemfile specifies branch "master" then the local override should have branch "master" checked out. This is because the goal of a local override is so that you can work on a gem in a local folder while running and testing the application. In production it will check out the branch and revision specified in the Gemfile and Gemfile.lock and it should offcourse be exactly what you are running with your local override.

解决方案可能出现的问题:1。/ path / to / local / repo中用户的本地覆盖使用分支deleteme但Gemfile指定master如果您的Gemfile指定分支“master”,则本地覆盖应该检出分支“master”。这是因为本地覆盖的目标是在运行和测试应用程序时可以在本地文件夹中处理gem。在生产中,它将检查Gemfile和Gemfile.lock中指定的分支和修订版本,它应该是您正在运行的本地覆盖。

2. Could not find user-0.0.1 in any of the sources Run `bundle install` to install missing gems. When you run bundle install it places a version number for each gem in the Gemfile.lock. This file is added to git so that other developers and your production server runs the same versions of the gems as you do. Your Gemfile.lock needs to specify the same version of your gem as what is returned in the local override gemspec file. If you incremented the version number in the local override you need to run "bundle update gemname" in the application that uses it so that it updates the Gemfile.lock. Note that bundler caches everything in a gemspec file until you increment the version. Thus you can't add new dependencies or change dependency versions in a gemspec if you don't increase the version number in that gemspec.

2.无法在任何源中找到user-0.0.1运行`bundle install`来安装缺少的gem。当您运行bundle install时,它会为Gemfile.lock中的每个gem设置一个版本号。此文件已添加到git中,以便其他开发人员和您的生产服务器运行与您相同版本的gem。您的Gemfile.lock需要指定与本地覆盖gemspec文件中返回的gem相同的gem版本。如果您在本地覆盖中增加了版本号,则需要在使用它的应用程序中运行“bundle update gemname”,以便更新Gemfile.lock。请注意,在您递增版本之前,bundler会将所有内容缓存在gemspec文件中。因此,如果不增加gemspec中的版本号,则无法在gemspec中添加新依赖项或更改依赖项版本。

The git-bundle gem

git-bundle gem

If you use a git repository in your Gemfile with local overrides bundler will store git revision hashes in your Gemfile.lock as mentioned above. Example:

如果您在Gemfile中使用git存储库并使用本地覆盖,则Bundler将在您的Gemfile.lock中存储git修订版哈希,如上所述。例:

Gemfile: gem 'example', git: 'https://github.com/your_name/example.git', branch: :master

Gemfile:gem'example',git:'https://github.com/your_name/example.git',branch :: master

Bundle config shell command: bundle config local.example /path/to/local/git/repository

Bundle config shell命令:bundle config local.example / path / to / local / git / repository

Gemfile.lock (auto generated): GIT remote: https://github.com/your_name/example.git revision: b9270e61abb89e1ff77fb8cfacb463e4d04388ad branch: master

Gemfile.lock(自动生成):GIT远程:https://github.com/your_name/example.git修订版:b9270e61abb89e1ff77fb8cfacb463e4d04388ad分支:master

After you commit in the local override repository you will need to run bundle install on your main application so that it rebuilds the Gemfile.lock to include the new revision hash and commit it. I recommend using the gem below as it automates this process for you and also aids in other scenarios. See the gem page for exact detail.

在本地覆盖存储库中提交后,您将需要在主应用程序上运行bundle install,以便重新构建Gemfile.lock以包含新的版本哈希并提交它。我建议使用下面的gem,因为它可以为您自动执行此过程,也可以帮助其他方案。有关详细信息,请参阅gem页面。

https://github.com/EPI-USE-Labs/git-bundle

The activesupport-decorators gem

activesupport-decorators gem

As a sidenote, when you need to extend classes between your gems you can use the decorator pattern which is implemented elegantly by the activesupport-decorators gem:

作为旁注,当您需要在宝石之间扩展类时,您可以使用由activesupport-decorators gem优雅实现的装饰器模式:

https://github.com/EPI-USE-Labs/activesupport-decorators