hash-pipe 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/hash-pipe.gemspec +1 -1
- data/lib/hash-pipe.rb +1 -1
- data/lib/hash_pipe/nested_values.rb +3 -10
- data/spec/hash-pipe/nested_keys_spec.rb +18 -0
- 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: 5a8f375ae022cfd53366c69371f5b15bb2d661c9
|
4
|
+
data.tar.gz: 9f7633a90fbdf61bab4a52d6238d556e46aa7d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be548be7aca55c7692a2b6a4841eb58444f13d46107cc97ddf6dff86a40a563ffef1ab839989830576bbd6a5bdd8a228a9aedf388d679be0b4e397688aa42b5a
|
7
|
+
data.tar.gz: ffaffb69d2f71db76825d41513c73e9d699438e2361a72d67a96cd0f6f69f4e86fe0ba85f711a4ae5de32eb6397fb31c99f34b80aa6b59a29e4e69f44c2494f4
|
data/Gemfile.lock
CHANGED
data/hash-pipe.gemspec
CHANGED
data/lib/hash-pipe.rb
CHANGED
@@ -1,21 +1,14 @@
|
|
1
1
|
Hash.class_eval do
|
2
2
|
|
3
3
|
def nested_fetch(path)
|
4
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|