pluggability 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -2
- data/History.rdoc +6 -0
- data/lib/pluggability.rb +36 -23
- data/spec/pluggability_spec.rb +10 -6
- metadata +3 -3
- 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: a4a48369fcbed3a05f6c1d709edf28215bc7a69f
|
4
|
+
data.tar.gz: 71d8323ae8af471d64796aebdb53814c12b34d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d7eaa318bd1a7b45a0e704ea1c8e3b10c290551a407c7334ff92b1e065fa5fd89e6a3fdf9036018edd5fc75be5ec5110b5a39542090b6b158da1ec74cc20d01
|
7
|
+
data.tar.gz: 930077f441537a74d322f7ef28ac2be40c2031194bfc31e67d6f6ec723029627a48af8d86bf5cb6a7eacf2f3f2291a643bdecb22ad1f2254daea3db8b47d8b37
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
M��
|
2
|
-
|
1
|
+
qK�GI��M�yR����t���^S��Dr�1J�x�'+�~�7@
|
2
|
+
|
data/History.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== v0.1.0 [2013-03-27] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
- Add loading via underbarred name variants (CommaDelimitedThing ->
|
4
|
+
comma_delimited)
|
5
|
+
- Rename some stuff for consistency.
|
6
|
+
|
1
7
|
== v0.0.2 [2012-08-13] Michael Granger <ged@FaerieMUD.org>
|
2
8
|
|
3
9
|
Simplify Pluggability#derivatives.
|
data/lib/pluggability.rb
CHANGED
@@ -12,7 +12,7 @@ module Pluggability
|
|
12
12
|
|
13
13
|
|
14
14
|
# Library version
|
15
|
-
VERSION = '0.0
|
15
|
+
VERSION = '0.1.0'
|
16
16
|
|
17
17
|
|
18
18
|
### An exception class for Pluggability specific errors.
|
@@ -55,7 +55,7 @@ module Pluggability
|
|
55
55
|
|
56
56
|
|
57
57
|
### Returns the type name used when searching for a derivative.
|
58
|
-
def
|
58
|
+
def plugin_type
|
59
59
|
base = nil
|
60
60
|
self.ancestors.each do |klass|
|
61
61
|
if klass.instance_variables.include?( :@derivatives ) ||
|
@@ -65,7 +65,7 @@ module Pluggability
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
raise FactoryError, "Couldn't find
|
68
|
+
raise FactoryError, "Couldn't find plugin base for #{self.name}" if
|
69
69
|
base.nil?
|
70
70
|
|
71
71
|
if base.name =~ /^.*::(.*)/
|
@@ -74,6 +74,7 @@ module Pluggability
|
|
74
74
|
return base.name
|
75
75
|
end
|
76
76
|
end
|
77
|
+
alias factory_type plugin_type
|
77
78
|
|
78
79
|
|
79
80
|
### Inheritance callback -- Register subclasses in the derivatives hash
|
@@ -84,16 +85,7 @@ module Pluggability
|
|
84
85
|
|
85
86
|
# If it's not an anonymous class, make some keys out of variants of its name
|
86
87
|
if subclass.name
|
87
|
-
|
88
|
-
keys << simple_name << simple_name.downcase
|
89
|
-
|
90
|
-
# Handle class names like 'FooBar' for 'Bar' factories.
|
91
|
-
Pluggability.log.debug "Inherited %p for %p-type plugins" % [ subclass, self.factory_type ]
|
92
|
-
if subclass.name.match( /(?:.*::)?(\w+)(?:#{self.factory_type})/i )
|
93
|
-
keys << Regexp.last_match[1].downcase
|
94
|
-
else
|
95
|
-
keys << subclass.name.sub( /.*::/, '' ).downcase
|
96
|
-
end
|
88
|
+
keys += self.make_derivative_names( subclass )
|
97
89
|
else
|
98
90
|
Pluggability.log.debug " no name-based variants for anonymous subclass %p" % [ subclass ]
|
99
91
|
end
|
@@ -108,6 +100,27 @@ module Pluggability
|
|
108
100
|
end
|
109
101
|
|
110
102
|
|
103
|
+
### Return all variants of the name of the given +subclass+ that can be
|
104
|
+
### used to load it.
|
105
|
+
def make_derivative_names( subclass )
|
106
|
+
keys = []
|
107
|
+
|
108
|
+
simple_name = subclass.name.sub( /^.*::/i, '' ).sub( /\W+$/, '' )
|
109
|
+
keys << simple_name << simple_name.downcase
|
110
|
+
keys << simple_name.gsub( /([a-z])([A-Z])/, "\\1_\\2" ).downcase
|
111
|
+
|
112
|
+
# Handle class names like 'FooBar' for 'Bar' factories.
|
113
|
+
Pluggability.log.debug "Inherited %p for %p-type plugins" % [ subclass, self.plugin_type ]
|
114
|
+
if subclass.name.match( /(?:.*::)?(\w+)(?:#{self.plugin_type})/i )
|
115
|
+
keys << Regexp.last_match[1].downcase
|
116
|
+
else
|
117
|
+
keys << subclass.name.sub( /.*::/, '' ).downcase
|
118
|
+
end
|
119
|
+
|
120
|
+
return keys
|
121
|
+
end
|
122
|
+
|
123
|
+
|
111
124
|
### Returns an Array of registered derivatives
|
112
125
|
def derivative_classes
|
113
126
|
self.derivatives.values.uniq
|
@@ -169,7 +182,7 @@ module Pluggability
|
|
169
182
|
|
170
183
|
|
171
184
|
### Find and load all derivatives of this class, using plugin_prefixes if any
|
172
|
-
### are defined, or a pattern derived from the #
|
185
|
+
### are defined, or a pattern derived from the #plugin_type if not. Returns
|
173
186
|
### an array of all derivative classes. Load failures are logged but otherwise
|
174
187
|
### ignored.
|
175
188
|
def load_all
|
@@ -183,8 +196,8 @@ module Pluggability
|
|
183
196
|
end
|
184
197
|
else
|
185
198
|
# Use all but the last pattern, which will just be '*.rb'
|
186
|
-
Pluggability.log.debug "Using
|
187
|
-
[ self.
|
199
|
+
Pluggability.log.debug "Using plugin type (%p) to build load patterns." %
|
200
|
+
[ self.plugin_type ]
|
188
201
|
patterns += self.make_require_path( '*', '' )[0..-2].
|
189
202
|
map {|f| f + '.rb' }
|
190
203
|
end
|
@@ -225,7 +238,7 @@ module Pluggability
|
|
225
238
|
unless self.derivatives[ class_name.downcase ]
|
226
239
|
errmsg = "Require of '%s' succeeded, but didn't load a %s named '%s' for some reason." % [
|
227
240
|
result,
|
228
|
-
self.
|
241
|
+
self.plugin_type,
|
229
242
|
class_name.downcase,
|
230
243
|
]
|
231
244
|
Pluggability.log.error( errmsg )
|
@@ -236,11 +249,11 @@ module Pluggability
|
|
236
249
|
|
237
250
|
### Build and return the unique part of the given <tt>class_name</tt>
|
238
251
|
### either by stripping leading namespaces if the name already has the
|
239
|
-
### name of the
|
240
|
-
### or by appending the
|
252
|
+
### name of the plugin type in it (eg., 'My::FooService' for Service,
|
253
|
+
### or by appending the plugin type if it doesn't.
|
241
254
|
def get_module_name( class_name )
|
242
|
-
if class_name =~ /\w+#{self.
|
243
|
-
mod_name = class_name.sub( /(?:.*::)?(\w+)(?:#{self.
|
255
|
+
if class_name =~ /\w+#{self.plugin_type}/
|
256
|
+
mod_name = class_name.sub( /(?:.*::)?(\w+)(?:#{self.plugin_type})/, "\\1" )
|
244
257
|
else
|
245
258
|
mod_name = class_name
|
246
259
|
end
|
@@ -290,7 +303,7 @@ module Pluggability
|
|
290
303
|
# some reason.
|
291
304
|
if fatals.empty?
|
292
305
|
errmsg = "Couldn't find a %s named '%s': tried %p" % [
|
293
|
-
self.
|
306
|
+
self.plugin_type,
|
294
307
|
mod_name,
|
295
308
|
tries
|
296
309
|
]
|
@@ -310,7 +323,7 @@ module Pluggability
|
|
310
323
|
### "drivers/SocketDataDriver", "drivers/socket", "drivers/Socket"]
|
311
324
|
def make_require_path( modname, subdir )
|
312
325
|
path = []
|
313
|
-
myname = self.
|
326
|
+
myname = self.plugin_type
|
314
327
|
|
315
328
|
# Make permutations of the two parts
|
316
329
|
path << modname
|
data/spec/pluggability_spec.rb
CHANGED
@@ -104,7 +104,7 @@ describe Pluggability do
|
|
104
104
|
Plugin.should_receive( :require ).with( 'plugins/dazzle_plugin' ).and_return do |*args|
|
105
105
|
loaded_class = Class.new( Plugin )
|
106
106
|
# Simulate a named class, since we're not really requiring
|
107
|
-
Plugin.derivatives['dazzle'] = loaded_class
|
107
|
+
Plugin.derivatives['dazzle'] = loaded_class
|
108
108
|
true
|
109
109
|
end
|
110
110
|
|
@@ -162,7 +162,7 @@ describe Pluggability do
|
|
162
162
|
and_return( true )
|
163
163
|
Plugin.should_receive( :require ).with( 'plugins/private/third.rb' ).
|
164
164
|
and_return( true )
|
165
|
-
|
165
|
+
|
166
166
|
Plugin.load_all
|
167
167
|
end
|
168
168
|
end
|
@@ -170,15 +170,15 @@ describe Pluggability do
|
|
170
170
|
|
171
171
|
context "derivative of an extended class" do
|
172
172
|
|
173
|
-
it "knows what type of
|
174
|
-
TestingPlugin.
|
173
|
+
it "knows what type of plugin loads it" do
|
174
|
+
TestingPlugin.plugin_type.should == 'Plugin'
|
175
175
|
end
|
176
176
|
|
177
177
|
it "raises a FactoryError if it can't figure out what type of factory loads it" do
|
178
178
|
TestingPlugin.stub!( :ancestors ).and_return( [] )
|
179
179
|
expect {
|
180
|
-
TestingPlugin.
|
181
|
-
}.to raise_error( Pluggability::FactoryError, /couldn't find
|
180
|
+
TestingPlugin.plugin_type
|
181
|
+
}.to raise_error( Pluggability::FactoryError, /couldn't find plugin base/i )
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
@@ -189,6 +189,10 @@ describe Pluggability do
|
|
189
189
|
Plugin.create( 'blacksheep' ).should be_an_instance_of( BlackSheep )
|
190
190
|
end
|
191
191
|
|
192
|
+
it "is loadable via its underbarred name" do
|
193
|
+
Plugin.create( 'black_sheep' ).should be_an_instance_of( BlackSheep )
|
194
|
+
end
|
195
|
+
|
192
196
|
end
|
193
197
|
|
194
198
|
|
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.0
|
4
|
+
version: 0.1.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-27 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: loggability
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project: pluggability
|
184
|
-
rubygems_version: 2.0.
|
184
|
+
rubygems_version: 2.0.3
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: Pluggability is a mixin module that turns an including class into a factory
|
metadata.gz.sig
CHANGED
Binary file
|