optopus 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/optopus.rb +26 -18
  2. 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
- value = nil
160
+ values = nil
161
161
 
162
162
  [key, key.gsub(/[-_]/, '-'), key.gsub(/[-_]/, '_')].each do |k|
163
- if value = config[k]
163
+ if values = config[k]
164
164
  key = k
165
165
  break
166
166
  end
167
167
  end
168
168
 
169
- next unless value
169
+ next unless values
170
170
 
171
- value = orig_val = value.to_s
172
- type = args.find {|i| i.kind_of?(Class) }
173
- pat, conv = OptionParser::DefaultList.atype[type]
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
- if pat and pat !~ value
176
- raise OptionParser::InvalidArgument.new(v, "(#{key}: #{value})")
177
- end
176
+ if pat and pat !~ value
177
+ raise OptionParser::InvalidArgument.new(v, "(#{key}: #{value})")
178
+ end
178
179
 
179
- value = conv.call(value) if conv
180
+ value = conv.call(value) if conv
180
181
 
181
- if value and block
182
- begin
183
- CheckerContext.evaluate(v, value, &block)
184
- rescue OptionParser::ParseError => e
185
- errmsg = "#{e.message}: #{key}=#{orig_val}"
186
- raise OptionParser::ParseError, errmsg
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
- options[name] = value
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optopus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel