@@ -30,7 +30,7 @@ module PluginHost
30
30
# * a file could not be found
31
31
# * the requested Plugin is not registered
32
32
PluginNotFound = Class . new LoadError
33
- HostNotFound = Class . new LoadError
33
+ HostNotFound = Class . new LoadError
34
34
35
35
PLUGIN_HOSTS = [ ]
36
36
PLUGIN_HOSTS_BY_ID = { } # dummy hash
@@ -49,8 +49,8 @@ def load_all
49
49
def [] id , *args , &blk
50
50
plugin = validate_id ( id )
51
51
begin
52
- plugin = plugin_hash . [] plugin , *args , &blk
53
- end while plugin . is_a? Symbol
52
+ plugin = plugin_hash . []( plugin , *args , &blk )
53
+ end while plugin . is_a? String
54
54
plugin
55
55
end
56
56
@@ -95,7 +95,7 @@ def plugin_path *args
95
95
def map hash
96
96
for from , to in hash
97
97
from = validate_id from
98
- to = validate_id to
98
+ to = validate_id to
99
99
plugin_hash [ from ] = to unless plugin_hash . has_key? from
100
100
end
101
101
end
@@ -197,23 +197,22 @@ def path_to plugin_id
197
197
File . join plugin_path , "#{ plugin_id } .rb"
198
198
end
199
199
200
- # Converts +id+ to a Symbol if it is a String,
201
- # or returns +id+ if it already is a Symbol.
200
+ # Converts +id+ to a valid plugin ID String, or returns +nil+.
202
201
#
203
202
# Raises +ArgumentError+ for all other objects, or if the
204
203
# given String includes non-alphanumeric characters (\W).
205
204
def validate_id id
206
- if id . is_a? Symbol or id . nil?
207
- id
208
- elsif id . is_a? String
205
+ case id
206
+ when Symbol
207
+ id . to_s
208
+ when String
209
209
if id [ /\w +/ ] == id
210
- # FIXME: cache attack
211
- id . downcase . to_sym
210
+ id . downcase
212
211
else
213
212
raise ArgumentError , "Invalid id given: #{ id } "
214
213
end
215
214
else
216
- raise ArgumentError , "String or Symbol expected, but #{ id . class } given."
215
+ raise ArgumentError , "Symbol or String expected, but #{ id . class } given."
217
216
end
218
217
end
219
218
0 commit comments