Class: Frazzle::Registry
- Inherits:
-
Object
- Object
- Frazzle::Registry
- Defined in:
- lib/frazzle/core/registry.rb
Overview
****************************************************************************************************** Plugin registry maintaining the plugins of a gem. ****************************************************************************************************** A plugin must have a name according convention:
|plugin-gem-name| = |target-name|plugin-entity|plugin-type|
|--- plugin-name ---------|
Eg: “pizza-stone-oven” and “pizza-electric-oven” could be two “oven” plugins for a “pizza” gem
A plugin must also have a certain layout with a plugin-file in it’s installation folder:
[plugin-gem-home]/lib//plugin.rb
Where plugin.rb will provide a plugin-loader to create the plugin’s runtime object ******************************************************************************************************
Instance Attribute Summary collapse
-
#base_name ⇒ Object
Returns the value of attribute base_name.
Instance Method Summary collapse
- #get_all_plugins ⇒ Object
- #get_plugins(plugin_type) ⇒ Object
-
#initialize(base_name, base_separator = '-', plugin_separator = '-') ⇒ Registry
constructor
A new instance of Registry.
- #load_plugin(plugin_name, context = Object.new) ⇒ Object
Constructor Details
#initialize(base_name, base_separator = '-', plugin_separator = '-') ⇒ Registry
Returns a new instance of Registry.
21 22 23 24 25 |
# File 'lib/frazzle/core/registry.rb', line 21 def initialize(base_name, base_separator='-', plugin_separator='-') @base_name = base_name @base_separator = base_separator @plugin_separator = plugin_separator end |
Instance Attribute Details
#base_name ⇒ Object
Returns the value of attribute base_name.
26 27 28 |
# File 'lib/frazzle/core/registry.rb', line 26 def base_name @base_name end |
Instance Method Details
#get_all_plugins ⇒ Object
33 34 35 36 37 |
# File 'lib/frazzle/core/registry.rb', line 33 def get_all_plugins get_names(find_gems do |spec| spec.name =~ /#{@base_name}#{@base_separator}.*/ end) end |
#get_plugins(plugin_type) ⇒ Object
28 29 30 |
# File 'lib/frazzle/core/registry.rb', line 28 def get_plugins(plugin_type) get_names(get_plugin_gems(plugin_type)) end |
#load_plugin(plugin_name, context = Object.new) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/frazzle/core/registry.rb', line 39 def load_plugin(plugin_name, context=Object.new) gem = get_plugin_gem(plugin_name) if gem then load_plugin_gem(gem, context) else raise "Unable to find plugin: #{@base_name}#{@base_separator}#{plugin_name}" end end |