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.
- .plugin_prefix ⇒ Object
- .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
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/claide/command/plugins_helper.rb', line 22 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 #{plugin_prefix}-plugins: #{response.inspect}" end end |
.known_plugins ⇒ Array
The list of all known plugins, according to the JSON hosted on github’s cocoapods-plugins
38 39 40 41 |
# File 'lib/claide/command/plugins_helper.rb', line 38 def self.known_plugins json = download_json json['plugins'] end |
.matching_plugins(query, full_text_search) ⇒ Array
Filter plugins to return only matching ones
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/claide/command/plugins_helper.rb', line 54 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 |
.plugin_prefix ⇒ Object
14 15 16 |
# File 'lib/claide/command/plugins_helper.rb', line 14 def self.plugin_prefix CLAide::Plugins.config.plugin_prefix 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
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/claide/command/plugins_helper.rb', line 75 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 |