8

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

montrealmike
  • 11,433
  • 10
  • 64
  • 86

2 Answers2

16

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

jrochkind
  • 22,799
  • 12
  • 59
  • 74
  • Using https://github.com/ggreer/the_silver_searcher : `ag i_search_for_escape_javascript --ruby \`bundle show --paths\`` – jmgarnier Mar 07 '17 at 15:14
4

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.

Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
  • `grep -ir escape_javascript *` `grep: *: No such file or directory` – Rodrigo Jan 14 '15 at 15:04
  • 1
    `No such file or directory` would be because of some unreadable/nonexistent files; fixed by passing `-s` http://stackoverflow.com/a/16297914/429758 ; `grep -isr escape_javascript *` . The bundle folder shouldn't have this problem though as it does not have any symlinks. – Prakash Murthy Jan 14 '15 at 15:09
  • It works Prakash. But my rails gem directory is empty. Do you know why? – Rodrigo Jan 14 '15 at 15:16
  • 1
    rails gem directory should have just the guides and README.md. Rest of the code is bundled in other gems. Not sure what the issue is if the folder is totally empty. – Prakash Murthy Jan 14 '15 at 15:20
  • 1
    Here is a better way to do the same: http://www.saturnflyer.com/blog/jim/2013/03/15/searching-through-your-bundled-gems/ – Prakash Murthy Jan 16 '15 at 17:09