wizardwerdna-pluggable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +23 -23
  2. data/VERSION +1 -1
  3. data/pluggable.gemspec +1 -1
  4. 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 process param
9
- plugins.each {|plugin| plugin.process param}
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:Plugin
14
- def process param; ...; end
13
+ class Plugin1 < Test::Plugin
14
+ def process; "foo"; end
15
15
  end
16
16
 
17
- class Plugin2 < Test:Plugin
18
- def process param; ...; end
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 process param
27
- plugins.each {|plugin| plugin.process param}
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:Plugin
34
+ class Plugin1 < Test::Plugin
35
35
  def foo; "foo"; end
36
- def process param; subprocess; end
37
- private
38
- def subprocess; ...; end
36
+ def process; foo; end
39
37
  end
40
38
 
41
- class Plugin2 < Test:Plugin
39
+ class Plugin2 < Test::Plugin
42
40
  def bar; "bar"; end
43
- def process param; subprocess; end
44
- private
45
- def subprocess; ...; end
41
+ def process; bar; end
46
42
  end
47
43
 
48
- Test.new.plugins.delegate_public_methods_to_plugins_except :process
49
- Test.new.foo # => "foo"
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.0
1
+ 0.1.1
data/pluggable.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pluggable}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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"]
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew C. Greenberg