Rails: Quick overview of licenses in used Gems

23rd June 2013 – 167 words

Using Gems is easy, but most people forget that Gems usually comes with a license. Here is a short command do find out used licenses:

Gem.loaded_specs.
  flat_map{|k,v| v.licenses.map{|license| [k, license]}}.
  reduce({}){|a,e| gem,license = e; a[license] ||= []; a[license] << gem; a}.
  map{|k,v|"#{k}: #{v.join(", ")}"}

Works great with bundler, which requires all Gems before. Most Gems are licensed under MIT, but some require more attention.

Caveat: Some Gems have no license written and/or the Rubygems licenses array is empty, dispite looking into the Gem, you can find one.