mm_dirtier 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mm_dirtier/support.rb +50 -0
- data/lib/mm_dirtier/version.rb +1 -1
- data/lib/mm_dirtier.rb +2 -1
- data/test/functional/test_observable_keys.rb +27 -4
- metadata +5 -4
@@ -0,0 +1,50 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Extensions
|
3
|
+
module Hash
|
4
|
+
def from_mongo(value)
|
5
|
+
value ||= {}
|
6
|
+
value.make_indifferent!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module IndifferentAccess
|
13
|
+
def [](key)
|
14
|
+
key = key.to_s
|
15
|
+
super(key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(key,val)
|
19
|
+
super(key.to_s,val)
|
20
|
+
end
|
21
|
+
|
22
|
+
def include?(key)
|
23
|
+
super(key.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(key)
|
27
|
+
super(key.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(sym,*args,&block)
|
31
|
+
return self[sym.to_s[0..-2]] = args[0] if sym.to_s =~ /.*=$/
|
32
|
+
return self[sym] if self.keys.include?(sym.to_s)
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Hash
|
38
|
+
extend MongoMapper::Extensions::Hash
|
39
|
+
|
40
|
+
def make_indifferent!
|
41
|
+
return self if defined?(@is_indifferent) && @is_indifferent
|
42
|
+
|
43
|
+
stringify_keys!
|
44
|
+
extend IndifferentAccess
|
45
|
+
@is_indifferent = true
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/lib/mm_dirtier/version.rb
CHANGED
data/lib/mm_dirtier.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class ObservableKeysTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
context "marking changes on observable array keys" do
|
6
|
+
setup do
|
7
|
+
@document = Doc { key :ary, Array }
|
8
|
+
end
|
8
9
|
|
9
|
-
context "marking changes on observable keys" do
|
10
10
|
should "not happen if there are none" do
|
11
11
|
doc = @document.new
|
12
12
|
doc.ary_changed?.should be_false
|
@@ -53,6 +53,29 @@ class ObservableKeysTest < Test::Unit::TestCase
|
|
53
53
|
a2.unshift("hi there")
|
54
54
|
doc.ary_changed?.should be_true
|
55
55
|
end
|
56
|
+
end
|
56
57
|
|
58
|
+
context "marking changes on observable hash keys" do
|
59
|
+
setup do
|
60
|
+
@document = Doc { key :hash, Hash }
|
61
|
+
end
|
62
|
+
|
63
|
+
should "happen when change happens" do
|
64
|
+
doc = @document.new
|
65
|
+
doc.hash = {"Golly" => "Gee", "Willikers" => "Batman"}
|
66
|
+
doc.hash_changed?.should be_true
|
67
|
+
doc.hash_was.should == {}
|
68
|
+
doc.hash_change.should == [{}, {"Golly" => "Gee", "Willikers" => "Batman"}]
|
69
|
+
end
|
70
|
+
|
71
|
+
should "happen when modified in place" do
|
72
|
+
doc = @document.new
|
73
|
+
doc.hash = {"Golly" => "Gee", "Willikers" => "Batman"}
|
74
|
+
doc.save!
|
75
|
+
doc.hash["Willikers"] = "Robin"
|
76
|
+
doc.hash_changed?.should be_true
|
77
|
+
doc.hash_was.should == {"Golly" => "Gee", "Willikers" => "Batman"}
|
78
|
+
doc.hash_change.should == [{"Golly" => "Gee", "Willikers" => "Batman"},{"Golly" => "Gee", "Willikers" => "Robin"}]
|
79
|
+
end
|
57
80
|
end
|
58
81
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm_dirtier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nathan Stults
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-04 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -104,6 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
|
105
105
|
files:
|
106
106
|
- lib/mm_dirtier/plugins/dirtier.rb
|
107
|
+
- lib/mm_dirtier/support.rb
|
107
108
|
- lib/mm_dirtier/extensions.rb
|
108
109
|
- lib/mm_dirtier/in_array_proxy_listener.rb
|
109
110
|
- lib/mm_dirtier/many_embedded_proxy_listener.rb
|