Module: CLAide::Command::PluginsHelper
- Defined in:
- lib/claide/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
Class Method Summary collapse
-
.download_json ⇒ Hash
Force-download the JSON.
-
.known_plugins ⇒ Array
The list of all known plugins, according to the JSON hosted on github’s cocoapods-plugins.
-
.matching_plugins(query, full_text_search) ⇒ Array
Filter plugins to return only matching ones.
- .plugins_raw_url ⇒ Object
-
.print_plugin(plugin, verbose = false) ⇒ Object
Display information about a plugin.
Class Method Details
.download_json ⇒ Hash
Force-download the JSON
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/claide/command/plugins_helper.rb', line 18 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_plugins ⇒ Array
The list of all known plugins, according to the JSON hosted on github’s cocoapods-plugins
34 35 36 37 |
# File 'lib/claide/command/plugins_helper.rb', line 34 def self.known_plugins json = download_json json['plugins'] end |
.matching_plugins(query, full_text_search) ⇒ Array
Filter plugins to return only matching ones
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/claide/command/plugins_helper.rb', line 50 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 |
.plugins_raw_url ⇒ Object
10 11 12 |
# File 'lib/claide/command/plugins_helper.rb', line 10 def self.plugins_raw_url CLAide::Plugins.config.plugin_list_url end |
.print_plugin(plugin, verbose = false) ⇒ Object
Display information about a plugin
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/claide/command/plugins_helper.rb', line 71 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 |