hash-pipe 0.4.1 → 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 +4 -4
- data/.travis.yml +3 -5
- data/Gemfile.lock +2 -2
- data/hash-pipe.gemspec +1 -1
- data/lib/hash-pipe.rb +2 -0
- data/lib/hash_pipe/array_conversion.rb +25 -0
- data/spec/hash-pipe/array_conversion_spec.rb +30 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f00540352b758407a52def4a4a3d8f27d5d3f8a
|
4
|
+
data.tar.gz: 01967554191ae3d545ea1c3ea66502e0f2d0c668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4116a3c4ec2f9ada85f06c0f1fa5b57f11093697831347ee06d69aeafbc21e185c4bb70ce663a4081875257deb126ce686c9551f9a2543baae7ad528b8310947
|
7
|
+
data.tar.gz: 7b3593c9319e7bafbe3b452a4a2f2d18d1e35eddcd0a20e5f528f63f1527559a547d935bc1ad8c51644361652e328f6dcb4b1660b6a13f6beda2f1a2ec6a6649
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hash-pipe (0.
|
4
|
+
hash-pipe (0.5.0)
|
5
5
|
activesupport (>= 4.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.0.0)
|
10
|
+
activesupport (5.0.0.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (~> 0.7)
|
13
13
|
minitest (~> 5.1)
|
data/hash-pipe.gemspec
CHANGED
data/lib/hash-pipe.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
Array.class_eval do
|
2
|
+
# Creates a deep object out of an array
|
3
|
+
#
|
4
|
+
# hash = ["errors", "something", "somethingElse", "password", ["VALIDATION_STATE_PASSWORD"]]
|
5
|
+
#
|
6
|
+
# Could be turned into an object usign this
|
7
|
+
#
|
8
|
+
# hash.nest
|
9
|
+
#
|
10
|
+
# And the end result would look like this:
|
11
|
+
#
|
12
|
+
# "errors" => {
|
13
|
+
# "something" => {
|
14
|
+
# "somethingElse" => {
|
15
|
+
# "password" => ["VALIDATION_STATE_PASSWORD"]
|
16
|
+
# }
|
17
|
+
# }
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
def to_nested_hash
|
21
|
+
raise ArgumentError, "Values in array can't be nil" if any? &:nil?
|
22
|
+
reverse.inject { |hash, key| {key => hash} }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'next' do
|
4
|
+
it 'should nest an array' do
|
5
|
+
['hello', 'world'].to_nested_hash.should eq 'hello' => 'world'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should handle just one element in array' do
|
9
|
+
["hello"].to_nested_hash.should eq "hello"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should handle an empty array' do
|
13
|
+
[].to_nested_hash.should eq nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should throw error on nil values' do
|
17
|
+
expect{[nil, 'hello', 'world'].to_nested_hash}.to raise_error ArgumentError
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should nest longer arrays' do
|
21
|
+
['errors', 'something', 'somethingElse', 'password', ['VALIDATION_STATE_PASSWORD']].to_nested_hash.should eq 'errors' => {
|
22
|
+
'something' => {
|
23
|
+
'somethingElse' => {
|
24
|
+
'password' => ['VALIDATION_STATE_PASSWORD']
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -67,10 +67,12 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- hash-pipe.gemspec
|
69
69
|
- lib/hash-pipe.rb
|
70
|
+
- lib/hash_pipe/array_conversion.rb
|
70
71
|
- lib/hash_pipe/flattening.rb
|
71
72
|
- lib/hash_pipe/key_conversion.rb
|
72
73
|
- lib/hash_pipe/nested_values.rb
|
73
74
|
- lib/hash_pipe/value_checks.rb
|
75
|
+
- spec/hash-pipe/array_conversion_spec.rb
|
74
76
|
- spec/hash-pipe/flattening_spec.rb
|
75
77
|
- spec/hash-pipe/key_conversion_spec.rb
|
76
78
|
- spec/hash-pipe/nested_keys_spec.rb
|
@@ -101,6 +103,7 @@ signing_key:
|
|
101
103
|
specification_version: 4
|
102
104
|
summary: A small collection of useful hash extensions
|
103
105
|
test_files:
|
106
|
+
- spec/hash-pipe/array_conversion_spec.rb
|
104
107
|
- spec/hash-pipe/flattening_spec.rb
|
105
108
|
- spec/hash-pipe/key_conversion_spec.rb
|
106
109
|
- spec/hash-pipe/nested_keys_spec.rb
|