Severin
Severin

Reputation: 8588

How to check gem version within Rails

I was thinking about integrating a little feature into my CMS that checks for new releases of the gems that are installed. Is there a way to check the current installed version of a Gem from within the application/rails console?

Upvotes: 1

Views: 1249

Answers (1)

Florian
Florian

Reputation: 3366

In theory, you can access the rubygems api via the Gem class:

Gem.latest_version_for "pry"

# => Gem::Version.new("0.9.12.6")

To get the list of current gems, you can try this.

gems = Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
gems["pry"].version
# => Gem::Version.new("0.9.12.4")

Blatantly stolen from here.

Upvotes: 2

Related Questions