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 CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ .*.sw?
@@ -1,3 +1,3 @@
1
1
  module DocumentHash
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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
@@ -1,4 +1,4 @@
1
- describe Document::Core do
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 Documents" do
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 Document::Core
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 Documents" do
67
- subject = Document::Core[ { test: { inner: "test" } } ]
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 Document::Core
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
@@ -1,4 +1,4 @@
1
- require './lib/document'
1
+ require './lib/document_hash'
2
2
 
3
3
  RSpec.configure do |config|
4
4
 
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.2
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-24 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec