lib/pod/command/gem_helper.rb in cocoapods-plugins-0.3.0 vs lib/pod/command/gem_helper.rb in cocoapods-plugins-0.3.1
- old
+ new
@@ -38,28 +38,34 @@
# @return [Bool] true if the gem is installed, false otherwise.
#
def self.gem_installed?(gem_name, version_string = nil)
version = Gem::Version.new(version_string) if version_string
- gems = Gem::Specification.find_all_by_name(gem_name)
- return !gems.empty? unless version
-
- gems.each do |gem|
- return true if gem.version == version
+ if Gem::Specification.respond_to?(:find_all_by_name)
+ gems = Gem::Specification.find_all_by_name(gem_name)
+ return !gems.empty? unless version
+ gems.each { |gem| return true if gem.version == version }
+ false
+ else
+ dep = Gem::Dependency.new(gem_name, version_string)
+ !Gem.source_index.search(dep).empty?
end
-
- false
end
# Get the version of a gem that is installed locally. If more than
# one version is installed, this returns the first version found,
# which MAY not be the highest/newest version.
#
# @return [String] The version of the gem that is installed,
# or nil if it is not installed.
#
def self.installed_version(gem_name)
- gem = Gem::Specification.find_all_by_name(gem_name).first
+ if Gem::Specification.respond_to?(:find_all_by_name)
+ gem = Gem::Specification.find_all_by_name(gem_name).first
+ else
+ dep = Gem::Dependency.new(gem_name)
+ gem = Gem.source_index.search(dep).first
+ end
gem ? gem.version.to_s : nil
end
# Create a string containing all versions of a plugin,
# colored to indicate if a specific version is installed