document_hash 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/lib/document_hash/version.rb +1 -1
- data/lib/document_hash.rb +8 -1
- data/spec/lib/document_spec.rb +11 -6
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/lib/document_hash.rb
CHANGED
@@ -5,9 +5,10 @@ module DocumentHash
|
|
5
5
|
def self.[] *attr
|
6
6
|
super(*attr).tap do|new|
|
7
7
|
new.each do |k,v|
|
8
|
-
p v.class
|
9
8
|
new[k] = new.class[v] if v.is_a?(Hash) && ! v.is_a?(self.class)
|
10
9
|
end
|
10
|
+
|
11
|
+
symbolize_keys new
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -55,5 +56,11 @@ module DocumentHash
|
|
55
56
|
def changed_attributes
|
56
57
|
@changed ||= Set.new
|
57
58
|
end
|
59
|
+
|
60
|
+
def self.symbolize_keys hash
|
61
|
+
hash.keys.each do |key|
|
62
|
+
hash[(key.to_sym rescue key) || key] = hash.delete(key)
|
63
|
+
end
|
64
|
+
end
|
58
65
|
end
|
59
66
|
end
|
data/spec/lib/document_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe DocumentHash::Core do
|
2
2
|
it "inherits from a hash" do
|
3
3
|
subject.is_a? Hash
|
4
4
|
end
|
@@ -21,10 +21,10 @@ describe Document::Core do
|
|
21
21
|
subject["test"].should == "test"
|
22
22
|
end
|
23
23
|
|
24
|
-
it "converts any internal hashes to
|
24
|
+
it "converts any internal hashes to DocumentHashes" do
|
25
25
|
subject[:test] = { inner: "test" }
|
26
26
|
|
27
|
-
subject[:test].should be_a_kind_of
|
27
|
+
subject[:test].should be_a_kind_of DocumentHash::Core
|
28
28
|
end
|
29
29
|
|
30
30
|
it "makes it child documents to refer its parent" do
|
@@ -63,9 +63,14 @@ describe Document::Core do
|
|
63
63
|
subject[:test].should_not be_changed
|
64
64
|
end
|
65
65
|
|
66
|
-
it "converts inner hashes into
|
67
|
-
subject =
|
66
|
+
it "converts inner hashes into DocumentHashes" do
|
67
|
+
subject = DocumentHash::Core[ { test: { inner: "test" } } ]
|
68
68
|
|
69
|
-
subject[:test].should be_a_kind_of
|
69
|
+
subject[:test].should be_a_kind_of DocumentHash::Core
|
70
|
+
end
|
71
|
+
|
72
|
+
it "simbolizes the keys when creating a hash" do
|
73
|
+
subject = DocumentHash::Core[ { "test" => "value" } ]
|
74
|
+
subject.keys.should include :test
|
70
75
|
end
|
71
76
|
end
|
data/spec/spec_helper.rb
CHANGED
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.3
|
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-05-
|
12
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|