Reputation: 499
I am writing a gem and I have it referenced in the Gemfile. Regardless of whether I call a rake task or start up Webbrick, that gem gets loaded.
I want to detect whether it was loaded from a Rake task or from the web server.
How can my gem detect what type of process loaded the gem?
Upvotes: 4
Views: 53
Reputation: 49151
You can look at $0 and see what "main" file loaded it and figure it out from that. Rake's main file is called "rake", your webserver shouldn't start from the same file.
Upvotes: 2