Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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