Module: Pod::Command::GemHelper
- Defined in:
- lib/pod/command/gem_helper.rb
Overview
This module is used by Command::PluginsHelper to download the Gem Specification data, check if a Gem is installed, and provide info on all versions of a Gem.
Class Method Summary collapse
-
.cache ⇒ GemIndexCache
Getter for GemIndexCache.
-
.download_and_cache_specs ⇒ Object
Instantiate a cache and download the spec index if it has not already been done.
-
.gem_installed?(gem_name, version_string = nil) ⇒ Bool
Tells if a gem is installed.
-
.installed_version(gem_name) ⇒ String
Get the version of a gem that is installed locally.
-
.versions_string(plugin_name, index_cache = @cache) ⇒ String
Create a string containing all versions of a plugin, colored to indicate if a specific version is installed locally.
Class Method Details
.cache ⇒ GemIndexCache
Getter for GemIndexCache
18 19 20 |
# File 'lib/pod/command/gem_helper.rb', line 18 def self.cache @cache ||= GemIndexCache.new end |
.download_and_cache_specs ⇒ Object
Instantiate a cache and download the spec index if it has not already been done.
25 26 27 |
# File 'lib/pod/command/gem_helper.rb', line 25 def self.download_and_cache_specs cache.download_and_cache_specs end |
.gem_installed?(gem_name, version_string = nil) ⇒ Bool
Tells if a gem is installed
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pod/command/gem_helper.rb', line 40 def self.gem_installed?(gem_name, version_string = nil) version = Gem::Version.new(version_string) if version_string 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 end |
.installed_version(gem_name) ⇒ String
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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/pod/command/gem_helper.rb', line 61 def self.installed_version(gem_name) 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 |
.versions_string(plugin_name, index_cache = @cache) ⇒ String
Create a string containing all versions of a plugin, colored to indicate if a specific version is installed locally.
86 87 88 89 90 91 |
# File 'lib/pod/command/gem_helper.rb', line 86 def self.versions_string(plugin_name, index_cache = @cache) name_tuples = index_cache.specs_with_name(plugin_name) sorted_versions = name_tuples.sort_by(&:version) version_strings = colorize_versions(sorted_versions) version_strings.join ', ' end |