pluginfactory 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ BEGIN {
10
10
  $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
11
  }
12
12
 
13
- require 'spec'
13
+ require 'rspec'
14
14
  require 'logger'
15
15
  require 'pluginfactory'
16
16
 
@@ -32,7 +32,6 @@ end
32
32
 
33
33
 
34
34
  describe PluginFactory do
35
- include PluginFactory::SpecHelpers
36
35
 
37
36
  before( :each ) do
38
37
  setup_logging( :fatal )
@@ -55,11 +54,11 @@ describe PluginFactory do
55
54
 
56
55
  it "doesn't error when its log method is called if no logging callback is set" do
57
56
  PluginFactory.logger_callback = nil
58
- lambda { PluginFactory.log.debug("msg") }.should_not raise_error()
57
+ expect { PluginFactory.log.debug("msg") }.to_not raise_error()
59
58
  end
60
59
 
61
60
 
62
- describe "-extended class" do
61
+ context "-extended class" do
63
62
 
64
63
  it "knows about all of its derivatives" do
65
64
  Plugin.derivatives.keys.should include( 'sub' )
@@ -85,19 +84,23 @@ describe PluginFactory do
85
84
  end
86
85
  end
87
86
 
87
+ exception = nil
88
88
  begin
89
89
  Plugin.create('pugilist')
90
- rescue ::Exception => err
91
- err.backtrace.first.should =~ /#{__FILE__}/
90
+ rescue ::RuntimeError => err
91
+ exception = err
92
92
  else
93
- fail "Expected an exception to be raised"
93
+ fail "Expected an exception to be raised."
94
94
  end
95
+
96
+ exception.backtrace.first.should =~ /#{__FILE__}/
95
97
  end
96
98
 
97
99
  it "will refuse to create an object other than one of its derivatives" do
98
100
  class Doppelgaenger; end
99
- lambda { Plugin.create(Doppelgaenger) }.
100
- should raise_error( ArgumentError, /is not a descendent of/ )
101
+ expect {
102
+ Plugin.create(Doppelgaenger)
103
+ }.to raise_error( ArgumentError, /is not a descendent of/ )
101
104
  end
102
105
 
103
106
 
@@ -123,8 +126,9 @@ describe PluginFactory do
123
126
  at_least(6).times.
124
127
  and_return {|path| raise LoadError, "path" }
125
128
 
126
- lambda { Plugin.create('scintillating') }.
127
- should raise_error( FactoryError, /couldn't find a \S+ named \S+.*tried \[/i )
129
+ expect {
130
+ Plugin.create('scintillating')
131
+ }.to raise_error( FactoryError, /couldn't find a \S+ named \S+.*tried \[/i )
128
132
  end
129
133
 
130
134
 
@@ -132,8 +136,9 @@ describe PluginFactory do
132
136
  # at least 6 -> 3 variants * 2 paths
133
137
  Plugin.should_receive( :require ).and_return( true )
134
138
 
135
- lambda { Plugin.create('corruscating') }.
136
- should raise_error( FactoryError, /Require of '\S+' succeeded, but didn't load a Plugin/i )
139
+ expect {
140
+ Plugin.create('corruscating')
141
+ }.to raise_error( FactoryError, /Require of '\S+' succeeded, but didn't load a Plugin/i )
137
142
  end
138
143
 
139
144
 
@@ -145,13 +150,14 @@ describe PluginFactory do
145
150
  raise ScriptError, "error while parsing #{path}"
146
151
  }
147
152
 
148
- lambda { Plugin.create('portable') }.
149
- should raise_error( ScriptError, /error while parsing/ )
153
+ expect {
154
+ Plugin.create('portable')
155
+ }.to raise_error( ScriptError, /error while parsing/ )
150
156
  end
151
157
  end
152
158
 
153
159
 
154
- describe "derivative of an extended class" do
160
+ context "derivative of an extended class" do
155
161
 
156
162
  it "knows what type of factory loads it" do
157
163
  TestingPlugin.factory_type.should == 'Plugin'
@@ -159,13 +165,14 @@ describe PluginFactory do
159
165
 
160
166
  it "raises a FactoryError if it can't figure out what type of factory loads it" do
161
167
  TestingPlugin.stub!( :ancestors ).and_return( [] )
162
- lambda { TestingPlugin.factory_type }.
163
- should raise_error( FactoryError, /couldn't find factory base/i )
168
+ expect {
169
+ TestingPlugin.factory_type
170
+ }.to raise_error( FactoryError, /couldn't find factory base/i )
164
171
  end
165
172
  end
166
173
 
167
174
 
168
- describe "derivative of an extended class that isn't named <Something>Plugin" do
175
+ context "derivative of an extended class that isn't named <Something>Plugin" do
169
176
 
170
177
  it "is still creatable via its full name" do
171
178
  Plugin.create( 'blacksheep' ).should be_an_instance_of( BlackSheep )
@@ -174,7 +181,7 @@ describe PluginFactory do
174
181
  end
175
182
 
176
183
 
177
- describe "derivative of an extended class in another namespace" do
184
+ context "derivative of an extended class in another namespace" do
178
185
 
179
186
  it "is still creatable via its derivative name" do
180
187
  Plugin.create( 'loadable' ).should be_an_instance_of( Test::LoadablePlugin )
metadata CHANGED
@@ -1,120 +1,180 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pluginfactory
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 7
10
- version: 1.0.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - Martin Chase, Michael Granger
7
+ authors:
8
+ - Martin Chase
9
+ - Michael Granger
14
10
  autorequire:
15
11
  bindir: bin
16
- cert_chain:
17
- - |
18
- -----BEGIN CERTIFICATE-----
19
- MIIDLDCCAhSgAwIBAgIBADANBgkqhkiG9w0BAQUFADA8MQwwCgYDVQQDDANnZWQx
20
- FzAVBgoJkiaJk/IsZAEZFgdfYWVyaWVfMRMwEQYKCZImiZPyLGQBGRYDb3JnMB4X
21
- DTEwMDkxNjE0NDg1MVoXDTExMDkxNjE0NDg1MVowPDEMMAoGA1UEAwwDZ2VkMRcw
22
- FQYKCZImiZPyLGQBGRYHX2FlcmllXzETMBEGCgmSJomT8ixkARkWA29yZzCCASIw
23
- DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALy//BFxC1f/cPSnwtJBWoFiFrir
24
- h7RicI+joq/ocVXQqI4TDWPyF/8tqkvt+rD99X9qs2YeR8CU/YiIpLWrQOYST70J
25
- vDn7Uvhb2muFVqq6+vobeTkILBEO6pionWDG8jSbo3qKm1RjKJDwg9p4wNKhPuu8
26
- KGue/BFb67KflqyApPmPeb3Vdd9clspzqeFqp7cUBMEpFS6LWxy4Gk+qvFFJBJLB
27
- BUHE/LZVJMVzfpC5Uq+QmY7B+FH/QqNndn3tOHgsPadLTNimuB1sCuL1a4z3Pepd
28
- TeLBEFmEao5Dk3K/Q8o8vlbIB/jBDTUx6Djbgxw77909x6gI9doU4LD5XMcCAwEA
29
- AaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFJeoGkOr9l4B
30
- +saMkW/ZXT4UeSvVMA0GCSqGSIb3DQEBBQUAA4IBAQBG2KObvYI2eHyyBUJSJ3jN
31
- vEnU3d60znAXbrSd2qb3r1lY1EPDD3bcy0MggCfGdg3Xu54z21oqyIdk8uGtWBPL
32
- HIa9EgfFGSUEgvcIvaYqiN4jTUtidfEFw+Ltjs8AP9gWgSIYS6Gr38V0WGFFNzIH
33
- aOD2wmu9oo/RffW4hS/8GuvfMzcw7CQ355wFR4KB/nyze+EsZ1Y5DerCAagMVuDQ
34
- U0BLmWDFzPGGWlPeQCrYHCr+AcJz+NRnaHCKLZdSKj/RHuTOt+gblRex8FAh8NeA
35
- cmlhXe46pZNJgWKbxZah85jIjx95hR8vOI+NAM5iH9kOqK13DrxacTKPhqj5PjwF
36
- -----END CERTIFICATE-----
37
-
38
- date: 2010-09-27 00:00:00 -07:00
39
- default_executable:
40
- dependencies: []
12
+ cert_chain:
13
+ - !binary |-
14
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMRENDQWhTZ0F3SUJB
15
+ Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREE4TVF3d0NnWURWUVFEREFOblpX
16
+ UXgKRnpBVkJnb0praWFKay9Jc1pBRVpGZ2RmWVdWeWFXVmZNUk13RVFZS0Na
17
+ SW1pWlB5TEdRQkdSWURiM0puTUI0WApEVEV3TURreE5qRTBORGcxTVZvWERU
18
+ RXhNRGt4TmpFME5EZzFNVm93UERFTU1Bb0dBMVVFQXd3RFoyVmtNUmN3CkZR
19
+ WUtDWkltaVpQeUxHUUJHUllIWDJGbGNtbGxYekVUTUJFR0NnbVNKb21UOGl4
20
+ a0FSa1dBMjl5WnpDQ0FTSXcKRFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURD
21
+ Q0FRb0NnZ0VCQUx5Ly9CRnhDMWYvY1BTbnd0SkJXb0ZpRnJpcgpoN1JpY0kr
22
+ am9xL29jVlhRcUk0VERXUHlGLzh0cWt2dCtyRDk5WDlxczJZZVI4Q1UvWWlJ
23
+ cExXclFPWVNUNzBKCnZEbjdVdmhiMm11RlZxcTYrdm9iZVRrSUxCRU82cGlv
24
+ bldERzhqU2JvM3FLbTFSaktKRHdnOXA0d05LaFB1dTgKS0d1ZS9CRmI2N0tm
25
+ bHF5QXBQbVBlYjNWZGQ5Y2xzcHpxZUZxcDdjVUJNRXBGUzZMV3h5NEdrK3F2
26
+ RkZKQkpMQgpCVUhFL0xaVkpNVnpmcEM1VXErUW1ZN0IrRkgvUXFObmRuM3RP
27
+ SGdzUGFkTFROaW11QjFzQ3VMMWE0ejNQZXBkClRlTEJFRm1FYW81RGszSy9R
28
+ OG84dmxiSUIvakJEVFV4NkRqYmd4dzc3OTA5eDZnSTlkb1U0TEQ1WE1jQ0F3
29
+ RUEKQWFNNU1EY3dDUVlEVlIwVEJBSXdBREFMQmdOVkhROEVCQU1DQkxBd0hR
30
+ WURWUjBPQkJZRUZKZW9Ha09yOWw0Qgorc2FNa1cvWlhUNFVlU3ZWTUEwR0NT
31
+ cUdTSWIzRFFFQkJRVUFBNElCQVFCRzJLT2J2WUkyZUh5eUJVSlNKM2pOCnZF
32
+ blUzZDYwem5BWGJyU2QycWIzcjFsWTFFUEREM2JjeTBNZ2dDZkdkZzNYdTU0
33
+ ejIxb3F5SWRrOHVHdFdCUEwKSElhOUVnZkZHU1VFZ3ZjSXZhWXFpTjRqVFV0
34
+ aWRmRUZ3K0x0anM4QVA5Z1dnU0lZUzZHcjM4VjBXR0ZGTnpJSAphT0Qyd211
35
+ OW9vL1JmZlc0aFMvOEd1dmZNemN3N0NRMzU1d0ZSNEtCL255emUrRXNaMVk1
36
+ RGVyQ0FhZ01WdURRClUwQkxtV0RGelBHR1dsUGVRQ3JZSENyK0FjSnorTlJu
37
+ YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
38
+ Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
39
+ cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
40
+ date: 2012-02-20 00:00:00.000000000 Z
41
+ dependencies:
42
+ - !ruby/object:Gem::Dependency
43
+ name: hoe-mercurial
44
+ requirement: &70125869528840 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 1.3.1
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: *70125869528840
53
+ - !ruby/object:Gem::Dependency
54
+ name: hoe-highline
55
+ requirement: &70125869528340 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.1
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: *70125869528340
64
+ - !ruby/object:Gem::Dependency
65
+ name: hoe-mercurial
66
+ requirement: &70125869527820 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: 1.3.1
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: *70125869527820
75
+ - !ruby/object:Gem::Dependency
76
+ name: hoe-deveiate
77
+ requirement: &70125869527320 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: *70125869527320
86
+ - !ruby/object:Gem::Dependency
87
+ name: rdoc
88
+ requirement: &70125869526780 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '3.10'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: *70125869526780
97
+ - !ruby/object:Gem::Dependency
98
+ name: hoe
99
+ requirement: &70125869526280 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '2.13'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: *70125869526280
108
+ description: ! 'PluginFactory is a mixin module that turns an including class into
109
+ a factory for
41
110
 
42
- description: |-
43
- PluginFactory is a mixin module that turns an including class into a factory for
44
111
  its derivatives, capable of searching for and loading them by name. This is
112
+
45
113
  useful when you have an abstract base class which defines an interface and basic
114
+
46
115
  functionality for a part of a larger system, and a collection of subclasses
116
+
47
117
  which implement the interface for different underlying functionality.
48
- email:
118
+
119
+
120
+ An example of where this might be useful is in a program which talks to a
121
+
122
+ database. To avoid coupling it to a specific database, you use a Driver class
123
+
124
+ which encapsulates your program''s interaction with the database behind a useful
125
+
126
+ interface. Now you can create a concrete implementation of the Driver class for
127
+
128
+ each kind of database you wish to talk to. If you make the base Driver class a
129
+
130
+ PluginFactory, too, you can add new drivers simply by dropping them in a
131
+
132
+ directory and using the Driver''s `create` method to instantiate them:'
133
+ email:
49
134
  - stillflame@FaerieMUD.org
50
135
  - ged@FaerieMUD.org
51
136
  executables: []
52
-
53
137
  extensions: []
54
-
55
- extra_rdoc_files:
138
+ extra_rdoc_files:
139
+ - Manifest.txt
140
+ - History.rdoc
141
+ - README.rdoc
142
+ files:
56
143
  - ChangeLog
57
- - README
58
- - LICENSE
59
- files:
144
+ - History.rdoc
145
+ - Manifest.txt
146
+ - README.rdoc
60
147
  - Rakefile
61
- - ChangeLog
62
- - README
63
- - LICENSE
64
- - spec/pluginfactory_spec.rb
65
- - spec/lib/helpers.rb
66
148
  - lib/pluginfactory.rb
67
- - rake/191_compat.rb
68
- - rake/dependencies.rb
69
- - rake/documentation.rb
70
- - rake/helpers.rb
71
- - rake/hg.rb
72
- - rake/manual.rb
73
- - rake/packaging.rb
74
- - rake/publishing.rb
75
- - rake/style.rb
76
- - rake/svn.rb
77
- - rake/testing.rb
78
- - rake/verifytask.rb
79
- has_rdoc: true
80
- homepage: http://deveiate.org/projects/PluginFactory/
81
- licenses: []
82
-
149
+ - spec/lib/helpers.rb
150
+ - spec/pluginfactory_spec.rb
151
+ - .gemtest
152
+ homepage: http://deveiate.org/projects/PluginFactory
153
+ licenses:
154
+ - BSD
83
155
  post_install_message:
84
- rdoc_options:
85
- - --tab-width=4
86
- - --show-hash
87
- - --include
88
- - .
89
- - --main=README
90
- - --title=pluginfactory
91
- require_paths:
156
+ rdoc_options:
157
+ - --main
158
+ - README.rdoc
159
+ require_paths:
92
160
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
161
+ required_ruby_version: !ruby/object:Gem::Requirement
94
162
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
168
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
111
173
  requirements: []
112
-
113
- rubyforge_project:
114
- rubygems_version: 1.3.7
174
+ rubyforge_project: pluginfactory
175
+ rubygems_version: 1.8.16
115
176
  signing_key:
116
177
  specification_version: 3
117
- summary: A mixin for making plugin classes
118
- test_files:
119
- - spec/pluginfactory_spec.rb
120
- - spec/lib/helpers.rb
178
+ summary: PluginFactory is a mixin module that turns an including class into a factory
179
+ for its derivatives, capable of searching for and loading them by name
180
+ test_files: []
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- 5���,�Z�ӵ)h�������Z1q�����~����T|�� ��6"��*.<�d:�O��I��=���oJ�x� �|��~͖�-=�z�
2
- Y�8�?a^� MѼ�}X`�Bke��a��5ä{��֍M�coa9�Mc_}��r�����/gD��KIM�3��j-��N���A�� x���\����o�&�<6Á�M�G����F�(Ț����B�C�{��]0P�Y5�r (;�`��[/�J��xE.e�ߙj
1
+ *���W��y�K������M�[n��H;�:[2M�B)�\%���!PK��� 1,���:e۰�V�~:&�uCe'p -�Qܮ��w s׋�"a7'j,D�ᴱ J��O�7���$hnkƜA��X���#6��������o��h�,����T#��f0Ʊ�Z����Mi I�l�l���t���zF[T��{��V~TpX>�P�qԬ/�6�;^߫��x�R|Q��w���{���ѫc/��&uf=�6�a
data/LICENSE DELETED
@@ -1,27 +0,0 @@
1
- Copyright (c) 2008, 2009 Michael Granger and Martin Chase
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
-
7
- * Redistributions of source code must retain the above copyright notice,
8
- this list of conditions and the following disclaimer.
9
-
10
- * Redistributions in binary form must reproduce the above copyright notice,
11
- this list of conditions and the following disclaimer in the documentation
12
- and/or other materials provided with the distribution.
13
-
14
- * Neither the name of the author/s, nor the names of the project's
15
- contributors may be used to endorse or promote products derived from this
16
- software without specific prior written permission.
17
-
18
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README DELETED
@@ -1,200 +0,0 @@
1
-
2
- = PluginFactory
3
-
4
- PluginFactory is a mixin module that turns an including class into a factory for
5
- its derivatives, capable of searching for and loading them by name. This is
6
- useful when you have an abstract base class which defines an interface and basic
7
- functionality for a part of a larger system, and a collection of subclasses
8
- which implement the interface for different underlying functionality.
9
-
10
- An example of where this might be useful is in a program which talks to a
11
- database. To avoid coupling it to a specific database, you use a Driver class
12
- which encapsulates your program's interaction with the database behind a useful
13
- interface. Now you can create a concrete implementation of the Driver class for
14
- each kind of database you wish to talk to. If you make the base Driver class a
15
- PluginFactory, too, you can add new drivers simply by dropping them in a
16
- directory and using the Driver's <tt>create</tt> method to instantiate them:
17
-
18
- == Synopsis
19
-
20
- in driver.rb:
21
-
22
- require "PluginFactory"
23
-
24
- class Driver
25
- include PluginFactory
26
- def self::derivative_dirs
27
- ["drivers"]
28
- end
29
- end
30
-
31
- in drivers/mysql.rb:
32
-
33
- require 'driver'
34
-
35
- class MysqlDriver < Driver
36
- ...implementation...
37
- end
38
-
39
- in /usr/lib/ruby/1.8/PostgresDriver.rb:
40
-
41
- require 'driver'
42
-
43
- class PostgresDriver < Driver
44
- ...implementation...
45
- end
46
-
47
- elsewhere
48
-
49
- require 'driver'
50
-
51
- config[:driver_type] #=> "mysql"
52
- driver = Driver.create( config[:driver_type] )
53
- driver.class #=> MysqlDriver
54
- pgdriver = Driver.create( "PostGresDriver" )
55
-
56
- == How Plugins Are Loaded
57
-
58
- The +create+ class method added to your class by PluginFactory searches for your
59
- module using several different strategies. It tries various permutations of the
60
- base class's name in combination with the derivative requested. For example,
61
- assume we want to make a +DataDriver+ base class, and then use plugins to define
62
- drivers for different kinds of data sources:
63
-
64
- require 'pluginfactory'
65
-
66
- class DataDriver
67
- include PluginFactory
68
- end
69
-
70
- When you attempt to load the 'socket' data-driver class like so:
71
-
72
- DataDriver.create( 'socket' )
73
-
74
- PluginFactory searches for modules with the following names:
75
-
76
- 'socketdatadriver'
77
- 'socket_datadriver'
78
- 'socketDataDriver'
79
- 'socket_DataDriver'
80
- 'SocketDataDriver'
81
- 'Socket_DataDriver'
82
- 'socket'
83
- 'Socket'
84
-
85
- Obviously the last one will load something other than what is intended, so you
86
- can also tell PluginFactory that plugins should be loaded from a subdirectory by
87
- declaring a class method called `derivative_dirs` in the base class. It should
88
- return an Array that contains a list of subdirectories to try:
89
-
90
- class DataDriver
91
- include PluginFactory
92
-
93
- def self::derivative_dirs
94
- ['drivers']
95
- end
96
- end
97
-
98
- This will change the list that is required to:
99
-
100
- 'drivers/socketdatadriver'
101
- 'drivers/socket_datadriver'
102
- 'drivers/socketDataDriver'
103
- 'drivers/socket_DataDriver'
104
- 'drivers/SocketDataDriver'
105
- 'drivers/Socket_DataDriver'
106
- 'drivers/socket'
107
- 'drivers/Socket'
108
-
109
- If you return more than one subdirectory, each of them will be tried in turn:
110
-
111
- class DataDriver
112
- include PluginFactory
113
-
114
- def self::derivative_dirs
115
- ['drivers', 'datadriver']
116
- end
117
- end
118
-
119
- will change the search to include:
120
-
121
- 'drivers/socketdatadriver'
122
- 'drivers/socket_datadriver'
123
- 'drivers/socketDataDriver'
124
- 'drivers/socket_DataDriver'
125
- 'drivers/SocketDataDriver'
126
- 'drivers/Socket_DataDriver'
127
- 'drivers/socket'
128
- 'drivers/Socket'
129
- 'datadriver/socketdatadriver'
130
- 'datadriver/socket_datadriver'
131
- 'datadriver/socketDataDriver'
132
- 'datadriver/socket_DataDriver'
133
- 'datadriver/SocketDataDriver'
134
- 'datadriver/Socket_DataDriver'
135
- 'datadriver/socket'
136
- 'datadriver/Socket'
137
-
138
- If the plugin is not found, a FactoryError is raised, and the message will list
139
- all the permutations that were tried.
140
-
141
- == Logging
142
-
143
- If you need a little more insight into what's going on, PluginFactory exposes a
144
- logging callback which will be called at various points in the process, and will
145
- include details on what's being attempted.
146
-
147
- You can activate logging by setting PluginFactory.logger_callback to something
148
- that responds to the #call message. It will be called with two arguments, a
149
- severity level and a message:
150
-
151
- callback.call( :info, "Something happened" )
152
-
153
- This is intended to make it easy to hook up to Logger or anything with a similar
154
- interface:
155
-
156
- require 'pluginfactory'
157
- require 'logger'
158
-
159
- class DataDriver
160
- include PluginFactory
161
-
162
- @logger = Logger.new( $stderr )
163
- @logger.level = Logger::DEBUG
164
- PluginFactory.logger_callback = lambda do |severity, msg|
165
- @logger.send(severity, msg)
166
- end
167
- end
168
-
169
- DataDriver.create( 'ringbuffer' )
170
-
171
- this might generate a log that looks like:
172
-
173
- D, [...] DEBUG -- : Loading derivative ringbuffer
174
- D, [...] DEBUG -- : Subdirs are: [""]
175
- D, [...] DEBUG -- : Path is: ["ringbufferdatadriver", "ringbufferDataDriver",
176
- "ringbuffer"]...
177
- D, [...] DEBUG -- : Trying ringbufferdatadriver...
178
- D, [...] DEBUG -- : No module at 'ringbufferdatadriver', trying the next
179
- alternative: 'no such file to load -- ringbufferdatadriver'
180
- D, [...] DEBUG -- : Trying ringbufferDataDriver...
181
- D, [...] DEBUG -- : No module at 'ringbufferDataDriver', trying the next
182
- alternative: 'no such file to load -- ringbufferDataDriver'
183
- D, [...] DEBUG -- : Trying ringbuffer...
184
- D, [...] DEBUG -- : No module at 'ringbuffer', trying the next alternative:
185
- 'no such file to load -- ringbuffer'
186
- D, [...] DEBUG -- : fatals = []
187
- E, [...] ERROR -- : Couldn't find a DataDriver named 'ringbuffer':
188
- tried ["ringbufferdatadriver", "ringbufferDataDriver", "ringbuffer"]
189
-
190
- == Authors
191
-
192
- * Martin Chase <stillflame@FaerieMUD.org>
193
- * Michael Granger <ged@FaerieMUD.org>
194
-
195
- :include: LICENSE
196
-
197
- --
198
-
199
- Please see the file LICENSE for licensing details.
200
-