Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to search through the source code of all the gems for a project

I'm getting a warning on my console that i'd like to resolve. The problem is that i'm not sure which gem is causing this warning. What is the best way to search through the source for all the gems for a specific project.

Thanks

like image 849
montrealmike Avatar asked Dec 04 '22 04:12

montrealmike


2 Answers

The accepted answer will search through all gems installed on your system, possibly including ones that aren't actually dependencies.

To search only through actual dependencies of your app, not just any installed gem, from the app root dir:

grep -r "escape_javascript" $(bundle show --paths) .

The . on the end will make sure to search your actual app too, not only it's dependencies. If that's what you want.

From http://hectorcorrea.com/blog/bundle-grep-and-rails-applications/68

like image 128
jrochkind Avatar answered May 20 '23 05:05

jrochkind


I usually do the following:

cd `bundle show rails` # Go to the directory having rails gem content
cd ..                  # Go one level up to the folder having all gems
grep -ir escape_javascript *  # search for the required text in all files
> actionview-4.1.6/lib/action_view/helpers/javascript_helper.rb:      def escape_javascript(javascript)
> actionview-4.1.6/lib/action_view/helpers/javascript_helper.rb:      alias_method :j, :escape_javascript

EDIT: The answer below by jrochkind is the correct answer; my answer is incorrect as it searches through all the gems installed in the system.

like image 22
Prakash Murthy Avatar answered May 20 '23 07:05

Prakash Murthy