pluggability 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +5 -5
- data/History.rdoc +7 -0
- data/README.rdoc +2 -2
- data/Rakefile +4 -3
- data/lib/pluggability.rb +38 -30
- data/spec/pluggability_spec.rb +15 -4
- metadata +8 -8
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6657aec37785ba2a1d1b7be5f114acf4924000bc
|
4
|
+
data.tar.gz: b86d76b06fa680fee6fb5288de1058340d67910d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91f428c726410e0e67fb3a5c9e83f2782e97aba1adfdbadffc38729a0bafe9c867ec18b9f75540675e8a325776a0d073ca25214e612d90015f113afdf4432aab
|
7
|
+
data.tar.gz: 6b332d73c7d3abd9fb3ae481eed77931eca4760a8bb37371cb9925b5556ecc78ae4a4ec0d1fa8388da4b168ce69a3c0f0940f01725f813780d741d7b941a3b1e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
[f66a50774525]
|
24
24
|
|
25
25
|
* lib/pluggability.rb, spec/pluggability_spec.rb:
|
26
|
-
Fix specs for
|
26
|
+
Fix specs for PluginError changes; add backward-compatibility
|
27
27
|
constant.
|
28
28
|
[379015772893] [v0.0.1]
|
29
29
|
|
@@ -329,7 +329,7 @@
|
|
329
329
|
[7ef14552ab3d]
|
330
330
|
|
331
331
|
* lib/pluginfactory.rb:
|
332
|
-
- Made load failures raise
|
332
|
+
- Made load failures raise PluginErrors as intended instead of
|
333
333
|
RuntimeErrors.
|
334
334
|
[e95a4103ceff]
|
335
335
|
|
@@ -416,7 +416,7 @@
|
|
416
416
|
[bdfc3046476d]
|
417
417
|
|
418
418
|
* lib/pluginfactory.rb:
|
419
|
-
|
419
|
+
PluginError now inherits from RuntimeError
|
420
420
|
[fff45f7bd617]
|
421
421
|
|
422
422
|
* test.rb:
|
@@ -578,7 +578,7 @@
|
|
578
578
|
[b83ace0e5210]
|
579
579
|
|
580
580
|
* lib/pluginfactory.rb:
|
581
|
-
- Made load failures raise
|
581
|
+
- Made load failures raise PluginErrors as intended instead of
|
582
582
|
RuntimeErrors.
|
583
583
|
[ee1c6ed5d684]
|
584
584
|
|
@@ -665,7 +665,7 @@
|
|
665
665
|
[48a6ad672ee6]
|
666
666
|
|
667
667
|
* lib/pluginfactory.rb:
|
668
|
-
|
668
|
+
PluginError now inherits from RuntimeError
|
669
669
|
[3bbead1f4ca4]
|
670
670
|
|
671
671
|
* test.rb:
|
data/History.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== v0.2.0 [2013-03-28] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
- Fix loading of grandchildren of plugins
|
4
|
+
- Rename Pluggability::FactoryError to
|
5
|
+
Pluggability::PluginError (with backward-compatibility aliases)
|
6
|
+
|
7
|
+
|
1
8
|
== v0.1.0 [2013-03-27] Michael Granger <ged@FaerieMUD.org>
|
2
9
|
|
3
10
|
- Add loading via underbarred name variants (CommaDelimitedThing ->
|
data/README.rdoc
CHANGED
@@ -141,7 +141,7 @@ will change the search to include:
|
|
141
141
|
'datadriver/apache'
|
142
142
|
'datadriver/Apache'
|
143
143
|
|
144
|
-
If the plugin is not found, a Pluggability::
|
144
|
+
If the plugin is not found, a Pluggability::PluginError is raised, and
|
145
145
|
the message will list all the permutations that were tried.
|
146
146
|
|
147
147
|
|
@@ -215,7 +215,7 @@ and generate the API documentation.
|
|
215
215
|
|
216
216
|
== License
|
217
217
|
|
218
|
-
Copyright (c) 2008-
|
218
|
+
Copyright (c) 2008-2013, Michael Granger and Martin Chase
|
219
219
|
All rights reserved.
|
220
220
|
|
221
221
|
Redistribution and use in source and binary forms, with or without
|
data/Rakefile
CHANGED
@@ -12,14 +12,15 @@ hoespec = Hoe.spec 'pluggability' do
|
|
12
12
|
self.readme_file = 'README.rdoc'
|
13
13
|
self.history_file = 'History.rdoc'
|
14
14
|
self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
|
15
|
-
self.spec_extras[:rdoc_options] = ['-
|
15
|
+
self.spec_extras[:rdoc_options] = ['-t', 'Pluggability Toolkit']
|
16
|
+
self.spec_extras[:rdoc_options] += [ '-f', 'fivefish' ] if File.directory?( '.hg' )
|
16
17
|
|
17
18
|
self.developer 'Martin Chase', 'stillflame@FaerieMUD.org'
|
18
19
|
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
19
20
|
|
20
|
-
self.dependency 'loggability', '~> 0.
|
21
|
+
self.dependency 'loggability', '~> 0.6'
|
21
22
|
|
22
|
-
self.dependency 'hoe-deveiate', '~> 0.
|
23
|
+
self.dependency 'hoe-deveiate', '~> 0.2', :development
|
23
24
|
|
24
25
|
self.spec_extras[:licenses] = ["BSD"]
|
25
26
|
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
data/lib/pluggability.rb
CHANGED
@@ -12,25 +12,48 @@ module Pluggability
|
|
12
12
|
|
13
13
|
|
14
14
|
# Library version
|
15
|
-
VERSION = '0.
|
15
|
+
VERSION = '0.2.0'
|
16
16
|
|
17
17
|
|
18
|
-
|
19
|
-
class
|
18
|
+
# An exception class for Pluggability specific errors.
|
19
|
+
class PluginError < RuntimeError; end
|
20
|
+
FactoryError = PluginError
|
20
21
|
|
21
22
|
|
22
23
|
### Add the @derivatives instance variable to including classes.
|
23
24
|
def self::extend_object( obj )
|
24
25
|
obj.instance_variable_set( :@plugin_prefixes, [] )
|
25
26
|
obj.instance_variable_set( :@derivatives, {} )
|
27
|
+
|
28
|
+
Pluggability.pluggable_classes << obj
|
29
|
+
|
26
30
|
super
|
27
31
|
end
|
28
32
|
|
29
33
|
|
34
|
+
##
|
35
|
+
# The Array of all classes that have added Pluggability
|
36
|
+
@pluggable_classes = []
|
37
|
+
class << self; attr_reader :pluggable_classes; end
|
38
|
+
|
39
|
+
|
40
|
+
### Return the ancestor of +subclass+ that has Pluggability.
|
41
|
+
def self::plugin_base_class( subclass )
|
42
|
+
return subclass.ancestors.find do |klass|
|
43
|
+
Pluggability.pluggable_classes.include?( klass )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
30
48
|
#############################################################
|
31
49
|
### M I X I N M E T H O D S
|
32
50
|
#############################################################
|
33
51
|
|
52
|
+
### Return the Hash of derivative classes, keyed by various versions of
|
53
|
+
### the class name.
|
54
|
+
attr_reader :derivatives
|
55
|
+
|
56
|
+
|
34
57
|
### Get/set the prefixes that will be used when searching for particular plugins
|
35
58
|
### for the calling Class.
|
36
59
|
def plugin_prefixes( *args )
|
@@ -46,27 +69,10 @@ module Pluggability
|
|
46
69
|
end
|
47
70
|
|
48
71
|
|
49
|
-
### Return the Hash of derivative classes, keyed by various versions of
|
50
|
-
### the class name.
|
51
|
-
def derivatives
|
52
|
-
return super unless defined?( @derivatives )
|
53
|
-
return @derivatives
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
72
|
### Returns the type name used when searching for a derivative.
|
58
73
|
def plugin_type
|
59
|
-
base =
|
60
|
-
|
61
|
-
if klass.instance_variables.include?( :@derivatives ) ||
|
62
|
-
klass.instance_variables.include?( "@derivatives" )
|
63
|
-
base = klass
|
64
|
-
break
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
raise FactoryError, "Couldn't find plugin base for #{self.name}" if
|
69
|
-
base.nil?
|
74
|
+
base = Pluggability.plugin_base_class( self ) or
|
75
|
+
raise PluginError, "Couldn't find plugin base for #{self.name}"
|
70
76
|
|
71
77
|
if base.name =~ /^.*::(.*)/
|
72
78
|
return $1
|
@@ -80,20 +86,22 @@ module Pluggability
|
|
80
86
|
### Inheritance callback -- Register subclasses in the derivatives hash
|
81
87
|
### so that ::create knows about them.
|
82
88
|
def inherited( subclass )
|
83
|
-
Pluggability.
|
89
|
+
plugin_class = Pluggability.plugin_base_class( subclass )
|
90
|
+
|
91
|
+
Pluggability.logger.debug "%p inherited by %p" % [ plugin_class, subclass ]
|
84
92
|
keys = [ subclass ]
|
85
93
|
|
86
94
|
# If it's not an anonymous class, make some keys out of variants of its name
|
87
95
|
if subclass.name
|
88
|
-
keys +=
|
96
|
+
keys += plugin_class.make_derivative_names( subclass )
|
89
97
|
else
|
90
98
|
Pluggability.log.debug " no name-based variants for anonymous subclass %p" % [ subclass ]
|
91
99
|
end
|
92
100
|
|
93
101
|
keys.compact.uniq.each do |key|
|
94
102
|
Pluggability.log.info "Registering %s derivative of %s as %p" %
|
95
|
-
[ subclass.name,
|
96
|
-
|
103
|
+
[ subclass.name, plugin_class.name, key ]
|
104
|
+
plugin_class.derivatives[ key ] = subclass
|
97
105
|
end
|
98
106
|
|
99
107
|
super
|
@@ -170,7 +178,7 @@ module Pluggability
|
|
170
178
|
|
171
179
|
subclass = self.derivatives[ class_name.downcase ]
|
172
180
|
unless subclass.is_a?( Class )
|
173
|
-
raise
|
181
|
+
raise PluginError,
|
174
182
|
"load_derivative(%s) added something other than a class "\
|
175
183
|
"to the registry for %s: %p" %
|
176
184
|
[ class_name, self.name, subclass ]
|
@@ -242,7 +250,7 @@ module Pluggability
|
|
242
250
|
class_name.downcase,
|
243
251
|
]
|
244
252
|
Pluggability.log.error( errmsg )
|
245
|
-
raise
|
253
|
+
raise PluginError, errmsg, caller(3)
|
246
254
|
end
|
247
255
|
end
|
248
256
|
|
@@ -308,7 +316,7 @@ module Pluggability
|
|
308
316
|
tries
|
309
317
|
]
|
310
318
|
Pluggability.log.error( errmsg )
|
311
|
-
raise
|
319
|
+
raise PluginError, errmsg
|
312
320
|
else
|
313
321
|
Pluggability.log.debug "Re-raising first fatal error"
|
314
322
|
Kernel.raise( fatals.first )
|
@@ -349,5 +357,5 @@ end # module Pluggability
|
|
349
357
|
|
350
358
|
|
351
359
|
# Backward-compatibility alias
|
352
|
-
FactoryError = Pluggability::
|
360
|
+
FactoryError = Pluggability::PluginError unless defined?( FactoryError )
|
353
361
|
|
data/spec/pluggability_spec.rb
CHANGED
@@ -31,6 +31,8 @@ module Test
|
|
31
31
|
class LoadablePlugin < Plugin; end
|
32
32
|
end
|
33
33
|
|
34
|
+
class SubSubPlugin < SubPlugin; end
|
35
|
+
|
34
36
|
|
35
37
|
#
|
36
38
|
# Examples
|
@@ -122,7 +124,7 @@ describe Pluggability do
|
|
122
124
|
|
123
125
|
expect {
|
124
126
|
Plugin.create('scintillating')
|
125
|
-
}.to raise_error( Pluggability::
|
127
|
+
}.to raise_error( Pluggability::PluginError, /couldn't find a \S+ named \S+.*tried \[/i )
|
126
128
|
end
|
127
129
|
|
128
130
|
|
@@ -132,7 +134,7 @@ describe Pluggability do
|
|
132
134
|
|
133
135
|
expect {
|
134
136
|
Plugin.create('corruscating')
|
135
|
-
}.to raise_error( Pluggability::
|
137
|
+
}.to raise_error( Pluggability::PluginError, /Require of '\S+' succeeded, but didn't load a Plugin/i )
|
136
138
|
end
|
137
139
|
|
138
140
|
|
@@ -174,11 +176,11 @@ describe Pluggability do
|
|
174
176
|
TestingPlugin.plugin_type.should == 'Plugin'
|
175
177
|
end
|
176
178
|
|
177
|
-
it "raises a
|
179
|
+
it "raises a PluginError if it can't figure out what type of factory loads it" do
|
178
180
|
TestingPlugin.stub!( :ancestors ).and_return( [] )
|
179
181
|
expect {
|
180
182
|
TestingPlugin.plugin_type
|
181
|
-
}.to raise_error( Pluggability::
|
183
|
+
}.to raise_error( Pluggability::PluginError, /couldn't find plugin base/i )
|
182
184
|
end
|
183
185
|
end
|
184
186
|
|
@@ -204,5 +206,14 @@ describe Pluggability do
|
|
204
206
|
|
205
207
|
end
|
206
208
|
|
209
|
+
|
210
|
+
context "subclass of a derivative" do
|
211
|
+
|
212
|
+
it "is still registered with the base class" do
|
213
|
+
Plugin.derivatives[ 'subsub' ].should == SubSubPlugin
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
207
218
|
end
|
208
219
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluggability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Chase
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
|
32
32
|
/YSusaiDXHKU2O3Akc3htA==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2013-03-
|
34
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: loggability
|
@@ -39,14 +39,14 @@ dependencies:
|
|
39
39
|
requirements:
|
40
40
|
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
42
|
+
version: '0.6'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
49
|
+
version: '0.6'
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: hoe-mercurial
|
52
52
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,14 +95,14 @@ dependencies:
|
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version: '0.
|
98
|
+
version: '0.2'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
101
|
version_requirements: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
103
|
- - ~>
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: '0.
|
105
|
+
version: '0.2'
|
106
106
|
- !ruby/object:Gem::Dependency
|
107
107
|
name: hoe
|
108
108
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,10 +163,10 @@ licenses:
|
|
163
163
|
metadata: {}
|
164
164
|
post_install_message:
|
165
165
|
rdoc_options:
|
166
|
-
- -f
|
167
|
-
- fivefish
|
168
166
|
- -t
|
169
167
|
- Pluggability Toolkit
|
168
|
+
- -f
|
169
|
+
- fivefish
|
170
170
|
require_paths:
|
171
171
|
- lib
|
172
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|