Skip to content

Instantly share code, notes, and snippets.

@sue445
Created June 4, 2017 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sue445/538c7339ccfb35decdb3463511acf21e to your computer and use it in GitHub Desktop.
Save sue445/538c7339ccfb35decdb3463511acf21e to your computer and use it in GitHub Desktop.
Gemfile中のgemの名前だけ取り出して標準出力に書き出す
# Gemfile中のgemの名前だけ取り出して標準出力に書き出す
#
# 使い方
# ruby parse_gemfile.rb /path/to/gemfile
#
# 複数のgemfileから被ってるのが多い順に表示する
# ruby parse_gemfile.rb *.gemfile | sort | uniq -c | sort -nr
# rails newした時にデフォルトで入ってるgemは除外する
EXCLUDE_GEMS = %w(
rails
sqlite3
puma
sass-rails
uglifier
therubyracer
coffee-rails
turbolinks
jbuilder
redis
bcrypt
capistrano-rails
byebug
capybara
selenium-webdriver
web-console
listen
spring
spring-watcher-listen
tzinfo-data
mysql2
)
ARGV.each do |source_file|
File.read(source_file).each_line do |line|
match_data = line.match(/^\s*gem\s*+["'](.+?)["']/)
next unless match_data
gem_name = match_data[1]
next if EXCLUDE_GEMS.include?(gem_name)
puts gem_name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment