hash-pipe 0.4.1 → 0.5.0

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: 125cc0051bce42e5e4801ad26660318d574ee162
4
- data.tar.gz: 64b636b85bca36ae2e2225cd074f11fcc2f759a0
3
+ metadata.gz: 0f00540352b758407a52def4a4a3d8f27d5d3f8a
4
+ data.tar.gz: 01967554191ae3d545ea1c3ea66502e0f2d0c668
5
5
  SHA512:
6
- metadata.gz: c3d92f08f72bb917fafcf10164d78b59a209df8e0320e9828ef0e60bb3038bdd4a471f4a4f71f7bf723c624065a1d92dae7b54eb52469689e9a27332b7b391df
7
- data.tar.gz: d8b3882bedea744c1e210005c3e16aec46cb325069bb6d58c52556a7461538d9172f3f7a5d7c65915b059427eb0674d646823dc45a47e0d39748cd41f19e3ecd
6
+ metadata.gz: 4116a3c4ec2f9ada85f06c0f1fa5b57f11093697831347ee06d69aeafbc21e185c4bb70ce663a4081875257deb126ce686c9551f9a2543baae7ad528b8310947
7
+ data.tar.gz: 7b3593c9319e7bafbe3b452a4a2f2d18d1e35eddcd0a20e5f528f63f1527559a547d935bc1ad8c51644361652e328f6dcb4b1660b6a13f6beda2f1a2ec6a6649
@@ -1,7 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
6
- - 2.1.0
7
- script: bundle exec rspec spec
3
+ - 2.2.5
4
+ - 2.3.1
5
+ script: bundle exec rspec spec
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hash-pipe (0.4.1)
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)
@@ -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.4.1"
5
+ s.version = "0.5.0"
6
6
  s.authors = ["Damien Timewell"]
7
7
  s.email = ["mail@damientimewell.com"]
8
8
  s.licenses = ['MIT']
@@ -4,3 +4,5 @@ require 'hash_pipe/key_conversion'
4
4
  require 'hash_pipe/value_checks'
5
5
  require 'hash_pipe/nested_values'
6
6
  require 'hash_pipe/flattening'
7
+ require 'hash_pipe/array_conversion'
8
+
@@ -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.1
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 00:00:00.000000000 Z
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