frazzle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1 @@
1
+ gem plugin-manager using extention-points
@@ -0,0 +1,85 @@
1
+ module Frazzle
2
+
3
+ # ******************************************************************************************************
4
+ # Plugin registry maintaining the plugins of a gem.
5
+ # ******************************************************************************************************
6
+ # A plugin must have a name according convention:
7
+ #
8
+ # |plugin-gem-name| = |target-name|plugin-entity|plugin-type|
9
+ # |--- plugin-name ---------|
10
+ #
11
+ # Eg: "pizza-stone-oven" and "pizza-electric-oven" could be two "oven" plugins for a "pizza" gem
12
+ #
13
+ # A plugin must also have a certain layout with a plugin-file in it's installation folder:
14
+ #
15
+ # [plugin-gem-home]/lib/[plugin-gem-name]/plugin.rb
16
+ #
17
+ # Where plugin.rb will provide a plugin-loader to create the plugin's runtime object
18
+ # ******************************************************************************************************
19
+ class Registry
20
+
21
+ def initialize(base_name, base_separator='-', plugin_separator='-')
22
+ @base_name = base_name
23
+ @base_separator = base_separator
24
+ @plugin_separator = plugin_separator
25
+ end
26
+ attr_accessor :base_name
27
+
28
+ def get_plugins(plugin_type)
29
+ get_names(get_plugin_gems(plugin_type))
30
+ end
31
+
32
+
33
+ def get_all_plugins
34
+ get_names(find_gems do |spec|
35
+ spec.name =~ /#{@base_name}#{@base_separator}.*/
36
+ end)
37
+ end
38
+
39
+ def load_plugin(plugin_name, context=Object.new)
40
+ gem = get_plugin_gem(plugin_name)
41
+ if gem then
42
+ load_plugin_gem(gem, context)
43
+ else
44
+ raise "Unable to find plugin: #{@base_name}#{@base_separator}#{plugin_name}"
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def get_names(specs)
51
+ specs.map do |spec|
52
+ spec.name =~ /#{@base_name}#{@base_separator}(.*)/
53
+ $1
54
+ end
55
+ end
56
+
57
+ def find_gems(&block)
58
+ Gem::Specification.latest_specs.select do |spec|
59
+ block.call(spec)
60
+ end
61
+ end
62
+
63
+ def get_plugin_gems(plugin_type)
64
+ find_gems do |gem|
65
+ gem.name =~ /#{@base_name}#{@base_separator}.*#{@plugin_separator}#{plugin_type}/
66
+ end
67
+ end
68
+
69
+ def get_plugin_gem(plugin_name)
70
+ find_gems do |gem|
71
+ gem.name =~ /#{@base_name}#{@base_separator}#{plugin_name}/
72
+ end.first
73
+ end
74
+
75
+ def load_plugin_gem(gem, context)
76
+ file = File.join(gem.full_gem_path, 'lib', gem.name, 'plugin.rb')
77
+ if File.exists?(file) then
78
+ content = File.read(file)
79
+ return context.instance_eval(content)
80
+ else
81
+ raise "Unable to load plugin-file: #{file}"
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1 @@
1
+ require_relative "core/registry"
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frazzle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin russ
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: plugin registry based on gems
15
+ email: kevin.russ@esrlabs.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README
20
+ files:
21
+ - lib/frazzle/frazzle.rb
22
+ - lib/frazzle/core/registry.rb
23
+ - README
24
+ homepage:
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.24
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: gem plugin-manager using extention-points
48
+ test_files: []