dot_hash 0.5.7 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/dot_hash/properties.rb +6 -5
- data/lib/dot_hash/version.rb +1 -1
- data/test/dot_hash/properties_test.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f2a20d001035964bad9b1410aed024647538eb
|
4
|
+
data.tar.gz: ef40f1c6b2c5d64a555754b94723b23a847063c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e7d0dac7042dd443cbcd381079bc29c6c7bb34a78a8c7d51f7fc137642b4db30e106110ed7c490aa500798f58ca26545a7cc882cef746e8d0909c48d6c8c27f
|
7
|
+
data.tar.gz: db1a85782e03701a13725d277ec8995e33278be9d93d784d61e6a650a1f5cb953481e249f57b1a846cdd9fd10e85e4af031cab5eab95daf4e6781137e43f964c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
# DotHash
|
3
|
-
[![Build Status](https://travis-ci.org/3den/dot_hash.png?branch=master)](https://travis-ci.org/3den/dot_hash)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/3den/dot_hash.png)](https://codeclimate.com/github/3den/dot_hash) [![Build Status](https://travis-ci.org/3den/dot_hash.png?branch=master)](https://travis-ci.org/3den/dot_hash)
|
4
4
|
|
5
5
|
A very efficient gem that lets you use hashes as object properties. It is almost as fast as a plain Hash
|
6
6
|
since it's complexity is also linear, `O(n) # where N is the number of nested parents of the given property`.
|
data/lib/dot_hash/properties.rb
CHANGED
@@ -40,14 +40,15 @@ module DotHash
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def execute(key, *args, &block)
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
get_value(key) do
|
44
|
+
hash.public_send(key, *args, &block)
|
45
|
+
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def get_value(key)
|
48
|
+
def get_value(key, &fallback)
|
49
49
|
key = hash.has_key?(key.to_s) ? key.to_s : key.to_sym
|
50
|
-
value = hash
|
50
|
+
value = hash.fetch(key) { fallback ? fallback.call : nil }
|
51
|
+
|
51
52
|
return value unless value.is_a?(Hash)
|
52
53
|
hash[key] = self.class.new value
|
53
54
|
end
|
data/lib/dot_hash/version.rb
CHANGED
@@ -38,7 +38,7 @@ module DotHash
|
|
38
38
|
describe "with a nested hash" do
|
39
39
|
before do
|
40
40
|
@properties = Properties.new user: {
|
41
|
-
"info" => {name: "dude", is_admin: false}
|
41
|
+
"info" => {name: "dude", is_admin: false, favorite_thing: nil}
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
@@ -50,6 +50,10 @@ module DotHash
|
|
50
50
|
properties.user.info.name.must_equal "dude"
|
51
51
|
properties.user.info.is_admin.must_equal false
|
52
52
|
end
|
53
|
+
|
54
|
+
it 'preserves nil-value nodes' do
|
55
|
+
properties.user.info.favorite_thing.must_equal nil
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
59
|
describe "#[]" do
|
@@ -64,6 +68,10 @@ module DotHash
|
|
64
68
|
it "accesses properties like a string hash" do
|
65
69
|
properties["user"]["name"].must_equal "dude"
|
66
70
|
end
|
71
|
+
|
72
|
+
it 'returns nil when value not present' do
|
73
|
+
properties['missing'].must_equal nil
|
74
|
+
end
|
67
75
|
end
|
68
76
|
end
|
69
77
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dot_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Eden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|