Zhenya
Zhenya

Reputation: 6198

How to manage dependencies between my ruby projects?

This sounds like a basic question, but I can't find any answer to it on the Internet.

So I have a git ruby project database_models. It's a gem. I want 3 other project to use it. I've added a dependency on this project to those 3 projects like this:

gem "database_models", :git => "path", :branch => master

Now, I want a a develop branch of those 3 projects to use the develop branch of database_models, and I want a master branch of those 3 projects to use the master branch of database_models, so that my production environment is stable and independent of my development environment.

I can see 4 options of doing this, and I don't like any of them:

  1. Deploy database_models to the server, and update those 3 projects to reference database_models using a path, instead of git

  2. Git submodule

  3. User different versions of database_models gem (1.1, 1.2, 1.3...). I would probably need my own gem server for that, right?

  4. Write some code in a Gemfile that would choose the correct branch based on the environment where "bundle install" is run.

Upvotes: 1

Views: 335

Answers (2)

Ken Stipek
Ken Stipek

Reputation: 1522

User different versions of database_models gem (1.1, 1.2, 1.3...). I would probably need my own gem server for that, right?

I would do this and simply have my Gemfile select the correct gem via a tag. Here is an example: git 'https://github.com/rails/rails.git', tag: 'v5.0.0'

So you can do the same while storing your custom gem on github (no gem server required).

Here is how to use tags with Git.

This should give you the flexibility you need.

Upvotes: 1

mahemoff
mahemoff

Reputation: 46399

Usually you'd use Bundler with a local path. Your Gemfile points to the Git or Github repo using git or github:

gem 'spree', github: 'spree/spree', branch: 'master'

Note that includes the branch. You can make each of your projects use a different branch of your gem if you want to. You can make each of your projects use a different branch of your gem if you want to. You can also use groups to deploy different versions of your gem depending on the environment:

group :development, :test
  gem 'spree', github: 'spree/spree', branch: 'bleedinedge'
end

group :staging, :production
  gem 'spree', github: 'spree/spree', branch: 'master'
end

The above will work fine as long as you keep pushing to the Github. But thanks to local config, you can run the following on your command line:

bundle config local.database_modules ~/Projects/gems/spree

That will add a line to your ~/.bundle/config, so when you run bundle in your projects, it will pull it from your local repo.

Upvotes: 1

Related Questions