map 4.6.1 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/a.rb +15 -35
  2. data/lib/map.rb +5 -5
  3. data/map.gemspec +1 -1
  4. data/test/map_test.rb +13 -9
  5. 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
- #m[:a].push(:b)
27
- #p m[:a]
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
- __END__
33
- args = [:a, :b, {:k => :v}]
10
+ def default(*args)
11
+ @default
12
+ end
34
13
 
35
- Map.update_options_for!(args) do |options|
36
- options[:foo] = :bar
37
- end
14
+ def deserialize(object)
15
+ Map.for(object.to_hash)
16
+ end
38
17
 
39
- Map.update_options_for!(args) do |options|
40
- options[:time] = Time.now
18
+ def serialize(object)
19
+ object.to_hash
20
+ end
41
21
  end
42
22
 
43
- p args
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.6.1' unless defined?(Version)
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__')
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "map"
6
- spec.version = "4.6.1"
6
+ spec.version = "4.7.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "map"
9
9
  spec.description = "description: map kicks the ass"
@@ -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: 37
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 4
8
- - 6
9
- - 1
10
- version: 4.6.1
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-08 00:00:00 Z
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.10
71
+ rubygems_version: 1.8.11
74
72
  signing_key:
75
- specification_version: 4
73
+ specification_version: 3
76
74
  summary: map
77
75
  test_files: []
78
76