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 ******************************************************************************************************
Defined Under Namespace
Classes: Plugin
Instance Attribute Summary collapse
-
#base_name ⇒ Object
Returns the value of attribute base_name.
Instance Method Summary collapse
- #all_plugin ⇒ Object
- #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
- #plugins(plugin_type) ⇒ Object
Constructor Details
#initialize(base_name, base_separator = '-', plugin_separator = '-') ⇒ Registry
Returns a new instance of Registry.
32 33 34 35 36 |
# File 'lib/frazzle/core/registry.rb', line 32 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.
37 38 39 |
# File 'lib/frazzle/core/registry.rb', line 37 def base_name @base_name end |
Instance Method Details
#all_plugin ⇒ Object
48 49 50 |
# File 'lib/frazzle/core/registry.rb', line 48 def all_plugin get_all_plugins.map{|name|Plugin.new(self, name)} end |
#get_all_plugins ⇒ Object
52 53 54 55 56 |
# File 'lib/frazzle/core/registry.rb', line 52 def get_all_plugins get_names(find_gems do |spec| spec.name =~ /#{@base_name}#{@base_separator}.*/ end) end |
#get_plugins(plugin_type) ⇒ Object
43 44 45 |
# File 'lib/frazzle/core/registry.rb', line 43 def get_plugins(plugin_type) get_names(get_plugin_gems(plugin_type)) end |
#load_plugin(plugin_name, context = Object.new) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/frazzle/core/registry.rb', line 58 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 |
#plugins(plugin_type) ⇒ Object
39 40 41 |
# File 'lib/frazzle/core/registry.rb', line 39 def plugins(plugin_type) get_plugins(plugin_type).map{|name|Plugin.new(self, name)} end |