DEV Community

Phil Schalm
Phil Schalm

Posted on

3 2

Advanced Bundler

The following will be a (hopefully often) updated article with tricks to help utilize Bundler to its fullest.

DRY multi-platform gemspecs (2019-06-14)

  • Note the .dup call after loading the common specification. This is important as Bundler actually loads all (*.gemspec) files and Rubygems caches the results of evaling a Gem::Specification.load call. Without the .dup this means you'll end up modifying the same spec instance for every custom gemspec you want to have.
gemname.gemspec.common
Gem::Specification.new do |gem|
  gem.authors     = ["Phil Schalm"]
  gem.email       = ["notmyrealemail@nowhere.com"]
  gem.description = "Sample"
  gem.summary     = "Longer sample"
  gem.files       = %w[gemname.gemspec gemname-java.gemspec gemname.gemspec.common Gemfile]

  # Common dependencies here
end
gemname.gemspec
Gem::Specification.load(File.expand_path("gemname.gemspec.common", __dir__)).dup.tap do |gem|
  gem.instance_exec do
    self.name = "gemname"
    # 'Everything else' specific dependencies here
  end
end
gemname-java.gemspec
Gem::Specification.load(File.expand_path("gemname.gemspec.common", __dir__)).dup.tap do |gem|
  gem.instance_exec do
    self.name = "gemname-java"
    # Java specific dependencies here
  end
end
Gemfile
source 'https://rubygems.org'

gemspec name: RUBY_PLATFORM == "java" ? "gemname-java" : "gemname"

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay