Class: SemVerComponents::Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/sem_ver_components/plugins.rb

Instance Method Summary collapse

Constructor Details

#initialize(plugins_type) ⇒ Plugins

Constructor

Parameters
  • plugins_type (Symbol): Plugins type we are parsing



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sem_ver_components/plugins.rb', line 9

def initialize(plugins_type)
  @plugins_type = plugins_type
  @plugins = Hash[Dir.glob("#{__dir__}/#{plugins_type}/*.rb").map do |plugin_file|
    plugin_name = File.basename(plugin_file, '.rb').to_sym
    require "#{__dir__}/#{plugins_type}/#{plugin_name}.rb"
    [
      plugin_name,
      SemVerComponents.
        const_get(plugins_type.to_s.split('_').collect(&:capitalize).join.to_sym).
        const_get(plugin_name.to_s.split('_').collect(&:capitalize).join.to_sym)
    ]
  end]
end

Instance Method Details

#[](plugin_name) ⇒ Object

Get a plugin class

Parameters
  • plugin_name (Symbol): The plugin name

Result
  • Class: The corresponding plugin class



37
38
39
# File 'lib/sem_ver_components/plugins.rb', line 37

def [](plugin_name)
  @plugins[plugin_name]
end

#listObject

List available plugin names

Result
  • Array<Symbol>: Available plugin names



27
28
29
# File 'lib/sem_ver_components/plugins.rb', line 27

def list
  @plugins.keys
end