map 4.6.1 → 4.7.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/a.rb +15 -35
- data/lib/map.rb +5 -5
- data/map.gemspec +1 -1
- data/test/map_test.rb +13 -9
- metadata +7 -9
data/a.rb
CHANGED
@@ -1,44 +1,24 @@
|
|
1
1
|
require 'map'
|
2
2
|
|
3
|
-
#m = Map.new
|
4
|
-
#m.default = []
|
5
|
-
|
6
|
-
class Errors < ::Map
|
7
|
-
def [](key)
|
8
|
-
self[key] = Array.new unless has_key?(key)
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
e = Errors.new
|
14
|
-
p e[:k]
|
15
|
-
p e
|
16
|
-
e.set(:a, :b, 42)
|
17
|
-
p e.get(:a, :b)
|
18
|
-
p e
|
19
|
-
#m = Map.new{|m,k| m[k] ||= Array.new}
|
20
|
-
|
21
|
-
|
22
|
-
#m.set(:a, :b, 42)
|
23
|
-
#p m.get(:a, :b)
|
24
|
-
|
25
3
|
|
26
|
-
|
27
|
-
|
28
|
-
#p m
|
29
|
-
#p m
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mongoid'
|
30
6
|
|
7
|
+
class Map
|
8
|
+
include Mongoid::Fields::Serializable
|
31
9
|
|
32
|
-
|
33
|
-
|
10
|
+
def default(*args)
|
11
|
+
@default
|
12
|
+
end
|
34
13
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
14
|
+
def deserialize(object)
|
15
|
+
Map.for(object.to_hash)
|
16
|
+
end
|
38
17
|
|
39
|
-
|
40
|
-
|
18
|
+
def serialize(object)
|
19
|
+
object.to_hash
|
20
|
+
end
|
41
21
|
end
|
42
22
|
|
43
|
-
|
44
|
-
|
23
|
+
m = Map.new
|
24
|
+
m[:key]
|
data/lib/map.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Map < Hash
|
2
|
-
Version = '4.
|
2
|
+
Version = '4.7.0' unless defined?(Version)
|
3
3
|
Load = Kernel.method(:load) unless defined?(Load)
|
4
4
|
|
5
5
|
class << Map
|
@@ -279,10 +279,6 @@ class Map < Hash
|
|
279
279
|
[convert_key(key), convert_value(val)]
|
280
280
|
end
|
281
281
|
|
282
|
-
# maps are aggressive with copy operations. they are all deep copies. make a
|
283
|
-
# new one if you really want a shallow copy
|
284
|
-
#
|
285
|
-
# TODO - fallback to shallow if objects cannot be marshal'd....
|
286
282
|
def copy
|
287
283
|
default = self.default
|
288
284
|
self.default = nil
|
@@ -307,6 +303,10 @@ class Map < Hash
|
|
307
303
|
key.is_a?(Symbol) && include?(key = key.to_s) ? self[key] : super
|
308
304
|
end
|
309
305
|
|
306
|
+
def default=(value)
|
307
|
+
raise ArgumentError.new("Map doesn't work so well with a non-nil default value!") unless value.nil?
|
308
|
+
end
|
309
|
+
|
310
310
|
# writer/reader methods
|
311
311
|
#
|
312
312
|
alias_method '__set__', '[]=' unless method_defined?('__set__')
|
data/map.gemspec
CHANGED
data/test/map_test.rb
CHANGED
@@ -10,14 +10,6 @@ Testing Map do
|
|
10
10
|
assert{ Map.new(hash = {}) }
|
11
11
|
end
|
12
12
|
|
13
|
-
testing 'that the contructor accepts a hash and preserves the default value' do
|
14
|
-
hash = {}
|
15
|
-
hash.default = 42
|
16
|
-
assert{ hash[:missing] == 42 }
|
17
|
-
map = assert{ Map.new(hash) }
|
18
|
-
assert{ map[:missing] == 42 }
|
19
|
-
end
|
20
|
-
|
21
13
|
testing 'that the constructor accepts the empty array' do
|
22
14
|
array = []
|
23
15
|
assert{ Map.new(array) }
|
@@ -586,7 +578,7 @@ Testing Map do
|
|
586
578
|
assert( m.A? )
|
587
579
|
end
|
588
580
|
|
589
|
-
testing 'that maps a clever little question method on Struct' do
|
581
|
+
testing 'that maps have a clever little question method on Struct' do
|
590
582
|
m = Map.new
|
591
583
|
m.set(:a, :b, :c, 42)
|
592
584
|
m.set([:x, :y, :z] => 42.0, [:A, 2] => 'forty-two')
|
@@ -610,6 +602,18 @@ Testing Map do
|
|
610
602
|
|
611
603
|
end
|
612
604
|
|
605
|
+
testing 'that Map#default= blows up until a sane strategy for dealing with it is developed' do
|
606
|
+
m = Map.new
|
607
|
+
|
608
|
+
assert do
|
609
|
+
begin
|
610
|
+
m.default = 42
|
611
|
+
rescue Object => e
|
612
|
+
e.is_a?(ArgumentError)
|
613
|
+
end
|
614
|
+
end
|
615
|
+
end
|
616
|
+
|
613
617
|
protected
|
614
618
|
def new_int_map(n = 1024)
|
615
619
|
map = assert{ Map.new }
|
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: 35
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 4.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 4.7.0
|
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-10-
|
18
|
+
date: 2011-10-19 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: "description: map kicks the ass"
|
@@ -42,8 +42,6 @@ files:
|
|
42
42
|
homepage: https://github.com/ahoward/map
|
43
43
|
licenses: []
|
44
44
|
|
45
|
-
metadata: {}
|
46
|
-
|
47
45
|
post_install_message:
|
48
46
|
rdoc_options: []
|
49
47
|
|
@@ -70,9 +68,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
68
|
requirements: []
|
71
69
|
|
72
70
|
rubyforge_project: codeforpeople
|
73
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.11
|
74
72
|
signing_key:
|
75
|
-
specification_version:
|
73
|
+
specification_version: 3
|
76
74
|
summary: map
|
77
75
|
test_files: []
|
78
76
|
|