wizardwerdna-pluggable 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/pluggable.rb +11 -8
- data/pluggable.gemspec +4 -4
- data/spec/pluggable_spec.rb +11 -5
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -56,6 +56,7 @@ Finally, it may be useful to establish an API for plugins in the form of a tradi
|
|
56
56
|
require 'rubygems'
|
57
57
|
require 'pluggable'
|
58
58
|
module PluginAPI
|
59
|
+
def initialize(one, two, three); end
|
59
60
|
def first; "first"; end
|
60
61
|
def second; private_second; end
|
61
62
|
module ClassMethods
|
@@ -70,7 +71,7 @@ Finally, it may be useful to establish an API for plugins in the form of a tradi
|
|
70
71
|
|
71
72
|
class Test
|
72
73
|
include Pluggable
|
73
|
-
def initialize; install_plugins; end
|
74
|
+
def initialize; install_plugins(:one, :two, :three); end # arity must match initialize methods for all plugins
|
74
75
|
def process; plugins.map {|plugin| plugin.process}; end
|
75
76
|
private
|
76
77
|
def method_missing symbol, *args
|
data/Rakefile
CHANGED
@@ -5,8 +5,8 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "pluggable"
|
8
|
-
gem.summary = %Q{
|
9
|
-
gem.description = %Q{
|
8
|
+
gem.summary = %Q{Pluggable is a mixin for classes requiring plugins.}
|
9
|
+
gem.description = %Q{Pluggable classes are automatically registered from classes that subclass from <classname>::Plugin, and can use tools for managing, installing and delegating methods therefrom.}
|
10
10
|
gem.email = "wizardwerdna@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/wizardwerdna/pluggable"
|
12
12
|
gem.authors = ["Andrew C. Greenberg"]
|
@@ -45,4 +45,4 @@ Rake::RDocTask.new do |rdoc|
|
|
45
45
|
rdoc.title = "pluggable #{version}"
|
46
46
|
rdoc.rdoc_files.include('README*')
|
47
47
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
-
end
|
48
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/pluggable.rb
CHANGED
@@ -19,24 +19,27 @@ module Pluggable
|
|
19
19
|
|
20
20
|
class PluginFactory < Array
|
21
21
|
include Singleton
|
22
|
-
def build_plugins
|
22
|
+
def build_plugins(*args)
|
23
23
|
array_of_instance_and_name_pairs = map do |each|
|
24
|
-
instance = each.new
|
24
|
+
instance = each.new(*args)
|
25
25
|
{:name => variable_name_for_plugin_instance(instance), :instance => instance}
|
26
26
|
end
|
27
27
|
Plugins.from_array_of_instance_and_name_pairs(array_of_instance_and_name_pairs)
|
28
28
|
end
|
29
29
|
def delegate_plugin_public_methods_to_plugins_class_except *excluded_methods
|
30
30
|
excluded_methods = excluded_methods.map{|each| each.to_s}
|
31
|
-
|
32
|
-
delegated_methods =
|
33
|
-
variable_name =
|
31
|
+
each do |klass|
|
32
|
+
delegated_methods = klass.public_instance_methods-Plugin.public_instance_methods-excluded_methods
|
33
|
+
variable_name = variable_name_for_plugin_class klass
|
34
34
|
Plugins.def_delegators variable_name, *delegated_methods
|
35
35
|
end
|
36
36
|
end
|
37
37
|
private
|
38
38
|
def variable_name_for_plugin_instance instance
|
39
|
-
|
39
|
+
variable_name_for_plugin_class instance.class
|
40
|
+
end
|
41
|
+
def variable_name_for_plugin_class klass
|
42
|
+
"@ivar_for_#{klass.to_s}".gsub(/::/) {'_colons_'}.to_sym
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
@@ -46,8 +49,8 @@ module Pluggable
|
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
49
|
-
def install_plugins
|
50
|
-
instance_variable_set :@pluggable_module_plugins, PluginFactory.instance.build_plugins
|
52
|
+
def install_plugins(*args)
|
53
|
+
instance_variable_set :@pluggable_module_plugins, PluginFactory.instance.build_plugins(*args)
|
51
54
|
end
|
52
55
|
|
53
56
|
def plugins
|
data/pluggable.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pluggable}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew C. Greenberg"]
|
12
|
-
s.date = %q{2009-08-
|
13
|
-
s.description = %q{
|
12
|
+
s.date = %q{2009-08-21}
|
13
|
+
s.description = %q{Pluggable classes are automatically registered from classes that subclass from <classname>::Plugin, and can use tools for managing, installing and delegating methods therefrom.}
|
14
14
|
s.email = %q{wizardwerdna@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
34
|
s.rubygems_version = %q{1.3.5}
|
35
|
-
s.summary = %q{
|
35
|
+
s.summary = %q{Pluggable is a mixin for classes requiring plugins.}
|
36
36
|
s.test_files = [
|
37
37
|
"spec/pluggable_spec.rb",
|
38
38
|
"spec/spec_helper.rb"
|
data/spec/pluggable_spec.rb
CHANGED
@@ -2,6 +2,7 @@ require 'forwardable'
|
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
3
|
|
4
4
|
module PluginAPI
|
5
|
+
def initialize(one, two, three); end
|
5
6
|
def first; "first"; end
|
6
7
|
def second; private_second; end
|
7
8
|
module ClassMethods
|
@@ -48,7 +49,7 @@ class Plugin3 < Test::Plugin
|
|
48
49
|
end
|
49
50
|
|
50
51
|
if Test.respond_to? :delegate_plugin_public_methods_except
|
51
|
-
Test.delegate_plugin_public_methods_except :exception_public
|
52
|
+
Test.delegate_plugin_public_methods_except :exception_public, :one, :two, :three, :initialize
|
52
53
|
end
|
53
54
|
|
54
55
|
|
@@ -80,12 +81,17 @@ describe Pluggable, "when included in a class" do
|
|
80
81
|
it "should add a method #install_plugins" do
|
81
82
|
Test.new.should respond_to(:install_plugins)
|
82
83
|
end
|
84
|
+
|
85
|
+
it "should properly instantiate plugins upon a call to #install_plugins" do
|
86
|
+
[Plugin1, Plugin2, Plugin3].each{|each| each.should_receive(:new).with(:one, :two, :three)}
|
87
|
+
Test.new.install_plugins(:one, :two, :three)
|
88
|
+
end
|
83
89
|
end
|
84
90
|
|
85
91
|
describe Pluggable, "after installing plugins" do
|
86
92
|
before(:each) do
|
87
93
|
@test_instance = Test.new
|
88
|
-
@test_instance.install_plugins
|
94
|
+
@test_instance.install_plugins(:one, :two, :three)
|
89
95
|
end
|
90
96
|
|
91
97
|
it "should have #plugins answer an object containing a collection of new plugin instances after #install_plugins" do
|
@@ -108,7 +114,7 @@ end
|
|
108
114
|
describe Pluggable, "after Test has delegated all but excepted plugin public methods" do
|
109
115
|
before(:each) do
|
110
116
|
@test_instance = Test.new
|
111
|
-
@test_instance.install_plugins
|
117
|
+
@test_instance.install_plugins(:one, :two, :three)
|
112
118
|
end
|
113
119
|
|
114
120
|
it "should delegate public methods of plugins" do
|
@@ -152,7 +158,7 @@ describe Test::PluginFactory, "instances" do
|
|
152
158
|
end
|
153
159
|
|
154
160
|
it "should build a Plugins object with fresh instances of each plugin" do
|
155
|
-
@installed_plugins = @instance.build_plugins
|
161
|
+
@installed_plugins = @instance.build_plugins(:one, :two, :three)
|
156
162
|
@installed_plugins.should be_a_kind_of(Test::Plugins)
|
157
163
|
@installed_plugins.should have(3).items
|
158
164
|
@installed_plugins.map{|each| each.class}.should include(Plugin1, Plugin2, Plugin3)
|
@@ -162,7 +168,7 @@ end
|
|
162
168
|
describe Test, "when using message_missing to simulate delegation from the parent" do
|
163
169
|
before(:each) do
|
164
170
|
@test_instance = Test.new
|
165
|
-
@test_instance.install_plugins
|
171
|
+
@test_instance.install_plugins(:one, :two, :three)
|
166
172
|
end
|
167
173
|
|
168
174
|
it "should properly process using all the plugins" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wizardwerdna-pluggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew C. Greenberg
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: Pluggable classes are automatically registered from classes that subclass from <classname>::Plugin, and can use tools for managing, installing and delegating methods therefrom.
|
26
26
|
email: wizardwerdna@gmail.com
|
27
27
|
executables: []
|
28
28
|
|
@@ -68,7 +68,7 @@ rubyforge_project:
|
|
68
68
|
rubygems_version: 1.3.5
|
69
69
|
signing_key:
|
70
70
|
specification_version: 3
|
71
|
-
summary:
|
71
|
+
summary: Pluggable is a mixin for classes requiring plugins.
|
72
72
|
test_files:
|
73
73
|
- spec/pluggable_spec.rb
|
74
74
|
- spec/spec_helper.rb
|