Module: Pod::Command::PluginsHelper
- Defined in:
- lib/pod/command/plugins_helper.rb
Overview
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
Constant Summary collapse
- PLUGINS_URL =
'https://raw.githubusercontent.com/CocoaPods/' \ 'cocoapods.org/master/data/plugins.json'
Class Method Summary collapse
-
.download_json ⇒ Hash
Force-download the JSON.
-
.gem_installed?(gem_name) ⇒ Bool
Tells if a gem is installed.
-
.known_plugins ⇒ Array
The list of all known plugins, according to the JSON hosted on github’s cocoapods.org.
-
.matching_plugins(query, full_text_search) ⇒ Array
Filter plugins to return only matching ones.
-
.print_plugin(plugin, verbose = false) ⇒ Object
Display information about a plugin.
Class Method Details
.download_json ⇒ Hash
Force-download the JSON
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pod/command/plugins_helper.rb', line 15 def self.download_json UI.puts 'Downloading Plugins list...' response = REST.get(PLUGINS_URL) if response.ok? parse_json(response.body) else raise Informative, 'Could not download plugins list ' \ "from cocoapods.org: #{response.inspect}" end end |
.gem_installed?(gem_name) ⇒ Bool
Tells if a gem is installed
66 67 68 69 70 71 72 73 |
# File 'lib/pod/command/plugins_helper.rb', line 66 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 |
.known_plugins ⇒ Array
The list of all known plugins, according to the JSON hosted on github’s cocoapods.org
31 32 33 34 |
# File 'lib/pod/command/plugins_helper.rb', line 31 def self.known_plugins json = download_json json['plugins'] end |
.matching_plugins(query, full_text_search) ⇒ Array
Filter plugins to return only matching ones
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pod/command/plugins_helper.rb', line 47 def self.matching_plugins(query, full_text_search) query_regexp = /#{query}/i known_plugins.reject do |plugin| texts = [plugin['name']] if full_text_search texts << plugin['author'] if plugin['author'] texts << plugin['description'] if plugin['description'] end texts.grep(query_regexp).empty? end end |
.print_plugin(plugin, verbose = false) ⇒ Object
Display information about a plugin
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pod/command/plugins_helper.rb', line 84 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 end end |