Class: Plugins

Inherits:
Array show all
Defined in:
lib/common/plugins/plugins.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#_grep_

Constructor Details

#initialize(option_parser = nil) ⇒ Plugins

Returns a new instance of Plugins


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/common/plugins/plugins.rb', line 7

def initialize(option_parser = nil)
  if option_parser
    if option_parser.is_a?(CustomOptionParser)
      @option_parser = option_parser
    else
      raise "The parser must be an instance of CustomOptionParser, #{option_parser.class} supplied"
    end
  else
    @option_parser = CustomOptionParser.new
  end
end

Instance Attribute Details

#option_parserObject (readonly)

Returns the value of attribute option_parser


5
6
7
# File 'lib/common/plugins/plugins.rb', line 5

def option_parser
  @option_parser
end

Instance Method Details

#register(*plugins) ⇒ Object

param Array(Plugin) plugins


20
21
22
23
24
# File 'lib/common/plugins/plugins.rb', line 20

def register(*plugins)
  plugins.each do |plugin|
    register_plugin(plugin)
  end
end

#register_plugin(plugin) ⇒ Object

param Plugin plugin


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/common/plugins/plugins.rb', line 27

def register_plugin(plugin)
  if plugin.is_a?(Plugin)
    self << plugin

    # A plugin may not have options
    if plugin_options = plugin.registered_options
      @option_parser.add(plugin_options)
    end
  else
    raise "The argument must be an instance of Plugin, #{plugin.class} supplied"
  end
end