wizardwerdna-pluggable 0.1.0 → 0.1.1
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 +23 -23
- data/VERSION +1 -1
- data/pluggable.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -2,51 +2,51 @@
|
|
2
2
|
|
3
3
|
Pluggable is a mixin for classes requiring plugins. A pluggable class, +Klass+, has a public function, +plugins+, returning an array-like object that holds all subclasses of <tt>Klass::Plugin</tt>.
|
4
4
|
|
5
|
+
require 'rubygems'
|
5
6
|
require 'pluggable'
|
6
7
|
class Test
|
7
8
|
include Pluggable
|
8
|
-
def
|
9
|
-
|
10
|
-
end
|
9
|
+
def initialize; install_plugins; end
|
10
|
+
def process; plugins.map {|plugin| plugin.process}; end
|
11
11
|
end
|
12
12
|
|
13
|
-
class Plugin1 < Test
|
14
|
-
def process
|
13
|
+
class Plugin1 < Test::Plugin
|
14
|
+
def process; "foo"; end
|
15
15
|
end
|
16
16
|
|
17
|
-
class Plugin2 < Test
|
18
|
-
def process
|
17
|
+
class Plugin2 < Test::Plugin
|
18
|
+
def process; "bar"; end
|
19
19
|
end
|
20
|
+
|
21
|
+
Test.new.process # => ["foo", "bar"]
|
20
22
|
|
21
23
|
It may be convenient to have public methods of plugins delegated to from the +plugins+ object, which may in turn be delgated to by the +Pluggable+ class in various ways. For example:
|
22
24
|
|
25
|
+
|
26
|
+
require 'rubygems'
|
23
27
|
require 'pluggable'
|
24
28
|
class Test
|
25
29
|
include Pluggable
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
def missing_method symbol, *args
|
30
|
-
plugins.send(symbol, *args)
|
31
|
-
end
|
30
|
+
def initialize; install_plugins; end
|
31
|
+
def process; plugins.map {|plugin| plugin.process}; end
|
32
32
|
end
|
33
33
|
|
34
|
-
class Plugin1 < Test
|
34
|
+
class Plugin1 < Test::Plugin
|
35
35
|
def foo; "foo"; end
|
36
|
-
def process
|
37
|
-
private
|
38
|
-
def subprocess; ...; end
|
36
|
+
def process; foo; end
|
39
37
|
end
|
40
38
|
|
41
|
-
class Plugin2 < Test
|
39
|
+
class Plugin2 < Test::Plugin
|
42
40
|
def bar; "bar"; end
|
43
|
-
def process
|
44
|
-
private
|
45
|
-
def subprocess; ...; end
|
41
|
+
def process; bar; end
|
46
42
|
end
|
47
43
|
|
48
|
-
Test.
|
49
|
-
|
44
|
+
Test.delegate_plugin_public_methods_except :process
|
45
|
+
|
46
|
+
|
47
|
+
Test.new.process # => ["foo", "bar"]
|
48
|
+
Test.new.plugins.foo = "foo"
|
49
|
+
Test.new.plugins.bar = "bar"
|
50
50
|
|
51
51
|
== Note on Patches/Pull Requests
|
52
52
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/pluggable.gemspec
CHANGED