Autoload custom extension

I’m having problems loading a custom extension. I checked some other extensions and it seems like adding a lib/middleman_extension.rb file that loads the actual extension code, should do the trick (should maybe be mentioned in http://middlemanapp.com/advanced/custom/), but it’s not loaded when I activate the extension. I need to require the extension explicitly in my middleman app.
I’m using middleman v3.1.0.rc.1, maybe the process has changed in 3.1?

Where is the extension stored? If it’s in a gem required in the Gemfile, it will be auto-required. If it’s simply in your project, you’ll have to require it yourself.

The middleman_extension.rb is a hack to allow Middleman to discover extensions which provide templates outside of a Bundler context.

It’s in a gem that I require via path: '..' in the Gemfile of my Middleman project right now.

So when exactly is the middleman_extension.rb file necessary?
Should my gem work without it (and without explicitly requiring it)?

Got it! The problem was that the gem’s main file did not have the same name as the gem itself. The gem name is hyphenated (gem-name) while the gem main file underscored (gem_name). I added a lib/gem-name.rb that requires lib/gem_name.rb and now it works wonderfully, even without a lib/middleman_extension.rb.

Ah, yeah, Bundler does the auto-require and depends on the naming convention.