map 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/map.rb +16 -7
- data/map.gemspec +1 -1
- data/test/map_test.rb +18 -0
- metadata +4 -4
data/lib/map.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Map < Hash
|
2
|
-
Version = '2.5.
|
2
|
+
Version = '2.5.1' unless defined?(Version)
|
3
3
|
Load = Kernel.method(:load) unless defined?(Load)
|
4
4
|
|
5
5
|
class << Map
|
@@ -47,8 +47,12 @@ class Map < Hash
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def coerce(other)
|
50
|
-
|
51
|
-
|
50
|
+
case other
|
51
|
+
when self
|
52
|
+
return other
|
53
|
+
else
|
54
|
+
allocate.update(other.to_hash)
|
55
|
+
end
|
52
56
|
end
|
53
57
|
|
54
58
|
def conversion_methods
|
@@ -167,13 +171,18 @@ class Map < Hash
|
|
167
171
|
super(&block)
|
168
172
|
|
169
173
|
when 1
|
170
|
-
|
174
|
+
first = args.first
|
175
|
+
case first
|
171
176
|
when Hash
|
172
|
-
initialize_from_hash(
|
177
|
+
initialize_from_hash(first)
|
173
178
|
when Array
|
174
|
-
initialize_from_array(
|
179
|
+
initialize_from_array(first)
|
175
180
|
else
|
176
|
-
|
181
|
+
if first.respond_to?(:to_hash)
|
182
|
+
initialize_from_hash(first.to_hash)
|
183
|
+
else
|
184
|
+
initialize_from_hash(first)
|
185
|
+
end
|
177
186
|
end
|
178
187
|
|
179
188
|
else
|
data/map.gemspec
CHANGED
data/test/map_test.rb
CHANGED
@@ -240,6 +240,24 @@ Testing Map do
|
|
240
240
|
assert{ map.list.all?{|x| x.id==42} }
|
241
241
|
end
|
242
242
|
|
243
|
+
testing 'that coercion is minimal' do
|
244
|
+
map = Map.new
|
245
|
+
a = Class.new(Map) do
|
246
|
+
def to_map() {:k => :a} end
|
247
|
+
end
|
248
|
+
b = Class.new(a) do
|
249
|
+
def to_map() {:k => :b} end
|
250
|
+
end
|
251
|
+
m = b.new
|
252
|
+
m.update(:list => [a.new, b.new])
|
253
|
+
assert{ m.list.first.class == b }
|
254
|
+
assert{ m.list.last.class == b }
|
255
|
+
m = a.new
|
256
|
+
m.update(:list => [a.new, b.new])
|
257
|
+
assert{ m.list.first.class == a }
|
258
|
+
assert{ m.list.last.class == a }
|
259
|
+
end
|
260
|
+
|
243
261
|
testing 'that map supports basic option parsing for methods' do
|
244
262
|
%w( options_for options opts ).each do |method|
|
245
263
|
args = [0,1, {:k => :v, :a => false}]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 2.5.
|
9
|
+
- 1
|
10
|
+
version: 2.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ara T. Howard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-14 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|