map 5.3.0 → 5.4.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.
data/lib/map.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class Map < Hash
3
- Version = '5.3.0' unless defined?(Version)
3
+ Version = '5.4.0' unless defined?(Version)
4
4
  Load = Kernel.method(:load) unless defined?(Load)
5
5
 
6
6
  class << Map
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
- options = Options.for(last.is_a?(Hash) ? last : {})
133
- options.arguments = self
134
- options
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
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "map"
6
- spec.version = "5.3.0"
6
+ spec.version = "5.4.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
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.is_a?(Hash) }
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
- %w( options_for! options! opts! ).each do |method|
284
- args = [0,1, {:k => :v, :a => false}]
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
- new_args = [0,1, opts]
290
- new_opts = assert{ Map.send(method, new_args) }
291
- assert{ new_opts.is_a?(Map) }
292
- assert{ !new_args.last.is_a?(Hash) }
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.3.0
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-17 00:00:00.000000000 Z
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