I'm converting Rails plugin to a gem and it has initializations in init.rb which used to run for plugin on plugin startup. But when I converted this plugin to gem this code no longer runs! What should I do to execute code on gem startup?
And initialization is Rails-specific, it require ::Rails.root
Using Railties initialization fixed and issue for me. init.rb was not run in appropriate time to have Rails.root configured.
My build currently shows deprecation warnings like
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from $PROJECT_HOME/config/environment.rb:8)
I think that has your answer ;)
Edit:
I just realized that perhaps it's also fine if it runs when the gem is loaded. In that case, lib/same-name-as-gem.rb
is automatically required when a gem is loaded (via bundler/rubygems).