When I run bundle install I see that it includes my gem and also the
gon gem as expected.
From a view helper in the app I am calling helper method in a module
in my gem's lib folder, and in there I have code such as
gon.variable = ...
and that code throws an error
ActionView::Template::Error (undefined method `gon' for
#<PlotValuesController:0x000000067bbc30>)
where PlotValuesController is the controller in the app. If I
explicitly include gon in the Gemfile for the app then all works as
correctly.
Any suggestions as to why I have to explicitly include gon in the
application's Gemfile, when it is included anyway via the dependency
in my gem?
Gemfile.lock with and without gon included explicitly can be seen at
Any suggestions as to why I have to explicitly include gon in the
application's Gemfile, when it is included anyway via the dependency
in my gem?
Bundler's autorequire feature only requires gems listed in the Gemfile, not their dependencies. You could either require gon from within your gem, when it is required (this may or may not be appropriate ) or require it from your app.
Thanks all, that was the point I had missed, that bundler ensures all
the gems are available but only those explicitly included in Gemfile
are automatically loaded. I required gon in the gem and now all is
well.