optbind 0.2.2 → 0.3.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
- data/CHANGELOG.md +14 -0
- data/lib/optbind/version.rb +1 -1
- data/lib/optbind.rb +28 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf2645df5139cfb5f2da9545d463f30b5e2e7fcd
|
|
4
|
+
data.tar.gz: 19b95d76da822aa643ba5ee62ad5c00e6ab86ef4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33129020311fbd81302a02c87c18a11e8efbfe42f2ed66335b9cfa584dd2c023620918663088365e3147a47ecffef50c3abb40d11cfae29bd128753b2e5549d5
|
|
7
|
+
data.tar.gz: 65e76a032087b2590ffa173776c04f3e284ea707c8d1cc0cbdf246794a36cf27c5757dc37dd707bd05202f8a22e7309a6eee9db477924add3b23010e77b99b8e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 0.3.0
|
|
2
|
+
|
|
3
|
+
* Add support for access to assigned variables
|
|
4
|
+
|
|
5
|
+
* Fix default argument handler when encountering blank arguments
|
|
6
|
+
|
|
7
|
+
*Pavol Zbell*
|
|
8
|
+
|
|
9
|
+
## 0.2.2
|
|
10
|
+
|
|
11
|
+
* Fix default option handler when encountering blank arguments
|
|
12
|
+
|
|
13
|
+
*Pavol Zbell*
|
|
14
|
+
|
|
1
15
|
## 0.2.1
|
|
2
16
|
|
|
3
17
|
* Fix multiple argument parsing with arrays as default values
|
data/lib/optbind/version.rb
CHANGED
data/lib/optbind.rb
CHANGED
|
@@ -74,7 +74,7 @@ class OptionBinder
|
|
|
74
74
|
@parser.abort "missing argument: #{a}=" if !r || (r.respond_to?(:empty?) && r.empty?)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
handle! handler, r, bound, variable, default
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
(@bound_variables_with_defaults ||= {})[variable] = default if bound
|
|
@@ -106,10 +106,24 @@ class OptionBinder
|
|
|
106
106
|
Hash[@bound_variables_with_defaults.keys.map { |v| [v, @reader.call(v)] }]
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
+
def assigned_variables
|
|
110
|
+
return {} unless @assigned_variables_with_values
|
|
111
|
+
@assigned_variables_with_values.dup
|
|
112
|
+
end
|
|
113
|
+
|
|
109
114
|
def default?(v)
|
|
110
115
|
v = v.to_sym
|
|
111
|
-
return nil unless
|
|
112
|
-
@bound_variables_with_defaults[v] == @reader.call(v)
|
|
116
|
+
return nil unless bound? v
|
|
117
|
+
(@bound_variables_with_defaults[v] || {}) == @reader.call(v)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def bound?(v)
|
|
121
|
+
(@bound_variables_with_defaults || {}).has_key? v.to_sym
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def assigned?(v)
|
|
125
|
+
return nil unless bound? v
|
|
126
|
+
(@assigned_variables_with_values || {}).has_key? v.to_sym
|
|
113
127
|
end
|
|
114
128
|
|
|
115
129
|
module Switch
|
|
@@ -200,7 +214,7 @@ class OptionBinder
|
|
|
200
214
|
r = argv[0] ? argv.shift : default
|
|
201
215
|
r = ([r].flatten + argv.shift(argv.size)) if a[:opts].include? :MULTIPLE
|
|
202
216
|
@parser.abort 'missing arguments' if r.nil? && a[:opts].include?(:REQUIRED)
|
|
203
|
-
|
|
217
|
+
handle! a[:handler], r, a[:bound], a[:variable], default
|
|
204
218
|
return argv if a[:opts].include? :MULTIPLE
|
|
205
219
|
end
|
|
206
220
|
@parser.abort 'too many arguments' if argv[0]
|
|
@@ -209,6 +223,16 @@ class OptionBinder
|
|
|
209
223
|
|
|
210
224
|
private :parse_args, :parse_args!
|
|
211
225
|
|
|
226
|
+
def handle!(handler, raw, bound, variable, default)
|
|
227
|
+
(handler || -> (r) { r }).call(raw == nil ? default : raw).tap do |x|
|
|
228
|
+
return x unless bound
|
|
229
|
+
@writer.call variable, x
|
|
230
|
+
(@assigned_variables_with_values ||= {})[variable] = x
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
private :handle!
|
|
235
|
+
|
|
212
236
|
module Arguable
|
|
213
237
|
def binder=(bind)
|
|
214
238
|
unless @optbind = bind
|