Using "custom" ruby gems

AI-generated summary

Using Custom Ruby Gems

FerrariFlunker is developing a fork of a plugin that requires the discordrb ruby gem, but the latest version on RubyGems (3.4.0) is outdated and buggy. The latest version is available on GitHub, but not published to RubyGems.

merefield clarifies that the GitHub repository is the official one and that the gem document not listing the latest version (3.4.1) is an issue. They suggest referencing the GitHub repository directly, but FerrariFlunker has tried this method without success.

fzngagan provides an example of an official plugin that uses a local copy of a gem and suggests a similar approach. This method involves creating a local copy of the git repository (not a submodule) and including the libdir in the plugin.rb file.

FerrariFlunker confirms that this method works, and thanks fzngagan and merefield for their help.

Alternatively, fzngagan suggests publishing the gem via GitHub packages, which can be a viable solution.

Hello! I’ve been struggling with this for a few days, so any help is appreciated!

I’m developing a fork of a plugin that requires the discordrb ruby gem. For whatever reason, the most up to date version on discordrb | RubyGems.org | your community gem host is 3.4.0, which is about two years old and buggy.

Luckily, there’s an up to date version of the plugin that exists here GitHub - shardlab/discordrb: Discord API for Ruby · GitHub, but hasn’t been able to be published to RubyGems :confused:

How can I go about using the github version of this gem/dependency? I feel like I’ve tried just about everything.

Have you seen?: Discord Bot Construction Kit 🤖

It’s still under active development. Speaking to the developers recently the next version will be out “when it’s done”. Amongst other things they are working on Threading support.

These are the same thing. It’s just that the gem document only claims 3.4.0 as latest. The other is the official repo. If you click the Homepage link on your first link it takes you to your second link ;). I have no idea why the gem document does not list 3.4.1.

You can reference a GitHub repo if you really have to: https://stackoverflow.com/questions/2823492/install-gem-from-github-branch

I have! I’m pretty sure our plugin is a fork of a fork of that. We require some specific logic in our case, so it makes sense to develop our own version.

What would this look like in the discourse setting? I feel like I’ve tried every method of declaring the dependency via github in plugin.rb already (check our commit history :smile:)

image

Our build fails with every gem syntax I’ve tried that tries to point to the github source. I’m pretty sure it has to do with how discourse/lib/plugin_gem.rb at main · discourse/discourse · GitHub tries to find the .gemspec file for plugin gems. Would you be able to give me the steps for a workaround?

Hi @FerrariFlunker
Here’s in an example of of an official plugin which uses a local copy of the holidays gem. I think you can use a similar pattern in your case.

Here’s how its included.

A local version of the git repo (note: cannot be a submodule, has to be a true local copy) and the libdir inclusion lines worked perfectly! Thank you so much for your help, it’s incredibly appreciated @fzngagan and @merefield :+1:

Hopefully this topic will help others find this answer, it’s been quite the journey to figure this out :smile:

You can also publish the gem via github packages. Publishing a Ruby gem to the GitHub Package Registry | michaelheap.com