deep_hash_transformer 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deep_hash_transformer.rb +7 -5
- data/lib/deep_hash_transformer/version.rb +3 -1
- data/spec/deep_hash_transformer_spec.rb +22 -20
- data/spec/spec_helper.rb +2 -0
- metadata +35 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7f171270350f94fdce54754d2cd72e7832b50d96fd92255e7c0ccf2b4a4460b
|
4
|
+
data.tar.gz: bfbe82ac975f7a38f21a26ffd969fb226592ec67e4d54c6009213ad56883e146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c2b9b9c03df98e7407c1ff2e365b2b49a5e200380b1a3747be28d3bcdb8832be8c59c5b94db2753b93809549d7841da2bf1e0a9d6bb425c1c9f545802bea830
|
7
|
+
data.tar.gz: cab7709f4bf6dbb2a3c9d692c0d3bb4af83b4ce318a020624ad7151c7e1d71f40dde2dec2df51326d79e0f9ae7f2a97c72ba11c65c38467e3e617d26bb572d1f
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'deep_hash_transformer/version'
|
2
4
|
|
3
5
|
class DeepHashTransformer
|
4
6
|
OPS = {
|
5
|
-
dasherize:
|
6
|
-
identity:
|
7
|
-
stringify:
|
8
|
-
symbolize:
|
9
|
-
underscore: ->(val) { val.to_s.tr('-'
|
7
|
+
dasherize: ->(val) { val.to_s.tr('_', '-') },
|
8
|
+
identity: ->(val) { val },
|
9
|
+
stringify: ->(val) { val.to_s },
|
10
|
+
symbolize: ->(val) { val.to_sym },
|
11
|
+
underscore: ->(val) { val.to_s.tr('-', '_') }
|
10
12
|
}.freeze
|
11
13
|
|
12
14
|
def initialize(hash)
|
@@ -1,41 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe DeepHashTransformer do
|
2
|
-
|
3
|
-
|
4
|
+
subject do
|
5
|
+
described_class.new(
|
4
6
|
Integer => 123,
|
5
7
|
:foobar => { bar: 'bar' },
|
6
8
|
'aa_zz' => [{ 'bar' => :bar, 'a-z' => 'a-z' }]
|
7
|
-
|
9
|
+
)
|
8
10
|
end
|
9
11
|
|
10
12
|
describe '#tr with `:underscore, :symbolize`' do
|
11
|
-
subject {
|
13
|
+
subject { super().tr(:underscore, :symbolize) }
|
12
14
|
|
13
15
|
it do
|
14
|
-
|
16
|
+
expect(subject).to eq( # rubocop:disable RSpec/NamedSubject
|
15
17
|
Integer => 123,
|
16
18
|
:foobar => { bar: 'bar' },
|
17
|
-
:aa_zz
|
19
|
+
:aa_zz => [{ bar: :bar, a_z: 'a-z' }]
|
18
20
|
)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
describe '#dasherize' do
|
23
|
-
subject {
|
25
|
+
subject { super().dasherize }
|
24
26
|
|
25
27
|
it do
|
26
|
-
|
28
|
+
expect(subject).to eq( # rubocop:disable RSpec/NamedSubject
|
27
29
|
Integer => 123,
|
28
30
|
'foobar' => { 'bar' => 'bar' },
|
29
|
-
'aa-zz'
|
31
|
+
'aa-zz' => [{ 'bar' => :bar, 'a-z' => 'a-z' }]
|
30
32
|
)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
describe '#identity' do
|
35
|
-
subject {
|
37
|
+
subject { super().identity }
|
36
38
|
|
37
39
|
it do
|
38
|
-
|
40
|
+
expect(subject).to eq( # rubocop:disable RSpec/NamedSubject
|
39
41
|
Integer => 123,
|
40
42
|
:foobar => { bar: 'bar' },
|
41
43
|
'aa_zz' => [{ 'bar' => :bar, 'a-z' => 'a-z' }]
|
@@ -44,37 +46,37 @@ RSpec.describe DeepHashTransformer do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
describe '#stringify' do
|
47
|
-
subject {
|
49
|
+
subject { super().stringify }
|
48
50
|
|
49
51
|
it do
|
50
|
-
|
52
|
+
expect(subject).to eq( # rubocop:disable RSpec/NamedSubject
|
51
53
|
Integer => 123,
|
52
54
|
'foobar' => { 'bar' => 'bar' },
|
53
|
-
'aa_zz'
|
55
|
+
'aa_zz' => [{ 'bar' => :bar, 'a-z' => 'a-z' }]
|
54
56
|
)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
60
|
describe '#symbolize' do
|
59
|
-
subject {
|
61
|
+
subject { super().symbolize }
|
60
62
|
|
61
63
|
it do
|
62
|
-
|
64
|
+
expect(subject).to eq( # rubocop:disable RSpec/NamedSubject
|
63
65
|
Integer => 123,
|
64
66
|
:foobar => { bar: 'bar' },
|
65
|
-
:aa_zz
|
67
|
+
:aa_zz => [{ bar: :bar, 'a-z': 'a-z' }]
|
66
68
|
)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
70
72
|
describe '#underscore' do
|
71
|
-
subject {
|
73
|
+
subject { super().underscore }
|
72
74
|
|
73
75
|
it do
|
74
|
-
|
76
|
+
expect(subject).to eq( # rubocop:disable RSpec/NamedSubject
|
75
77
|
Integer => 123,
|
76
78
|
'foobar' => { 'bar' => 'bar' },
|
77
|
-
'aa_zz'
|
79
|
+
'aa_zz' => [{ 'bar' => :bar, 'a_z' => 'a-z' }]
|
78
80
|
)
|
79
81
|
end
|
80
82
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_hash_transformer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Spickermann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: " DeepHashTransformer helps to transform deeply nested hash structures\n"
|
70
98
|
email:
|
71
99
|
- spickermann@gmail.com
|
@@ -82,7 +110,7 @@ homepage: https://github.com/spickermann/deep_hash_transformer
|
|
82
110
|
licenses:
|
83
111
|
- MIT
|
84
112
|
metadata: {}
|
85
|
-
post_install_message:
|
113
|
+
post_install_message:
|
86
114
|
rdoc_options: []
|
87
115
|
require_paths:
|
88
116
|
- lib
|
@@ -90,16 +118,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
118
|
requirements:
|
91
119
|
- - ">="
|
92
120
|
- !ruby/object:Gem::Version
|
93
|
-
version: 2.
|
121
|
+
version: 2.5.0
|
94
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
123
|
requirements:
|
96
124
|
- - ">="
|
97
125
|
- !ruby/object:Gem::Version
|
98
126
|
version: '0'
|
99
127
|
requirements: []
|
100
|
-
|
101
|
-
|
102
|
-
signing_key:
|
128
|
+
rubygems_version: 3.2.3
|
129
|
+
signing_key:
|
103
130
|
specification_version: 4
|
104
131
|
summary: Transforms deeply nested hash structure
|
105
132
|
test_files: []
|