Skip to content

@emilsoman /bundle_outdated.rb
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
'bundle outdated' extracted into a method
require 'bundler'
def outdated?(options = {})
gems = Array(options[:gems])
sources = Array(options[:source])
Bundler.definition.validate_ruby!
current_specs = Bundler.load.specs
if gems.empty? && sources.empty?
# We're doing a full update
definition = Bundler.definition(true)
else
definition = Bundler.definition(:gems => gems, :sources => sources)
end
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
# Loop through the current specs
current_specs.sort_by { |s| s.name }.each do |current_spec|
next if !gems.empty? && !gems.include?(current_spec.name)
active_spec = definition.index[current_spec.name].sort_by { |b| b.version }
if !current_spec.version.prerelease? && !options[:pre] && active_spec.size > 1
active_spec = active_spec.delete_if { |b| b.respond_to?(:version) && b.version.prerelease? }
end
active_spec = active_spec.last
next if active_spec.nil?
gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
git_outdated = current_spec.git_version != active_spec.git_version
if gem_outdated || git_outdated
return true
end
end
return false
end
# When Gemfile contains 'highline' . '0.4.0'
puts outdated?({gems: ['highline']}) #=> true
# When Gemfile contains 'highline' . '1.6.16'
puts outdated?({gems: ['highline']}) #=> false
# To check all the gems
puts outdated?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.