optopus 0.2.0 → 0.2.1
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.
- data/lib/optopus.rb +26 -18
- metadata +3 -3
data/lib/optopus.rb
CHANGED
@@ -157,37 +157,45 @@ module Optopus
|
|
157
157
|
key = name.to_s
|
158
158
|
end
|
159
159
|
|
160
|
-
|
160
|
+
values = nil
|
161
161
|
|
162
162
|
[key, key.gsub(/[-_]/, '-'), key.gsub(/[-_]/, '_')].each do |k|
|
163
|
-
if
|
163
|
+
if values = config[k]
|
164
164
|
key = k
|
165
165
|
break
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
next unless
|
169
|
+
next unless values
|
170
170
|
|
171
|
-
|
172
|
-
|
173
|
-
|
171
|
+
check = lambda do |value|
|
172
|
+
value = orig_val = value.to_s
|
173
|
+
type = args.find {|i| i.kind_of?(Class) }
|
174
|
+
pat, conv = OptionParser::DefaultList.atype[type]
|
174
175
|
|
175
|
-
|
176
|
-
|
177
|
-
|
176
|
+
if pat and pat !~ value
|
177
|
+
raise OptionParser::InvalidArgument.new(v, "(#{key}: #{value})")
|
178
|
+
end
|
178
179
|
|
179
|
-
|
180
|
+
value = conv.call(value) if conv
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
182
|
+
if value and block
|
183
|
+
begin
|
184
|
+
CheckerContext.evaluate(v, value, &block)
|
185
|
+
rescue OptionParser::ParseError => e
|
186
|
+
errmsg = "#{e.message}: #{key}=#{orig_val}"
|
187
|
+
raise OptionParser::ParseError, errmsg
|
188
|
+
end
|
187
189
|
end
|
188
|
-
end
|
189
190
|
|
190
|
-
|
191
|
+
return value
|
192
|
+
end # lambda
|
193
|
+
|
194
|
+
if values.kind_of?(Array)
|
195
|
+
options[name] = values.map {|i| check.call(i) }
|
196
|
+
else
|
197
|
+
options[name] = check.call(values)
|
198
|
+
end
|
191
199
|
end
|
192
200
|
end
|
193
201
|
end # if @file_args
|
metadata
CHANGED