hash-pipe 0.1.0 → 0.1.1

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: 0c23ebd04fd2a64e16045d5b42f8b39c606a5f59
4
- data.tar.gz: 69519dcdf75138afdc7d2291b28c0297e31d4f46
3
+ metadata.gz: 5a8f375ae022cfd53366c69371f5b15bb2d661c9
4
+ data.tar.gz: 9f7633a90fbdf61bab4a52d6238d556e46aa7d28
5
5
  SHA512:
6
- metadata.gz: a4d85d61874cd686a61ed0a770697e97be378a20cf75e3af61bd4c7d9dc8325b2d184097f4aedb8335a0f1c2da605f2416171ec984b264ad03fbe38c32449d4f
7
- data.tar.gz: c17f32ded2be8f0a5e6824d46a21b561c1378151e2cf7a8a316fa0fa4e1975d8beb51c838716833d5d063143d4a00b41a37c4ce745d44a1f6b14ddd71ca09a57
6
+ metadata.gz: be548be7aca55c7692a2b6a4841eb58444f13d46107cc97ddf6dff86a40a563ffef1ab839989830576bbd6a5bdd8a228a9aedf388d679be0b4e397688aa42b5a
7
+ data.tar.gz: ffaffb69d2f71db76825d41513c73e9d699438e2361a72d67a96cd0f6f69f4e86fe0ba85f711a4ae5de32eb6397fb31c99f34b80aa6b59a29e4e69f44c2494f4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hash-pipe (0.1.0)
4
+ hash-pipe (0.1.1)
5
5
  activesupport (~> 4.1)
6
6
 
7
7
  GEM
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "hash-pipe"
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
  s.authors = ["Damien Timewell"]
7
7
  s.email = ["mail@damientimewell.com"]
8
8
  s.licenses = ['MIT']
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext'
1
+ require 'active_support/all'
2
2
 
3
3
  require 'hash_pipe/key_conversion'
4
4
  require 'hash_pipe/value_checks'
@@ -1,21 +1,14 @@
1
1
  Hash.class_eval do
2
2
 
3
3
  def nested_fetch(path)
4
- path = Array(path)
5
-
6
- value = self
7
- until path.empty?
8
- value = value[path.shift]
9
- end
10
-
11
- value
4
+ Array(path).dup.reduce(self) { |current, key| current[key] }
12
5
  end
13
6
 
14
7
  def nested_delete(path)
15
- path = Array(path)
8
+ path = Array(path).dup
16
9
  last_path_element = path.pop
17
10
 
18
- self.nested_fetch(path).delete last_path_element
11
+ nested_fetch(path).delete last_path_element
19
12
  end
20
13
 
21
14
  end
@@ -33,4 +33,22 @@ describe 'nested_keys' do
33
33
  hash['email'].should be_nil
34
34
  end
35
35
 
36
+ it 'should not change path array input data on fetch' do
37
+ hash = { 'bank' => { 'code' => 2 } }
38
+ path = ['bank', 'code']
39
+
40
+ hash.nested_fetch path
41
+
42
+ path.should eq ['bank', 'code']
43
+ end
44
+
45
+ it 'should not change path array input data on delete' do
46
+ hash = { 'bank' => { 'code' => 2 } }
47
+ path = ['bank', 'code']
48
+
49
+ hash.nested_delete path
50
+
51
+ path.should eq ['bank', 'code']
52
+ end
53
+
36
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport