map 5.3.0 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/map.rb +1 -1
- data/lib/map/options.rb +27 -19
- data/map.gemspec +1 -1
- data/test/map_test.rb +20 -8
- metadata +2 -2
data/lib/map.rb
CHANGED
data/lib/map/options.rb
CHANGED
@@ -15,11 +15,14 @@ class Map
|
|
15
15
|
raise(ArgumentError, arg.inspect) unless arg.respond_to?(:to_hash)
|
16
16
|
arg.to_hash
|
17
17
|
end
|
18
|
+
|
18
19
|
unless options.is_a?(Options)
|
19
20
|
options = Map.for(options)
|
20
21
|
options.extend(Options)
|
21
22
|
end
|
23
|
+
|
22
24
|
raise unless options.is_a?(Map)
|
25
|
+
|
23
26
|
options
|
24
27
|
end
|
25
28
|
|
@@ -40,6 +43,20 @@ class Map
|
|
40
43
|
|
41
44
|
attr_accessor :arguments
|
42
45
|
|
46
|
+
def pop
|
47
|
+
arguments.pop if arguments.last.object_id == object_id
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def popped?
|
52
|
+
!(arguments.last.object_id == object_id)
|
53
|
+
end
|
54
|
+
|
55
|
+
def pop!
|
56
|
+
arguments.pop if arguments.last.object_id == object_id
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
43
60
|
%w( to_options stringify_keys ).each do |method|
|
44
61
|
module_eval <<-__, __FILE__, __LINE__
|
45
62
|
def #{ method }() dup end
|
@@ -108,30 +125,21 @@ class Map
|
|
108
125
|
end
|
109
126
|
alias_method('setopts', 'set_opts')
|
110
127
|
alias_method('setopts!', 'set_opts')
|
111
|
-
|
112
|
-
def pop
|
113
|
-
pop! unless popped?
|
114
|
-
self
|
115
|
-
end
|
116
|
-
|
117
|
-
def popped?
|
118
|
-
@popped = false unless defined?(@popped)
|
119
|
-
arguments and arguments.last!=self and @popped
|
120
|
-
end
|
121
|
-
|
122
|
-
def pop!
|
123
|
-
arguments.pop unless popped?
|
124
|
-
ensure
|
125
|
-
@popped = true
|
126
|
-
end
|
127
128
|
end
|
128
129
|
|
129
130
|
module Arguments
|
130
131
|
def options
|
131
132
|
@options ||=(
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
if last.is_a?(Hash)
|
134
|
+
options = Options.for(pop)
|
135
|
+
options.arguments = self
|
136
|
+
push(options)
|
137
|
+
options
|
138
|
+
else
|
139
|
+
options = Options.for({})
|
140
|
+
options.arguments = self
|
141
|
+
options
|
142
|
+
end
|
135
143
|
)
|
136
144
|
end
|
137
145
|
|
data/map.gemspec
CHANGED
data/test/map_test.rb
CHANGED
@@ -270,26 +270,38 @@ Testing Map do
|
|
270
270
|
testing 'that map supports basic option parsing for methods' do
|
271
271
|
%w( options_for options opts ).each do |method|
|
272
272
|
args = [0,1, {:k => :v, :a => false}]
|
273
|
+
Map.send(method, args)
|
273
274
|
opts = assert{ Map.send(method, args) }
|
274
275
|
assert{ opts.is_a?(Map) }
|
275
276
|
assert{ opts.getopt(:k)==:v }
|
276
277
|
assert{ opts.getopt(:a)==false }
|
277
278
|
assert{ opts.getopt(:b, :default => 42)==42 }
|
278
|
-
assert{ args.last.
|
279
|
+
assert{ args.last.object_id == opts.object_id }
|
279
280
|
end
|
280
281
|
end
|
281
282
|
|
282
283
|
testing 'that bang option parsing can pop the options off' do
|
283
|
-
|
284
|
-
|
284
|
+
logic = proc do |method, args|
|
285
|
+
before = args.dup
|
285
286
|
opts = assert{ Map.send(method, args) }
|
287
|
+
after = args
|
288
|
+
|
286
289
|
assert{ opts.is_a?(Map) }
|
287
|
-
assert{ !args.last.is_a?(Hash) }
|
290
|
+
assert{ !args.last.is_a?(Hash) } if before.last.is_a?(Hash)
|
291
|
+
assert{ args.last.object_id != opts.object_id }
|
288
292
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
+
opts
|
294
|
+
end
|
295
|
+
|
296
|
+
%w( options_for! options! opts! ).each do |method|
|
297
|
+
[
|
298
|
+
[0,1, {:k => :v, :a => false}],
|
299
|
+
[42],
|
300
|
+
[]
|
301
|
+
].each do |args|
|
302
|
+
opts = logic.call(method, args)
|
303
|
+
logic.call(method, [0, 1, opts])
|
304
|
+
end
|
293
305
|
end
|
294
306
|
end
|
295
307
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'description: map kicks the ass'
|
15
15
|
email: ara.t.howard@gmail.com
|