Skip to content

Instantly share code, notes, and snippets.

@yob
Created February 27, 2009 06:17
Show Gist options
  • Save yob/71318 to your computer and use it in GitHub Desktop.
Save yob/71318 to your computer and use it in GitHub Desktop.
rails init script that checks for fresh gem versions
# *************************************
# A handy initiliser that logs when the loaded version of
# Rails or a gem dependency is out of date. The notice is
# non-fatal (often we want it to be out of date). I often
# forget which version of a gem my apps are using, and
# don't notice when there is a newer version available.
#
# Only really makes sense on Rails >= 2.1, where initialisers
# and gem dependencies first appeared. Drop this file in
# config/initializers/
#
# James Healy
# 2nd February 2009
# *************************************
outdated = []
# *************************************
# check the current version of Rails to see if it's the latest
# *************************************
max_rails_gem = Gem.cache.find_name('rails').map(&:version).map(&:version).max
if max_rails_gem && (Rails::VERSION::STRING < max_rails_gem)
outdated << {:name => "rails", :loaded => Rails::VERSION::STRING, :max => max_rails_gem}
end
# *************************************
# check the current version of all required gems to see if they're the latest
# *************************************
Rails.configuration.gems.each do |gem|
name = gem.name
if Rails::VERSION::STRING >= "2.2.2"
loaded_version = gem.specification.version.to_s
else
loaded_version = gem.version.to_s
end
max_gem_version = Gem.cache.find_name(name).map(&:version).map(&:version).max
if max_gem_version && (loaded_version < max_gem_version)
outdated << {:name => name, :loaded => loaded_version, :max => max_gem_version}
end
end
# *************************************
# print notices
# *************************************
unless outdated.empty?
logger = RAILS_DEFAULT_LOGGER
logger.info
logger.info "*******************************"
outdated.each do |w|
logger.info "NOTICE: #{w[:name]} version #{w[:loaded]} is not the most recent version of #{w[:name]} available on the system (#{w[:max]})"
end
logger.info "*******************************"
logger.info
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment