Created
April 14, 2014 23:41
-
-
Save thejonanshow/10690441 to your computer and use it in GitHub Desktop.
Searches the source of every gem in a Gemfile for a particular search term (using 'ag', The Silver Searcher)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| term = ARGV[0] | |
| puts "Searching all gems in Gemfile for #{term}..." | |
| gemfile = File.read('Gemfile') | |
| gems = gemfile.split("\n").map do |line| | |
| next unless line.match(/gem '/) | |
| line.split('gem').last.split(',').first.gsub("'","").split.first.strip | |
| end.compact | |
| gems_with_target_term = gems.map do |gem| | |
| path = `bundle show #{gem}`.strip | |
| puts "Searching gem #{gem}" | |
| if `ag #{term} #{path}`.length > 0 | |
| puts "FOUND: Gem #{gem} contains references to #{term}" | |
| gem | |
| end | |
| end.compact | |
| puts "Gems containing references to #{term}:" | |
| p gems_with_target_term |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment