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_JSON_REPO_NAME =
'CocoaPods/cocoapods-plugins'
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

Class Method Summary collapse

Class Method Details

.download_jsonHash

Force-download the JSON

Returns:

  • (Hash)

    The hash representing the JSON with all known plugins



21
22
23
24
25
26
27
28
29
30
# File 'lib/pod/command/plugins_helper.rb', line 21

def self.download_json
  UI.puts 'Downloading Plugins list...'
  response = REST.get(PLUGINS_RAW_URL)
  if response.ok?
    parse_json(response.body)
  else
    raise Informative, 'Could not download plugins list ' \
      "from cocoapods-plugins: #{response.inspect}"
  end
end

.known_pluginsArray

The list of all known plugins, according to the JSON hosted on github’s cocoapods-plugins

Returns:

  • (Array)

    all known plugins, as listed in the downloaded JSON



37
38
39
40
# File 'lib/pod/command/plugins_helper.rb', line 37

def self.known_plugins
  json = download_json
  json['plugins']
end

.matching_plugins(query, full_text_search) ⇒ Array

Filter plugins to return only matching ones

Parameters:

  • query (String)

    A query string that corresponds to a valid RegExp pattern.

  • full_text_search (Bool)

    false only searches in the plugin’s name. true searches in the plugin’s name, author and description.

Returns:

  • (Array)

    all plugins matching the query



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pod/command/plugins_helper.rb', line 53

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

Display information about a plugin

Parameters:

  • plugin (Hash)

    The hash describing the plugin

  • verbose (Bool) (defaults to: false)

    If true, will also print the author of the plugins. Defaults to false.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pod/command/plugins_helper.rb', line 74

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']
    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