How to put common utils in the app without polluing environm

I have developed some common utils which I use in all my RoR apps.
It’s a moule with a lot of utilities. In order t use them currently
this is what I do.

environment.rb
include AppCommonUtils

The file app_common_utils reside in lib directory. It works but I don’t
like it.

In order to use these utilities I need to tinker with the
environment.rb of each application. So I put this module as a pluging.
But in int init.rb of the plugin I don’t know what to write which will
be equivalent of putting the module in the environment.rb.

I’m suspecting it will be something along the line of

something.send(:include, AppCommonUtils)

Could someone help me out with what that something should be here?

Thanks

In order to use these utilities I need to tinker with the
environment.rb of each application. So I put this module as a pluging.
But in int init.rb of the plugin I don’t know what to write which will
be equivalent of putting the module in the environment.rb.

I’m suspecting it will be something along the line of

something.send(:include, AppCommonUtils)

Rails will load your AppCommonUtils module automatically without your
having to tinker with environment.rb.

If you want to include your module, i.e. above and beyond the
auto-‘require’ I just mentioned, you could try something like this
(though I’m not 100% sure about this) inside your module:

module AppCommonUtils
def self.included(base)
base.extend self
end
end

Regards,
Andy S.

The module AppCommonUtils needs to be included in environment.rb for
it to be invoked. Otherwise I don’t think it’ll work.

  • Neeraj