Skip to content

Instantly share code, notes, and snippets.

@borama
Last active October 25, 2023 21:03
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save borama/4d52c4f97c918a363a1fc7019593bf86 to your computer and use it in GitHub Desktop.
Save borama/4d52c4f97c918a363a1fc7019593bf86 to your computer and use it in GitHub Desktop.
A script that collects and prints info about the age of all ruby gems in your project, see https://dev.to/borama/how-old-are-dependencies-in-your-ruby-project-3jia
#!/bin/env ruby
#
# Collects info about the age of all gems in the project
#
require "json"
require "date"
bundle = `bundle list`
yearly_stats = {}
bundle.split(/\n/).each do |line|
next unless line =~ /\s+\*\s+[^ ]+\s+\(.*\)/
gem_name, gem_version = /\s+\*\s+([^ ]+)\s+\((.*)\)/.match(line).to_a[1..-1]
begin
gem_json = `curl -s https://rubygems.org/api/v2/rubygems/#{gem_name}/versions/#{gem_version}.json`
built_at = JSON.parse(gem_json)["built_at"]
release_date = Date.parse(built_at).to_date
puts "#{gem_name},#{gem_version},#{release_date.strftime("%Y-%m-%d")}"
release_year = release_date.strftime("%Y")
yearly_stats[release_year] ||= { count: 0, gems: [] }
yearly_stats[release_year][:count] += 1
yearly_stats[release_year][:gems] << gem_name
rescue => e
puts "#{gem_name},#{gem_version},???"
end
end
puts
puts "Yearly summary:"
yearly_stats.sort.each do |year, data|
puts "#{year},#{data[:count]},#{data[:gems].join(' ')}"
end
@borama
Copy link
Author

borama commented Aug 7, 2019

This script will find out the age (date of release) of all gems in your project and print this out together with yearly summary stats. The format of both output parts usually obeys the CSV format so that you can paste it in your spreadsheet and make a chart of it.

Typical output:

$ ruby ruby_gems_age.rb
actioncable,6.0.0.rc1,2019-04-24
actionmailbox,6.0.0.rc1,2019-04-24
actionmailer,6.0.0.rc1,2019-04-24
actionpack,6.0.0.rc1,2019-04-24
...
webpacker,3.5.5,2018-07-09
websocket-driver,0.7.1,2019-06-10
websocket-extensions,0.1.4,2019-06-10
will_paginate,3.1.7,2019-03-18
xpath,3.2.0,2018-10-15
zeitwerk,2.1.9,2019-07-16

Yearly summary:
2014,8,acts-as-dag ...
2015,6,coffee-script ...
...
2019,115,actioncable ...

See the article for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment