document_hash 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/document_hash/core.rb +10 -0
- data/lib/document_hash/version.rb +1 -1
- data/spec/lib/document_spec.rb +26 -2
- metadata +2 -2
data/lib/document_hash/core.rb
CHANGED
@@ -45,6 +45,16 @@ module DocumentHash
|
|
45
45
|
values.select{|v| v.is_a? self.class }.each{ |v| v.reset! }
|
46
46
|
end
|
47
47
|
|
48
|
+
def touch!
|
49
|
+
self.each do |key, value|
|
50
|
+
if value.is_a? self.class
|
51
|
+
value.touch!
|
52
|
+
else
|
53
|
+
changed_key key,value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
48
58
|
def merge other
|
49
59
|
dup.merge! other
|
50
60
|
end
|
data/spec/lib/document_spec.rb
CHANGED
@@ -135,13 +135,37 @@ describe DocumentHash::Core do
|
|
135
135
|
subject[:inner][:attribute].should == "hola"
|
136
136
|
end
|
137
137
|
|
138
|
-
it "
|
138
|
+
it "has a touch functionality that re runs the after change callback" do
|
139
|
+
subject = DocumentHash::Core[ { test: :value } ]
|
140
|
+
test_mock = mock("test")
|
141
|
+
test_mock.should_receive(:callback_mock).with( [:test], :value )
|
142
|
+
|
143
|
+
subject.after_change do |path,value|
|
144
|
+
test_mock.callback_mock path, value
|
145
|
+
end
|
146
|
+
|
147
|
+
subject.touch!
|
148
|
+
end
|
149
|
+
|
150
|
+
it "has a touch functionality that handle deeper hashes" do
|
151
|
+
subject = DocumentHash::Core[ { inner: { attribute: :value } } ]
|
152
|
+
test_mock = mock("test")
|
153
|
+
test_mock.should_receive(:callback_mock).with( [:inner, :attribute], :value )
|
154
|
+
|
155
|
+
subject.after_change do |path,value|
|
156
|
+
test_mock.callback_mock path, value
|
157
|
+
end
|
158
|
+
|
159
|
+
subject.touch!
|
160
|
+
end
|
161
|
+
|
162
|
+
it "converts itself to a hash" do
|
139
163
|
subject = DocumentHash::Core[{ test: "test" }]
|
140
164
|
hash = subject.to_hash
|
141
165
|
hash.should be_an_instance_of Hash
|
142
166
|
end
|
143
167
|
|
144
|
-
it "converts internal hashes to hash"
|
168
|
+
it "converts internal hashes to hash" do
|
145
169
|
subject = DocumentHash::Core[{ test: { inner: "value" } }]
|
146
170
|
hash = subject.to_hash
|
147
171
|
hash[:test].should be_an_instance_of Hash
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: document_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
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: 2013-
|
12
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|