Class: Siba::Plugins
- Inherits:
-
Object
- Object
- Siba::Plugins
- Defined in:
- lib/siba/plugins/plugins.rb
Constant Summary collapse
- PLUGINS_HASH =
Siba::OptionsLoader.load_hash_from_yml(File. "../plugins.yml", __FILE__)
- CATEGORIES =
PLUGINS_HASH.keys
Class Method Summary collapse
- .categories_str ⇒ Object
- .category_and_type_correct?(category, type) ⇒ Boolean
- .get_list ⇒ Object
- .plugin_description(category, type) ⇒ Object
- .plugin_type_and_description(category, type, name_column_length) ⇒ Object
- .valid_category?(category) ⇒ Boolean
Class Method Details
.categories_str ⇒ Object
16 17 18 |
# File 'lib/siba/plugins/plugins.rb', line 16 def categories_str Siba::Plugins::CATEGORIES.join(", ") end |
.category_and_type_correct?(category, type) ⇒ Boolean
20 21 22 |
# File 'lib/siba/plugins/plugins.rb', line 20 def category_and_type_correct?(category, type) PLUGINS_HASH.keys.include?(category) && PLUGINS_HASH[category].keys.include?(type) end |
.get_list ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/siba/plugins/plugins.rb', line 36 def get_list str = "" all_names = PLUGINS_HASH.values.map{|a| a.keys}.flatten max_name_length = all_names.max do |a,b| a.length <=> b.length end.length + 5 PLUGINS_HASH.each do |category, plugins| str << "#{category.capitalize}" str << "s" if plugins.size > 1 str << ":\n" plugins.each do |type, desc| installed = InstalledPlugins.installed?(category, type) ? "*" : " " str << " #{installed} #{plugin_type_and_description(category, type, max_name_length)}\n" end str << "\n" end str end |
.plugin_description(category, type) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/siba/plugins/plugins.rb', line 24 def plugin_description(category, type) unless category_and_type_correct? category, type raise Siba::Error, "Incorrect category '#{category}' or type '#{type}'." end PLUGINS_HASH[category][type] end |
.plugin_type_and_description(category, type, name_column_length) ⇒ Object
31 32 33 34 |
# File 'lib/siba/plugins/plugins.rb', line 31 def plugin_type_and_description(category, type, name_column_length) desc = plugin_description category, type sprintf("%-#{name_column_length}s %s", type, desc) end |
.valid_category?(category) ⇒ Boolean
12 13 14 |
# File 'lib/siba/plugins/plugins.rb', line 12 def valid_category?(category) Siba::Plugins::CATEGORIES.include? category end |