deep_hash_transformer 2.1.0 → 2.2.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/lib/deep_hash_transformer/blank.rb +28 -0
- data/lib/deep_hash_transformer/collection_operation.rb +29 -0
- data/lib/deep_hash_transformer/{operation.rb → element_operation.rb} +4 -4
- data/lib/deep_hash_transformer/version.rb +1 -1
- data/lib/deep_hash_transformer.rb +26 -8
- data/spec/deep_hash_transformer/blank_spec.rb +26 -0
- data/spec/deep_hash_transformer/collection_operation_spec.rb +31 -0
- data/spec/deep_hash_transformer/element_operation_spec.rb +32 -0
- data/spec/deep_hash_transformer_spec.rb +74 -25
- data/spec/spec_helper.rb +15 -9
- metadata +11 -119
- data/spec/deep_hash_transformer/operation_spec.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd3cd6700a7e51238c1c16feb30a81fb8debe53c5225401f33442ef29d771c92
|
4
|
+
data.tar.gz: 93aeb34e4a4e0bdbefa97d6d946d21fc8ab87457bd8361d992aa66399100849e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 515fe31abc501135498b1450e9f90820c7612161e643198f9276006095abc5eff05e5c54cb924c37ae4e801e078a9cf9f26ccb17900341b2b7f093e86f9d4c03
|
7
|
+
data.tar.gz: 4cb38f5bcfcf1265f77244e61c8d4b13f0d833a52b6ef4e334cbe43bbe157eeee4a3c467f5d08f45b2e738cfee936395cee3a073e79e2c9453a7ba8aef7ab001
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DeepHashTransformer
|
4
|
+
class Blank
|
5
|
+
BLANK_STRING = /\A[[:space:]]*\z/
|
6
|
+
|
7
|
+
def self.call(value)
|
8
|
+
new(value).blank?
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def blank?
|
16
|
+
return true unless value
|
17
|
+
return value.blank? if value.respond_to?(:blank?)
|
18
|
+
return BLANK_STRING.match?(value) if value.is_a?(String)
|
19
|
+
return value.empty? if value.respond_to?(:empty?)
|
20
|
+
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :value
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "blank"
|
4
|
+
|
5
|
+
class DeepHashTransformer
|
6
|
+
module CollectionOperation
|
7
|
+
class << self
|
8
|
+
def compact(val)
|
9
|
+
case val
|
10
|
+
when Array, Hash
|
11
|
+
val.compact
|
12
|
+
else
|
13
|
+
val
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def compact_blank(val)
|
18
|
+
case val
|
19
|
+
when Array
|
20
|
+
val.reject { |elem| Blank.call(elem) }
|
21
|
+
when Hash
|
22
|
+
val.reject { |_, v| Blank.call(v) }
|
23
|
+
else
|
24
|
+
val
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class DeepHashTransformer
|
4
|
-
module
|
4
|
+
module ElementOperation
|
5
5
|
class << self
|
6
6
|
def camel_case(val)
|
7
7
|
pascal_case(val)
|
@@ -10,7 +10,7 @@ class DeepHashTransformer
|
|
10
10
|
|
11
11
|
def dasherize(val)
|
12
12
|
stringify(val)
|
13
|
-
.tr(
|
13
|
+
.tr("_", "-")
|
14
14
|
end
|
15
15
|
|
16
16
|
def identity(val)
|
@@ -34,14 +34,14 @@ class DeepHashTransformer
|
|
34
34
|
|
35
35
|
def underscore(val)
|
36
36
|
stringify(val)
|
37
|
-
.tr(
|
37
|
+
.tr("-", "_")
|
38
38
|
end
|
39
39
|
|
40
40
|
def snake_case(val)
|
41
41
|
stringify(val)
|
42
42
|
.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
43
43
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
44
|
-
.tr(
|
44
|
+
.tr("-", "_")
|
45
45
|
.downcase
|
46
46
|
end
|
47
47
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "deep_hash_transformer/collection_operation"
|
4
|
+
require "deep_hash_transformer/element_operation"
|
5
|
+
require "deep_hash_transformer/version"
|
5
6
|
|
6
7
|
class DeepHashTransformer
|
7
|
-
|
8
|
+
ELEMENT_OPS = %i[
|
8
9
|
camel_case
|
9
10
|
dasherize
|
10
11
|
identity
|
@@ -15,15 +16,22 @@ class DeepHashTransformer
|
|
15
16
|
underscore
|
16
17
|
].freeze
|
17
18
|
|
19
|
+
COLLECTION_OPS = %i[
|
20
|
+
compact
|
21
|
+
compact_blank
|
22
|
+
].freeze
|
23
|
+
|
24
|
+
OPS = ELEMENT_OPS + COLLECTION_OPS
|
25
|
+
|
18
26
|
def initialize(hash)
|
19
27
|
@hash = hash
|
20
28
|
end
|
21
29
|
|
22
30
|
def tr(*ops)
|
23
|
-
|
24
|
-
if
|
31
|
+
unknown_transformations = ops.map(&:to_s) - OPS.map(&:to_s)
|
32
|
+
if unknown_transformations.any?
|
25
33
|
raise(
|
26
|
-
ArgumentError, "unknown transformation(s): #{
|
34
|
+
ArgumentError, "unknown transformation(s): #{unknown_transformations.join(",")}"
|
27
35
|
)
|
28
36
|
end
|
29
37
|
|
@@ -38,8 +46,14 @@ class DeepHashTransformer
|
|
38
46
|
|
39
47
|
attr_reader :hash
|
40
48
|
|
49
|
+
def transform_collection(collection, ops)
|
50
|
+
ops.inject(collection) do |c, op|
|
51
|
+
COLLECTION_OPS.include?(op) ? CollectionOperation.public_send(op, c) : c
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
def transform_value(value, ops)
|
42
|
-
case value
|
56
|
+
collection = case value
|
43
57
|
when Array
|
44
58
|
value.map { |e| transform_value(e, ops) }
|
45
59
|
when Hash
|
@@ -47,11 +61,15 @@ class DeepHashTransformer
|
|
47
61
|
else
|
48
62
|
value
|
49
63
|
end
|
64
|
+
|
65
|
+
transform_collection(collection, ops)
|
50
66
|
end
|
51
67
|
|
52
68
|
def transform_key(key, ops)
|
53
69
|
return key unless [String, Symbol].include?(key.class)
|
54
70
|
|
55
|
-
ops.inject(key)
|
71
|
+
ops.inject(key) do |k, op|
|
72
|
+
ELEMENT_OPS.include?(op) ? ElementOperation.public_send(op, k) : k
|
73
|
+
end
|
56
74
|
end
|
57
75
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe DeepHashTransformer::Blank do
|
4
|
+
describe ".call" do
|
5
|
+
subject { described_class.call(value) }
|
6
|
+
|
7
|
+
presents = [true, 1, 0, "any", [nil], {A: nil}]
|
8
|
+
blanks = [nil, false, "", " ", [], {}]
|
9
|
+
|
10
|
+
presents.each do |value|
|
11
|
+
context "with #{value.inspect}" do
|
12
|
+
let(:value) { value }
|
13
|
+
|
14
|
+
it { is_expected.to be false }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
blanks.each do |value|
|
19
|
+
context "with #{value.inspect}" do
|
20
|
+
let(:value) { value }
|
21
|
+
|
22
|
+
it { is_expected.to be true }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe DeepHashTransformer::CollectionOperation do
|
4
|
+
examples = [
|
5
|
+
{a: "b"}, {a: nil}, {a: " "}, [:foo], ["", nil]
|
6
|
+
]
|
7
|
+
|
8
|
+
subject do
|
9
|
+
examples.map { |value| described_class.public_send(method, value) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".compact" do
|
13
|
+
let(:method) { :compact }
|
14
|
+
|
15
|
+
expected_output = [
|
16
|
+
{a: "b"}, {}, {a: " "}, [:foo], [""]
|
17
|
+
]
|
18
|
+
|
19
|
+
it { is_expected.to eq(expected_output) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".compact_blank" do
|
23
|
+
let(:method) { :compact_blank }
|
24
|
+
|
25
|
+
expected_output = [
|
26
|
+
{a: "b"}, {}, {}, [:foo], []
|
27
|
+
]
|
28
|
+
|
29
|
+
it { is_expected.to eq(expected_output) }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe DeepHashTransformer::ElementOperation do
|
4
|
+
examples = [
|
5
|
+
:symbol, "string", "camelCase", "dashed-key", "PascalCase", "under_scored"
|
6
|
+
]
|
7
|
+
|
8
|
+
subject do
|
9
|
+
examples.map { |value| described_class.public_send(method, value) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# rubocop:disable Layout/HashAlignment, Style/SymbolArray, Style/WordArray
|
13
|
+
expected_output = {
|
14
|
+
camel_case: ["symbol", "string", "camelCase", "dashedKey", "pascalCase", "underScored"],
|
15
|
+
dasherize: ["symbol", "string", "camelCase", "dashed-key", "PascalCase", "under-scored"],
|
16
|
+
identity: [:symbol, "string", "camelCase", "dashed-key", "PascalCase", "under_scored"],
|
17
|
+
pascal_case: ["Symbol", "String", "CamelCase", "DashedKey", "PascalCase", "UnderScored"],
|
18
|
+
snake_case: ["symbol", "string", "camel_case", "dashed_key", "pascal_case", "under_scored"],
|
19
|
+
stringify: ["symbol", "string", "camelCase", "dashed-key", "PascalCase", "under_scored"],
|
20
|
+
symbolize: [:symbol, :string, :camelCase, :"dashed-key", :PascalCase, :under_scored],
|
21
|
+
underscore: ["symbol", "string", "camelCase", "dashed_key", "PascalCase", "under_scored"]
|
22
|
+
}
|
23
|
+
# rubocop:enable Layout/HashAlignment, Style/SymbolArray, Style/WordArray
|
24
|
+
|
25
|
+
DeepHashTransformer::ELEMENT_OPS.each do |method|
|
26
|
+
describe "##{method}" do
|
27
|
+
let(:method) { method }
|
28
|
+
|
29
|
+
it { is_expected.to eq(expected_output[method]) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -3,14 +3,14 @@
|
|
3
3
|
RSpec.describe DeepHashTransformer do
|
4
4
|
subject(:operation) { described_class.new(example) }
|
5
5
|
|
6
|
-
let(:example) { {
|
6
|
+
let(:example) { {foo: "bar"} }
|
7
7
|
|
8
|
-
describe
|
9
|
-
DeepHashTransformer::
|
8
|
+
describe "autogenerated methods" do
|
9
|
+
DeepHashTransformer::ELEMENT_OPS.each do |method|
|
10
10
|
describe ".#{method}" do
|
11
11
|
it "delegates to `Operation.#{method}`" do
|
12
12
|
expect(
|
13
|
-
DeepHashTransformer::
|
13
|
+
DeepHashTransformer::ElementOperation
|
14
14
|
).to receive(method).with(:foo).once # rubocop:disable RSpec/MessageSpies
|
15
15
|
|
16
16
|
operation.public_send(method)
|
@@ -19,37 +19,37 @@ RSpec.describe DeepHashTransformer do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
context
|
22
|
+
describe "#tr" do
|
23
|
+
context "with `:snake_case, :symbolize`" do
|
24
24
|
subject { super().tr(:snake_case, :symbolize) }
|
25
25
|
|
26
|
-
let(:example) { {
|
26
|
+
let(:example) { {"FooBar" => "baz"} }
|
27
27
|
|
28
|
-
it { is_expected.to eq(foo_bar:
|
28
|
+
it { is_expected.to eq(foo_bar: "baz") }
|
29
29
|
end
|
30
30
|
|
31
|
-
context
|
31
|
+
context "with an unknown transformation" do
|
32
32
|
subject(:unknown_ops) { operation.tr(:unknown) }
|
33
33
|
|
34
|
-
it
|
34
|
+
it "raise an exception" do
|
35
35
|
expect { unknown_ops }.to raise_error(ArgumentError, /unknown/)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
context
|
39
|
+
context "with a complex, nested example" do
|
40
40
|
subject { super().tr(:camel_case, :symbolize) }
|
41
41
|
|
42
42
|
let(:example) do
|
43
43
|
{
|
44
44
|
Integer => 123,
|
45
|
-
:symbol => {
|
46
|
-
|
47
|
-
|
45
|
+
:symbol => {foo_bar: "bar"},
|
46
|
+
"string" => {"foo_bar" => 123},
|
47
|
+
"nested-array" => [
|
48
48
|
{
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
"camelCased" => "camelCased",
|
50
|
+
"dashed-key" => "dashed-key",
|
51
|
+
"PascalCased" => "PascalCased",
|
52
|
+
"under_scored" => "under_scored"
|
53
53
|
}
|
54
54
|
]
|
55
55
|
}
|
@@ -58,22 +58,71 @@ RSpec.describe DeepHashTransformer do
|
|
58
58
|
it do # rubocop:disable RSpec/ExampleLength
|
59
59
|
is_expected.to eq( # rubocop:disable RSpec/ImplicitSubject
|
60
60
|
Integer => 123,
|
61
|
-
:symbol => {
|
62
|
-
:string => {
|
61
|
+
:symbol => {fooBar: "bar"},
|
62
|
+
:string => {fooBar: 123},
|
63
63
|
:nestedArray => [
|
64
64
|
{
|
65
|
-
camelCased:
|
66
|
-
dashedKey:
|
67
|
-
pascalCased:
|
68
|
-
underScored:
|
65
|
+
camelCased: "camelCased",
|
66
|
+
dashedKey: "dashed-key",
|
67
|
+
pascalCased: "PascalCased",
|
68
|
+
underScored: "under_scored"
|
69
69
|
}
|
70
70
|
]
|
71
71
|
)
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
context "with nil values" do
|
76
|
+
subject { super().tr(:compact, :stringify) }
|
77
|
+
|
78
|
+
let(:example) do
|
79
|
+
{a: {b: ["", nil, :value], c: "", d: nil, e: true, f: false, g: 123, h: [""]}}
|
80
|
+
end
|
81
|
+
|
82
|
+
it do # rubocop:disable RSpec/ExampleLength
|
83
|
+
is_expected.to eq( # rubocop:disable RSpec/ImplicitSubject
|
84
|
+
"a" => {
|
85
|
+
"b" => ["", :value],
|
86
|
+
"c" => "",
|
87
|
+
"e" => true,
|
88
|
+
"f" => false,
|
89
|
+
"g" => 123,
|
90
|
+
"h" => [""]
|
91
|
+
}
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with blank values" do
|
97
|
+
subject { super().tr(:compact_blank, :stringify) }
|
98
|
+
|
99
|
+
let(:example) do
|
100
|
+
{a: {b: ["", nil, :value], c: "", d: nil, e: true, f: false, g: 123, h: [""]}}
|
101
|
+
end
|
102
|
+
|
103
|
+
it do # rubocop:disable RSpec/ExampleLength
|
104
|
+
is_expected.to eq( # rubocop:disable RSpec/ImplicitSubject
|
105
|
+
"a" => {
|
106
|
+
"b" => [:value],
|
107
|
+
"e" => true,
|
108
|
+
"g" => 123
|
109
|
+
}
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "with deeply nested blank values" do
|
115
|
+
subject { super().tr(:compact_blank) }
|
116
|
+
|
117
|
+
let(:example) do
|
118
|
+
{a: {b: [nil, {c: nil}]}}
|
119
|
+
end
|
120
|
+
|
121
|
+
it { is_expected.to eq({}) }
|
122
|
+
end
|
74
123
|
end
|
75
124
|
|
76
|
-
it
|
125
|
+
it "has a version number" do
|
77
126
|
expect(DeepHashTransformer::VERSION).not_to be_nil
|
78
127
|
end
|
79
128
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "bundler/setup"
|
4
|
+
require "deep_hash_transformer"
|
5
|
+
require "deep_hash_transformer/blank"
|
6
|
+
require "deep_hash_transformer/collection_operation"
|
7
|
+
require "deep_hash_transformer/element_operation"
|
8
|
+
|
9
|
+
require "simplecov"
|
7
10
|
|
8
11
|
SimpleCov.start do
|
9
|
-
if ENV[
|
10
|
-
require
|
12
|
+
if ENV["CI"]
|
13
|
+
require "simplecov_json_formatter"
|
14
|
+
require "simplecov-lcov"
|
11
15
|
|
12
16
|
SimpleCov::Formatter::LcovFormatter.config do |c|
|
13
17
|
c.report_with_single_file = true
|
14
|
-
c.single_report_path =
|
18
|
+
c.single_report_path = "coverage/lcov.info"
|
15
19
|
end
|
16
20
|
|
17
|
-
formatter SimpleCov::Formatter::
|
21
|
+
formatter SimpleCov::Formatter::MultiFormatter.new [
|
22
|
+
SimpleCov::Formatter::JSONFormatter, SimpleCov::Formatter::LcovFormatter
|
23
|
+
]
|
18
24
|
end
|
19
25
|
|
20
26
|
add_filter %w[version.rb initializer.rb]
|
@@ -22,7 +28,7 @@ end
|
|
22
28
|
|
23
29
|
RSpec.configure do |config|
|
24
30
|
# Enable flags like --only-failures and --next-failure
|
25
|
-
config.example_status_persistence_file_path =
|
31
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
26
32
|
|
27
33
|
config.expect_with :rspec do |c|
|
28
34
|
c.syntax = :expect
|
metadata
CHANGED
@@ -1,127 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_hash_transformer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Spickermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rubocop
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop-performance
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-rake
|
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'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov-lcov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
11
|
+
date: 2023-12-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
125
13
|
description: " DeepHashTransformer helps to transform keys in deeply nested hash
|
126
14
|
structures\n"
|
127
15
|
email:
|
@@ -132,9 +20,13 @@ extra_rdoc_files: []
|
|
132
20
|
files:
|
133
21
|
- MIT-LICENSE
|
134
22
|
- lib/deep_hash_transformer.rb
|
135
|
-
- lib/deep_hash_transformer/
|
23
|
+
- lib/deep_hash_transformer/blank.rb
|
24
|
+
- lib/deep_hash_transformer/collection_operation.rb
|
25
|
+
- lib/deep_hash_transformer/element_operation.rb
|
136
26
|
- lib/deep_hash_transformer/version.rb
|
137
|
-
- spec/deep_hash_transformer/
|
27
|
+
- spec/deep_hash_transformer/blank_spec.rb
|
28
|
+
- spec/deep_hash_transformer/collection_operation_spec.rb
|
29
|
+
- spec/deep_hash_transformer/element_operation_spec.rb
|
138
30
|
- spec/deep_hash_transformer_spec.rb
|
139
31
|
- spec/spec_helper.rb
|
140
32
|
homepage: https://github.com/spickermann/deep_hash_transformer
|
@@ -150,14 +42,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
42
|
requirements:
|
151
43
|
- - ">="
|
152
44
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
45
|
+
version: 3.0.0
|
154
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
47
|
requirements:
|
156
48
|
- - ">="
|
157
49
|
- !ruby/object:Gem::Version
|
158
50
|
version: '0'
|
159
51
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
52
|
+
rubygems_version: 3.5.3
|
161
53
|
signing_key:
|
162
54
|
specification_version: 4
|
163
55
|
summary: Transforms deeply nested hash structure
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe DeepHashTransformer::Operation do
|
4
|
-
examples = [
|
5
|
-
:symbol, 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under_scored'
|
6
|
-
]
|
7
|
-
|
8
|
-
subject do
|
9
|
-
examples.map { |value| described_class.public_send(method, value) }
|
10
|
-
end
|
11
|
-
|
12
|
-
# rubocop:disable Layout/HashAlignment, Style/SymbolArray, Style/WordArray
|
13
|
-
expected_output = {
|
14
|
-
camel_case: ['symbol', 'string', 'camelCase', 'dashedKey', 'pascalCase', 'underScored'],
|
15
|
-
dasherize: ['symbol', 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under-scored'],
|
16
|
-
identity: [:symbol, 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under_scored'],
|
17
|
-
pascal_case: ['Symbol', 'String', 'CamelCase', 'DashedKey', 'PascalCase', 'UnderScored'],
|
18
|
-
snake_case: ['symbol', 'string', 'camel_case', 'dashed_key', 'pascal_case', 'under_scored'],
|
19
|
-
stringify: ['symbol', 'string', 'camelCase', 'dashed-key', 'PascalCase', 'under_scored'],
|
20
|
-
symbolize: [:symbol, :string, :camelCase, :'dashed-key', :PascalCase, :under_scored],
|
21
|
-
underscore: ['symbol', 'string', 'camelCase', 'dashed_key', 'PascalCase', 'under_scored']
|
22
|
-
}
|
23
|
-
# rubocop:enable Layout/HashAlignment, Style/SymbolArray, Style/WordArray
|
24
|
-
|
25
|
-
DeepHashTransformer::OPS.each do |method|
|
26
|
-
describe "##{method}" do
|
27
|
-
let(:method) { method }
|
28
|
-
|
29
|
-
it { is_expected.to eq(expected_output[method]) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|