Ruby gem: how to run initialization on startup?

Go To StackoverFlow.com

0

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

2012-04-05 18:32
by Artem
I think this question needs some more clarification. What do you mean by gem startup? Do you mean if a gem is required then action x should always be executed - sunnyrjuneja 2012-04-05 19:35


0

Using Railties initialization fixed and issue for me. init.rb was not run in appropriate time to have Rails.root configured.

2012-04-06 21:38
by Artem


0

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).

2012-04-05 19:53
by Confusion
Ads