hash_path 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efc30720d5e9dc46735cdbcdca64437b58a0e442
4
- data.tar.gz: 5de1e070a617786d9717242cb421a993afca0341
3
+ metadata.gz: 41873ea7e48e65009bc87fd7a332086b168ba612
4
+ data.tar.gz: aee0abeeb18db90fe34ffb138d45fdd92ed12844
5
5
  SHA512:
6
- metadata.gz: 9b99483587f78bf847bd8ac51cbb38951fecfe9ba73679e37d3bc39341657904d63e0432daf3f1d6481695e0eb91f0658768232cb71e45e7f993401506efecde
7
- data.tar.gz: 997d8a91955d890b3657c405c404fd3c60781f1fc886ed3c0e3bfcea343a55be0eca19bca7ae5ea9a4e403279867f1216df8c8326bae176a69cac2c93c7dafc4
6
+ metadata.gz: 1b87e891baa0ef21473bbcadf5cb1d49b76a5e6ca5d0c1e9bc280510e8c66423cd5bbc7d661f0f427abe8caff25cde9bb0d3f8c2d982a39809777d6d818c33ef
7
+ data.tar.gz: 12801e82c63f51e9b5a9614393784f71c026cd2589a2de49e561abdb252137868f478a090add7592b7caa62f4eba9bff52febba518c7bc21add8e4e528e20900
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ## 0.5.0
4
+ ### 2014-12-17
5
+
6
+ - Nil now responds to hashpath methods to prevent trys everywhere
7
+
3
8
  ## 0.4.0
4
9
  ### 2014-11-25
5
10
 
@@ -2,6 +2,22 @@ require "hash_path/version"
2
2
  module HashPath
3
3
  class PathNotFound < StandardError; end
4
4
 
5
+ module NilPath
6
+ def at_path(path)
7
+ nil
8
+ end
9
+
10
+ def at_path!(path)
11
+ raise PathNotFound, path
12
+ end
13
+
14
+ def flatten_key_paths(*)
15
+ {}
16
+ end
17
+ end
18
+
19
+
20
+
5
21
  DELIMITER = '.'
6
22
 
7
23
  # Looks up the path provided
@@ -70,6 +86,11 @@ module HashPath
70
86
  end
71
87
  end
72
88
 
89
+
73
90
  class Hash
74
91
  include HashPath
75
92
  end
93
+
94
+ class NilClass
95
+ include HashPath::NilPath
96
+ end
@@ -1,3 +1,3 @@
1
1
  module HashPath
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -9,9 +9,19 @@ RSpec.describe HashPath do
9
9
  it 'returns a value if it is found' do
10
10
  expect({foo: {bar: 5}}.at_path('foo.bar')).to eq(5)
11
11
  end
12
+
13
+ it 'returns nil if the starting object is nil' do
14
+ expect(nil.at_path('foo')).to eq(nil)
15
+ end
12
16
  end
13
17
 
14
18
  describe '#at_path!' do
19
+ it 'raises when nil' do
20
+ expect {
21
+ nil.at_path!('foo')
22
+ }.to raise_error(HashPath::PathNotFound)
23
+ end
24
+
15
25
  it 'looks up a key given by a string' do
16
26
  expect({'foo' => 5}.at_path!('foo')).to eq(5)
17
27
  end
@@ -77,6 +87,10 @@ RSpec.describe HashPath do
77
87
  it 'un-nests hashes' do
78
88
  expect({a: 5, b: {c: 7}}.flatten_key_paths).to eq({'a' => 5, 'b.c' => 7})
79
89
  end
90
+
91
+ it 'returns an empty hash for nil' do
92
+ expect(nil.flatten_key_paths).to eq({})
93
+ end
80
94
  end
81
95
 
82
96
  describe 'HashPath::VERSION' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Neighman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec