lib/pod/command/plugins_helper.rb in cocoapods-plugins-0.2.0 vs lib/pod/command/plugins_helper.rb in cocoapods-plugins-0.3.0

- old
+ new

@@ -1,22 +1,28 @@ +require 'pod/command/gem_helper' + module Pod class Command # This module is used by Command::Plugins::List # and Command::Plugins::Search to download and parse # the JSON describing the plugins list and manipulate it # module PluginsHelper - PLUGINS_URL = 'https://raw.githubusercontent.com/CocoaPods/' \ - 'cocoapods.org/master/data/plugins.json' + PLUGINS_JSON_REPO_NAME = 'CocoaPods/cocoapods.org' + PLUGINS_JSON_REPO = 'https://github.com/' + PLUGINS_JSON_REPO_NAME + PLUGINS_JSON_REL_URL = '/master/plugins.json' + PLUGINS_RAW_URL = 'https://raw.githubusercontent.com/' \ + + PLUGINS_JSON_REPO_NAME + PLUGINS_JSON_REL_URL + # Force-download the JSON # # @return [Hash] The hash representing the JSON with all known plugins # def self.download_json UI.puts 'Downloading Plugins list...' - response = REST.get(PLUGINS_URL) + response = REST.get(PLUGINS_RAW_URL) if response.ok? parse_json(response.body) else raise Informative, 'Could not download plugins list ' \ "from cocoapods.org: #{response.inspect}" @@ -54,26 +60,10 @@ end texts.grep(query_regexp).empty? end end - # Tells if a gem is installed - # - # @param [String] gem_name - # The name of the plugin gem to test - # - # @return [Bool] true if the gem is installed, false otherwise. - # - def self.gem_installed?(gem_name) - if Gem::Specification.methods.include?(:find_all_by_name) - Gem::Specification.find_all_by_name(gem_name).any? - else - # Fallback to Gem.available? for old versions of rubygems - Gem.available?(gem_name) - end - end - # Display information about a plugin # # @param [Hash] plugin # The hash describing the plugin # @@ -84,20 +74,38 @@ def self.print_plugin(plugin, verbose = false) plugin_colored_name = plugin_title(plugin) UI.title(plugin_colored_name, '', 1) do UI.puts_indented plugin['description'] - UI.labeled('Gem', plugin['gem']) - UI.labeled('URL', plugin['url']) - UI.labeled('Author', plugin['author']) if verbose + ljust = verbose ? 16 : 11 + UI.labeled('Gem', plugin['gem'], ljust) + UI.labeled('URL', plugin['url'], ljust) + print_verbose_plugin(plugin, ljust) if verbose end end #----------------# private + # Smaller helper to print out the verbose details + # for a plugin. + # + # @param [Hash] plugin + # The hash describing the plugin + # + # @param [Integer] ljust + # The left justification that is passed into UI.labeled + # + def self.print_verbose_plugin(plugin, ljust) + UI.labeled('Author', plugin['author'], ljust) + unless GemHelper.cache.specs.empty? + versions = GemHelper.versions_string(plugin['gem']) + UI.labeled('Versions', versions, ljust) + end + end + # Parse the given JSON data, handling parsing errors if any # # @param [String] json_str # The string representation of the JSON to parse # @@ -115,10 +123,11 @@ # # @return [String] The formatted and colored title # def self.plugin_title(plugin) plugin_name = "-> #{plugin['name']}" - if gem_installed?(plugin['gem']) + if GemHelper.gem_installed?(plugin['gem']) + plugin_name += " (#{GemHelper.installed_version(plugin['gem'])})" plugin_name.green else plugin_name.yellow end end