How to properly require a GitHub gem dependency in another gem?

I’m having trouble requiring a gem from GitHub inside another gem. I have a foundation gem hosted on GitHub that contains a simple module structure:

module Display
  class Foundation
    # basic methods here
  end
end

In my second gem’s Gemfile, I’m adding the GitHub dependency like this:

gem "display-foundation", "~> 0.1.0", git: "[email protected]:myuser/display-foundation.git"

Then in my second gem’s main file, I’m trying to require it:

require "display-foundation"

But I keep getting a LoadError saying it cannot load the file. When I add the same gem to a Rails app’s Gemfile, everything works fine and the require statement works perfectly. What am I missing when trying to use a GitHub gem as a dependency in another gem? Is there something special I need to do to make the require work properly?

I encountered a similar issue a while back with a gem that depended on another internal gem. The core problem was that your gem needs to declare its GitHub dependency in the gemspec file, not just the Gemfile. While the Gemfile is used for development, the gemspec is crucial for defining runtime dependencies during installation. You cannot specify a git source directly in the gemspec, so I listed the dependency as a standard requirement and used the git source just in the Gemfile for development purposes. It’s crucial to ensure that your foundation gem has the correct version numbers and tags for proper reference in the gemspec. Alternatively, using Bundler’s path option for development can streamline the process, then switching to an official gem release for production use.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.