In my Rails app Gemfile, I have gem 'myfancygem', path: '/Users/matt/myfancygem'
This works as you'd expect.
I then added a configuration block feature to the gem, a la https://robots.thoughtbot.com/mygem-configure-block (and many others out there that are slight variants on this)
I created an initializer myfancygem.rb in my Rails app with the standard:
Myfancygem.configure do |config|
config.favorite_color = 'red'
end
When running my local app (either in rails console, or rails server), that favorite_color does NOT get set. It remains at the default specified inside the gem (nil
)
But if I push that gem to rubygems and load it normally (i.e. without the path
bit in the Gemfile), the initializer config works as expected.
Just in case I was doing something nutty in my gem, I git cloned the latest copy of the ReactOnRails gem, which does pretty much the same configuration approach. Then I pointed my Gemfile at the local ReactOnRails via path
. Guess what? SAME PROBLEM. The initializer I setup for my Rails app for ReactOnRails seems to be ignored. I even sprinkled puts
statements into the initializers to prove they were getting executed and the configuration was being set, but then it would reset back to defaults right after Rails.application.initialize!
in environment.rb
Ummm... what the heck?
Is this a known bug in Rails? Or Bundler? or something? Or is there some gotcha I'm missing? Or something I could have done wrong that I'm not realizing?