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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6470ab371c8535a3339aaed17e5bac24ddba862b
4
- data.tar.gz: e9f5dcb591ceef47f6cbbbb9b20ef03e74eec2d0
3
+ metadata.gz: 96f2a20d001035964bad9b1410aed024647538eb
4
+ data.tar.gz: ef40f1c6b2c5d64a555754b94723b23a847063c4
5
5
  SHA512:
6
- metadata.gz: 7bbae3c691aa833263069eba3384c5bca5291dbecb9759a05dab2251bc6647c56b6c3b4cc435ce6b621475087bfbd8e94623216bdb0611d5550b1c8adc42886f
7
- data.tar.gz: 18c7a8704cb1dde10320464d70acec2c7eba1095d18c51e9acddb8a05dd37c1e06ae517539699dce370a114fdf8c4c38a5224462c14b2d53541a496e80643c1c
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`.
@@ -40,14 +40,15 @@ module DotHash
40
40
  end
41
41
 
42
42
  def execute(key, *args, &block)
43
- value = get_value(key)
44
- return value unless value.nil?
45
- hash.public_send(key, *args, &block)
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[key]
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
@@ -1,3 +1,3 @@
1
1
  module DotHash
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.9"
3
3
  end
@@ -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.7
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-02-20 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake