[Bundler] Using a Git repository as ruby gem server

Hello everyone!

As surely everyone knows, one can specify a Git repository in the Gemfile as a gem source, like

gem 'mygem', :git => git@git.myserver.com:myuser/mygem.git'

However, this doesn't fully accomplish my needs. Imagine my repository has some tagged commits, like "1.1.0", "1.1.1", "1.2.0" etc. If I specify a dependency on "mygem" with a version requirement of, say, "~> 1.1.0, <= 1.2.0", how can I pull the commit with the best-matching version number? Right now, it would only check out one particular commit (HEAD on master branch), scanning its gemspec and either deliver it if it doesn't contradict the requirements or returns an error if it does, rather than searching through all commits for the best fit. Is there any way I can do that? I really would not like to use an additional gem server besides my Git repository.

Kind regards,
Manfred

It's not quite as convenient as just specifying version numbers but you can
also supply a ref: argument with the specific commit hash in git. So you
can do:

gem 'mygem', :git => git@git.myserver.com:myuser/mygem.git', :ref =>
'ae1245.....'

Hi, thanks for your answer. The problem with that approach is that I now have to specify the version twice: once in my gemspec (where I define the dependency) and then again in my Gemfile (where the version requirement would be totally ignored). Additionally, if a new version came out, I'd have to maintain and update every Gemfile I have which surely would be error-prone and tedious.

What I have tried now is to write a script inside the Gemfile: In my gemspec, I define a global variable to be a reference to the gemspec object such that I have the requirements info available in my Gemfile. There I load a list of all tagged commits from git and then manually analyze it for a best match. Afterwards, I load it via gem ..., :tag => ...
It somewhat works, however it feels awkward and Bundler will execute the code at every command, not just when doing "bundle install" which is kind of annoying. Is there any sort of "hook" where I can listen on particular events like bundle install or bundle update?

Kind regards,
Manfred

Have you had a look at: http://guides.rubygems.org/run-your-own-gem-server.

For personal use, you can set that up on a small, secured server.

The short answer is, "no, there's not a convenient way to do that."

ยทยทยท

On Thu, Mar 30, 2017 at 6:31 AM, Mugurel Chirica <chirica.mugurel@gmail.com> wrote:

Have you had a look at: Run your own gem server - RubyGems Guides
.

For personal use, you can set that up on a small, secured server.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;