Class: BoxGrinder::PluginManager
- Inherits:
-
Object
- Object
- BoxGrinder::PluginManager
- Includes:
- Singleton
- Defined in:
- lib/boxgrinder-build/managers/plugin-manager.rb
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#initialize ⇒ PluginManager
constructor
A new instance of PluginManager.
- #initialize_plugin(type, name) ⇒ Object
- #register_plugin(clazz, info) ⇒ Object
- #validate_plugin_info(info) ⇒ Object
Constructor Details
#initialize ⇒ PluginManager
Returns a new instance of PluginManager.
36 37 38 |
# File 'lib/boxgrinder-build/managers/plugin-manager.rb', line 36 def initialize @plugins = {:delivery => {}, :os => {}, :platform => {}} end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
80 81 82 |
# File 'lib/boxgrinder-build/managers/plugin-manager.rb', line 80 def plugins @plugins end |
Instance Method Details
#initialize_plugin(type, name) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/boxgrinder-build/managers/plugin-manager.rb', line 64 def initialize_plugin(type, name) plugins = @plugins[type] # this should never happen raise "There are no #{type} plugins." if plugins.nil? plugin_info = plugins[name] raise "There is no #{type} plugin registered for '#{name}' type/name." if plugin_info.nil? begin plugin = plugin_info[:class].new rescue raise "Error while initializing '#{plugin_info[:class].to_s}' plugin." end [plugin, plugin_info] end |
#register_plugin(clazz, info) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/boxgrinder-build/managers/plugin-manager.rb', line 40 def register_plugin(clazz, info) info = {:class => clazz, :require_root => false}.merge(info) validate_plugin_info(info) raise "We already have registered plugin for #{info[:name]}." unless @plugins[info[:name]].nil? unless info[:types].nil? info[:types].each do |type| @plugins[info[:type]][type] = info end else @plugins[info[:type]][info[:name]] = info end self end |
#validate_plugin_info(info) ⇒ Object
58 59 60 61 62 |
# File 'lib/boxgrinder-build/managers/plugin-manager.rb', line 58 def validate_plugin_info(info) raise "No name specified for your plugin" if info[:name].nil? raise "No class specified for your plugin" if info[:class].nil? raise "No type specified for your plugin" if info[:type].nil? end |