darthjee-core_ext 1.5.6 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -0
  3. data/.rubocop.yml +17 -0
  4. data/.rubocop_todo.yml +12 -0
  5. data/Gemfile +2 -1
  6. data/Rakefile +2 -0
  7. data/core_ext.gemspec +6 -3
  8. data/lib/darthjee/core_ext/array/hash_builder.rb +21 -13
  9. data/lib/darthjee/core_ext/array.rb +4 -2
  10. data/lib/darthjee/core_ext/date.rb +2 -0
  11. data/lib/darthjee/core_ext/enumerable.rb +5 -3
  12. data/lib/darthjee/core_ext/hash/chain_fetcher.rb +33 -0
  13. data/lib/darthjee/core_ext/hash/deep_hash_constructor.rb +62 -60
  14. data/lib/darthjee/core_ext/hash/key_changer.rb +64 -54
  15. data/lib/darthjee/core_ext/hash/keys_sorter.rb +31 -0
  16. data/lib/darthjee/core_ext/hash/squasher.rb +31 -0
  17. data/lib/darthjee/core_ext/hash/to_hash_mapper.rb +21 -0
  18. data/lib/darthjee/core_ext/hash/value_changer.rb +48 -44
  19. data/lib/darthjee/core_ext/hash.rb +28 -58
  20. data/lib/darthjee/core_ext/math.rb +4 -2
  21. data/lib/darthjee/core_ext/numeric.rb +5 -3
  22. data/lib/darthjee/core_ext/object/default_value.rb +2 -1
  23. data/lib/darthjee/core_ext/object.rb +2 -0
  24. data/lib/darthjee/core_ext/symbol.rb +2 -0
  25. data/lib/darthjee/core_ext/time.rb +2 -0
  26. data/lib/darthjee/core_ext/version.rb +3 -1
  27. data/lib/darthjee/core_ext.rb +2 -0
  28. data/lib/darthjee.rb +2 -1
  29. data/spec/lib/array_spec.rb +27 -19
  30. data/spec/lib/date_spec.rb +2 -0
  31. data/spec/lib/enumerable_spec.rb +10 -8
  32. data/spec/lib/hash/chain_fetcher_spec.rb +11 -0
  33. data/spec/lib/hash/deep_hash_constructor_spec.rb +3 -1
  34. data/spec/lib/hash/key_changer_spec.rb +19 -5
  35. data/spec/lib/hash/keys_sorter_spec.rb +10 -0
  36. data/spec/lib/hash/squasher_spec.rb +9 -0
  37. data/spec/lib/hash/to_hash_mapper_spec.rb +10 -0
  38. data/spec/lib/hash_spec.rb +16 -46
  39. data/spec/lib/math_spec.rb +2 -0
  40. data/spec/lib/numeric_spec.rb +2 -0
  41. data/spec/lib/object/default_value_spe.rb +2 -0
  42. data/spec/lib/object_spec.rb +2 -0
  43. data/spec/lib/symbol_spec.rb +2 -0
  44. data/spec/lib/time_spec.rb +2 -0
  45. data/spec/spec_helper.rb +2 -1
  46. data/spec/support/models/default_value.rb +2 -0
  47. data/spec/support/models/hash/value_changer/dummy.rb +19 -13
  48. data/spec/support/models/hash/value_changer/dummy_iteractor.rb +13 -8
  49. data/spec/support/shared_examples/{array_random.rb → array/array_random.rb} +5 -2
  50. data/spec/support/shared_examples/clean.rb +14 -2
  51. data/spec/support/shared_examples/date.rb +2 -0
  52. data/spec/support/shared_examples/expected.rb +2 -1
  53. data/spec/support/shared_examples/{chain_fetch.rb → hash/chain_fetch.rb} +9 -7
  54. data/spec/support/shared_examples/{chain_hash_keys_changer.rb → hash/chain_hash_keys_changer.rb} +14 -11
  55. data/spec/support/shared_examples/{hash_keys_changer.rb → hash/hash_keys_changer.rb} +7 -5
  56. data/spec/support/shared_examples/hash/hash_squasher.rb +23 -0
  57. data/spec/support/shared_examples/{hash_transpose.rb → hash/hash_transpose.rb} +8 -6
  58. data/spec/support/shared_examples/hash/keys_appender.rb +69 -0
  59. data/spec/support/shared_examples/{keys_camelizer.rb → hash/keys_camelizer.rb} +6 -4
  60. data/spec/support/shared_examples/hash/keys_sorter.rb +67 -0
  61. data/spec/support/shared_examples/{keys_underscorer.rb → hash/keys_underscorer.rb} +4 -3
  62. data/spec/support/shared_examples/{map_to_hash.rb → hash/map_to_hash.rb} +16 -16
  63. data/spec/support/shared_examples/{remap.rb → hash/remap.rb} +16 -13
  64. data/spec/support/shared_examples/hash/value_changer.rb +192 -0
  65. metadata +76 -30
  66. data/circle.yml +0 -10
  67. data/spec/support/shared_examples/keys_appender.rb +0 -43
  68. data/spec/support/shared_examples/value_changer.rb +0 -147
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_examples 'a class with a keys sort method' do
4
+ describe '#sort_keys' do
5
+ let(:options) { {} }
6
+
7
+ context 'when keys are symbols' do
8
+ let(:hash) { { b: 1, a: 2 } }
9
+
10
+ it 'sorts keys as symbols' do
11
+ expect(result).to eq(a: 2, b: 1)
12
+ end
13
+ end
14
+
15
+ context 'when keys are strings' do
16
+ let(:hash) { { 'b' => 1, 'a' => 2 } }
17
+
18
+ it 'sorts keys as string' do
19
+ expect(result).to eq('a' => 2, 'b' => 1)
20
+ end
21
+ end
22
+
23
+ context 'when there is a nested hash' do
24
+ let(:hash) { { b: 1, a: { d: 3, c: 4 } } }
25
+
26
+ context 'and no option is given' do
27
+ it 'sorts keys recursively' do
28
+ expect(result).to eq(a: { c: 4, d: 3 }, b: 1)
29
+ end
30
+ end
31
+
32
+ context 'and recursive option is given' do
33
+ let(:options) { { recursive: true } }
34
+
35
+ it 'sorts keys recursively when argumen is passed' do
36
+ expect(result).to eq(a: { c: 4, d: 3 }, b: 1)
37
+ end
38
+ end
39
+
40
+ context 'and no recursive option is given' do
41
+ let(:options) { { recursive: false } }
42
+
43
+ it 'does not sorts keys recursively when argumen is passed' do
44
+ expect(result).to eq(a: { d: 3, c: 4 }, b: 1)
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'when it is deep nestled' do
50
+ let(:hash) { { b: 1, a: { d: 2, c: { e: 3, f: 4 } } } }
51
+
52
+ it 'sort recursevely on many levels' do
53
+ expected = { a: { c: { f: 4, e: 3 }, d: 2 }, b: 1 }
54
+ expect(hash.sort_keys(recursive: true)).to eq(expected)
55
+ end
56
+ end
57
+
58
+ context 'when it has a nestled array' do
59
+ let(:hash) { { b: 1, a: { d: 2, c: [{ e: 3, f: 4 }] } } }
60
+
61
+ it 'applies to arrays as well' do
62
+ expected = { a: { c: [{ f: 4, e: 3 }], d: 2 }, b: 1 }
63
+ expect(hash.sort_keys(recursive: true)).to eq(expected)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples 'a class with underscore_keys method basic' do |method|
2
4
  describe :underscore_keys do
3
5
  let(:expected) { { input_key: 'value' } }
@@ -65,7 +67,7 @@ shared_examples 'a class with underscore_keys! method' do
65
67
  it_behaves_like 'a class with underscore_keys method basic', :underscore_keys!
66
68
 
67
69
  it 'changes original hash' do
68
- expect { hash.underscore_keys! }.to change { hash }
70
+ expect { hash.underscore_keys! }.to(change { hash })
69
71
  end
70
72
  end
71
73
 
@@ -76,7 +78,6 @@ shared_examples 'a class with underscore_keys method' do
76
78
  it_behaves_like 'a class with underscore_keys! method'
77
79
 
78
80
  it 'does not change original hash' do
79
- expect { hash.underscore_keys }.not_to change { hash }
81
+ expect { hash.underscore_keys }.not_to(change { hash })
80
82
  end
81
83
  end
82
-
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples 'an array with map_to_hash method' do
2
4
  describe '#map_to_hash' do
3
- let(:subject) { %w(word1 wooord2) }
4
- let(:mapping_block) { proc{ |word| word.length } }
5
+ let(:subject) { %w[word1 wooord2] }
6
+ let(:mapping_block) { proc { |word| word.length } }
5
7
  let(:mapped) { subject.map_to_hash(&mapping_block) }
6
8
  let(:expected) { { 'word1' => 5, 'wooord2' => 7 } }
7
9
 
@@ -20,10 +22,9 @@ shared_examples 'an array with map_to_hash method' do
20
22
  end
21
23
 
22
24
  context 'whe subject is an array' do
23
- let(:subject) { [%w(w1), %w(w2 w3)] }
25
+ let(:subject) { [%w[w1], %w[w2 w3]] }
24
26
  let(:mapped) { subject.map_to_hash(&mapping_block) }
25
- let(:expected) { { %w(w1) => 1, %w(w2 w3) => 2 } }
26
-
27
+ let(:expected) { { %w[w1] => 1, %w[w2 w3] => 2 } }
27
28
 
28
29
  it 'has the original array as keys' do
29
30
  expect(mapped.keys).to eq(subject)
@@ -42,23 +43,22 @@ end
42
43
 
43
44
  shared_examples 'a hash with map_to_hash method' do
44
45
  describe '#map_to_hash' do
45
- let(:subject) { { a: 1, b: 2 } }
46
- let(:mapping_block) { proc{ |k, v| "#{k}_#{v}" } }
47
- let(:mapped) { subject.map_to_hash(&mapping_block) }
46
+ let(:hash) { { a: 1, b: 2 } }
47
+ let(:mapping_block) { proc { |k, v| "#{k}_#{v}" } }
48
48
  let(:expected) { { a: 'a_1', b: 'b_2' } }
49
49
 
50
50
  it { expect(mapped).to be_a(Hash) }
51
51
 
52
52
  it do
53
- expect { subject.map_to_hash(&mapping_block) }.not_to change { subject }
53
+ expect { mapped }.not_to(change { hash })
54
54
  end
55
55
 
56
56
  it 'has the original keys as keys' do
57
- expect(mapped.keys).to eq(subject.keys)
57
+ expect(mapped.keys).to eq(hash.keys)
58
58
  end
59
59
 
60
60
  it 'has the mapped values as values' do
61
- expect(mapped.values).to eq(subject.map(&mapping_block))
61
+ expect(mapped.values).to eq(hash.map(&mapping_block))
62
62
  end
63
63
 
64
64
  it 'correctly map keys to value' do
@@ -66,16 +66,16 @@ shared_examples 'a hash with map_to_hash method' do
66
66
  end
67
67
 
68
68
  context 'when hash uses arrays for keys' do
69
- let(:subject) { { [:a, :b] => 1, [:c, :d] => 2 } }
70
- let(:mapping_block) { proc{ |k, v| "#{k.join('_')}_#{v}" } }
71
- let(:expected) { { [:a, :b]=> 'a_b_1', [:c, :d] => 'c_d_2' } }
69
+ let(:hash) { { %i[a b] => 1, %i[c d] => 2 } }
70
+ let(:mapping_block) { proc { |k, v| "#{k.join('_')}_#{v}" } }
71
+ let(:expected) { { %i[a b] => 'a_b_1', %i[c d] => 'c_d_2' } }
72
72
 
73
73
  it 'has the original keys as keys' do
74
- expect(mapped.keys).to eq(subject.keys)
74
+ expect(mapped.keys).to eq(hash.keys)
75
75
  end
76
76
 
77
77
  it 'has the mapped values as values' do
78
- expect(mapped.values).to eq(subject.map(&mapping_block))
78
+ expect(mapped.values).to eq(hash.map(&mapping_block))
79
79
  end
80
80
 
81
81
  it 'correctly map keys to value' do
@@ -1,25 +1,28 @@
1
- shared_examples 'a class with remap method' do
2
- let(:subject) { { a: 1, b: 2 } }
1
+ # frozen_string_literal: true
3
2
 
4
- describe :remap_keys do
5
- it_behaves_like 'a method that remaps the keys', :remap_keys
3
+ shared_examples 'a class with remap method' do
4
+ subject { hash }
6
5
 
7
- it 'does not change the original hash' do
8
- expect { subject.remap_keys(a: :e) }.not_to change { subject }
6
+ describe '#remap_keys' do
7
+ it_behaves_like 'a method that remaps the keys', :remap_keys do
8
+ it 'does not change the original hash' do
9
+ expect { result }.not_to(change { hash })
10
+ end
9
11
  end
10
12
  end
11
13
 
12
- describe :remap_keys! do
13
- it_behaves_like 'a method that remaps the keys', :remap_keys!
14
-
15
- it 'changes the original hash' do
16
- expect { subject.remap_keys!(a: :e) }.to change { subject }
14
+ describe '#remap_keys!' do
15
+ it_behaves_like 'a method that remaps the keys', :remap_keys! do
16
+ it 'changes the original hash' do
17
+ expect { result }.to(change { hash })
18
+ end
17
19
  end
18
20
  end
19
-
20
21
  end
21
22
 
22
23
  shared_examples 'a method that remaps the keys' do |method|
24
+ let(:hash) { { a: 1, b: 2 } }
25
+ let(:remap) { { a: :e } }
23
26
  let(:result) { subject.public_send(method, remap) }
24
27
 
25
28
  context 'when remap and hash keys match' do
@@ -78,7 +81,7 @@ shared_examples 'a method that remaps the keys' do |method|
78
81
  end
79
82
 
80
83
  context 'and the original key is an string' do
81
- let(:subject) { { 'a' => 1, 'b' => 2 } }
84
+ let(:hash) { { 'a' => 1, 'b' => 2 } }
82
85
  let(:remap) { { 'a' => :a } }
83
86
 
84
87
  it 'does not remap the keys' do
@@ -0,0 +1,192 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_examples 'a class with change_values method' do
4
+ let(:subject) { { a: 1, b: 2, c: { d: 3, e: 4 } } }
5
+ let(:inner_hash) { subject[:c] }
6
+
7
+ describe :change_values do
8
+ it_behaves_like 'a method that change the hash values', :change_values
9
+
10
+ it 'does not change original hash' do
11
+ expect do
12
+ subject.change_values { |value| value + 1 }
13
+ end.not_to(change { subject })
14
+ end
15
+
16
+ it 'does not change original hash' do
17
+ expect do
18
+ subject.change_values { |value| value + 1 }
19
+ end.not_to(change { inner_hash })
20
+ end
21
+
22
+ context 'when using an array' do
23
+ let(:subject) { { a: [{ b: 1 }] } }
24
+ let(:inner_array) { subject[:a] }
25
+
26
+ it 'does not change original hash' do
27
+ expect do
28
+ subject.change_values { |value| value + 1 }
29
+ end.not_to(change { inner_array })
30
+ end
31
+ end
32
+ end
33
+
34
+ describe :change_values! do
35
+ it_behaves_like 'a method that change the hash values', :change_values!
36
+
37
+ it 'changes original hash' do
38
+ expect do
39
+ subject.change_values! { |value| value + 1 }
40
+ end.to(change { subject })
41
+ end
42
+
43
+ it 'changes original hash' do
44
+ expect do
45
+ subject.change_values! { |value| value + 1 }
46
+ end.to(change { inner_hash })
47
+ end
48
+
49
+ context 'when using an array' do
50
+ let(:subject) { { a: [{ b: 1 }] } }
51
+ let(:inner_array) { subject[:a] }
52
+
53
+ it 'changes original hash' do
54
+ expect do
55
+ subject.change_values! { |value| value + 1 }
56
+ end.to(change { inner_array })
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ shared_examples 'a method that change the hash values' do |method|
63
+ context 'when using deeply nested hashes' do
64
+ it 'updates values of hash' do
65
+ result = subject.public_send(method) { |value| value + 1 }
66
+ expected = { a: 2, b: 3, c: { d: 4, e: 5 } }
67
+ expect(result).to eq(expected)
68
+ end
69
+
70
+ it 'works recursively when parameter is passed' do
71
+ result = subject.public_send(method, recursive: true) do |value|
72
+ value + 1
73
+ end
74
+ expected = { a: 2, b: 3, c: { d: 4, e: 5 } }
75
+ expect(result).to eq(expected)
76
+ end
77
+
78
+ it 'does not work recursively when parameter is passed as false' do
79
+ result = subject.public_send(method, recursive: false) do |value|
80
+ value + 1
81
+ end
82
+ expected = { a: 2, b: 3, c: { d: 3, e: 4 } }
83
+ expect(result).to eq(expected)
84
+ end
85
+
86
+ it 'does not ignore hash when option is passed' do
87
+ result = subject.public_send(method, skip_inner: false) do |value|
88
+ value.is_a?(Hash) ? 10 + value.size : value + 1
89
+ end
90
+ expected = { a: 2, b: 3, c: 12 }
91
+ expect(result).to eq(expected)
92
+ end
93
+
94
+ it 'ignore hash and work recursively when option is passed' do
95
+ result = subject.public_send(method, skip_inner: true) do |value|
96
+ value.is_a?(Hash) ? 10 + value.size : value + 1
97
+ end
98
+ expect(result).to eq(a: 2, b: 3, c: { d: 4, e: 5 })
99
+ end
100
+
101
+ it 'ignore hash and does not work recursively when option is passed' do
102
+ options = { skip_inner: false, recursive: false }
103
+ result = subject.public_send(method, options) do |value|
104
+ value.is_a?(Hash) ? value : value + 1
105
+ end
106
+ expect(result).to eq(a: 2, b: 3, c: { d: 3, e: 4 })
107
+ end
108
+ end
109
+
110
+ context 'when using deeply nested arrays' do
111
+ let(:subject) { { a: 1, b: 2, c: [{ d: 3 }, { e: { f: 4 } }, 5] } }
112
+
113
+ it 'goes recursivly true arrays' do
114
+ result = subject.public_send(method) { |value| value + 1 }
115
+
116
+ expect(result).to eq(a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }, 6])
117
+ end
118
+
119
+ it 'does not work recursively when parameter is passed as false' do
120
+ result = subject.public_send(method, recursive: false) do |value|
121
+ value + 1
122
+ end
123
+ expect(result).to eq(a: 2, b: 3, c: [{ d: 3 }, { e: { f: 4 } }, 5])
124
+ end
125
+
126
+ it 'does not ignore array when option is passed' do
127
+ result = subject.public_send(method, skip_inner: false) do |value|
128
+ value.is_a?(Array) ? 10 + value.size : value + 1
129
+ end
130
+ expect(result).to eq(a: 2, b: 3, c: 13)
131
+ end
132
+
133
+ it 'ignores array when option is passed' do
134
+ result = subject.public_send(method, skip_inner: true) do |value|
135
+ value.is_a?(Array) ? 10 + value.size : value + 1
136
+ end
137
+ expect(result).to eq(a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }, 6])
138
+ end
139
+
140
+ it 'ignore hash and does not work recursively when option is passed' do
141
+ options = { skip_inner: false, recursive: false }
142
+ result = subject.public_send(method, options) do |value|
143
+ value.is_a?(Array) ? value : value + 1
144
+ end
145
+ expect(result).to eq(a: 2, b: 3, c: [{ d: 3 }, { e: { f: 4 } }, 5])
146
+ end
147
+ end
148
+
149
+ context 'when using a nested extra class' do
150
+ let(:subject) { { a: 1, b: 2, c: Hash::ValueChanger::Dummy.new(3) } }
151
+ let(:result) { subject.public_send(method) { |value| value + 1 } }
152
+ let(:expected) { { a: 2, b: 3, c: 4 } }
153
+
154
+ it 'goes perform the mapping with the extra class' do
155
+ expect(result).to eq(expected)
156
+ end
157
+
158
+ context 'when class is an interactor' do
159
+ subject { { a: 1, b: 2, c: object } }
160
+ let(:expected) { { a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }] } }
161
+ let(:object) do
162
+ Hash::ValueChanger::DummyIteractor.new({ d: 3 }, e: { f: 4 })
163
+ end
164
+
165
+ it 'goes through the iteractor' do
166
+ expect(result).to eq(expected)
167
+ end
168
+ end
169
+
170
+ context 'when using mapping inner array with inner objecth' do
171
+ let(:object) { Hash::ValueChanger::Dummy.new(2) }
172
+ let(:array) { Hash::ValueChanger::DummyIteractor.new(object) }
173
+ let(:subject) { { a: 1, b: array } }
174
+ let(:result) do
175
+ subject.public_send(method, skip_inner: false) do |value|
176
+ case value
177
+ when Numeric
178
+ value + 10
179
+ when Hash, Hash::ValueChanger::DummyIteractor
180
+ value
181
+ else
182
+ value.as_json
183
+ end
184
+ end
185
+ end
186
+
187
+ it 'process the object after processing the array' do
188
+ expect(result).to eq(a: 11, b: [{ val: 12 }])
189
+ end
190
+ end
191
+ end
192
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darthjee-core_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-19 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-nav
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.4
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +81,19 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.7'
69
83
  - !ruby/object:Gem::Dependency
70
- name: pry-nav
84
+ name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 0.2.4
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: 0.2.4
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: 0.14.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
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'
97
125
  description: Extension of basic classes with usefull methods
98
126
  email:
99
127
  - darthjee@gmail.com
@@ -101,8 +129,11 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
132
+ - ".circleci/config.yml"
104
133
  - ".gitignore"
105
134
  - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".rubocop_todo.yml"
106
137
  - ARRAY_README.md
107
138
  - DATE_README.md
108
139
  - ENUMERABLE_README.md
@@ -114,7 +145,6 @@ files:
114
145
  - README.md
115
146
  - Rakefile
116
147
  - SYMBOL_README.md
117
- - circle.yml
118
148
  - core_ext.gemspec
119
149
  - docker-compose.yml
120
150
  - lib/darthjee.rb
@@ -124,8 +154,12 @@ files:
124
154
  - lib/darthjee/core_ext/date.rb
125
155
  - lib/darthjee/core_ext/enumerable.rb
126
156
  - lib/darthjee/core_ext/hash.rb
157
+ - lib/darthjee/core_ext/hash/chain_fetcher.rb
127
158
  - lib/darthjee/core_ext/hash/deep_hash_constructor.rb
128
159
  - lib/darthjee/core_ext/hash/key_changer.rb
160
+ - lib/darthjee/core_ext/hash/keys_sorter.rb
161
+ - lib/darthjee/core_ext/hash/squasher.rb
162
+ - lib/darthjee/core_ext/hash/to_hash_mapper.rb
129
163
  - lib/darthjee/core_ext/hash/value_changer.rb
130
164
  - lib/darthjee/core_ext/math.rb
131
165
  - lib/darthjee/core_ext/numeric.rb
@@ -138,8 +172,12 @@ files:
138
172
  - spec/lib/array_spec.rb
139
173
  - spec/lib/date_spec.rb
140
174
  - spec/lib/enumerable_spec.rb
175
+ - spec/lib/hash/chain_fetcher_spec.rb
141
176
  - spec/lib/hash/deep_hash_constructor_spec.rb
142
177
  - spec/lib/hash/key_changer_spec.rb
178
+ - spec/lib/hash/keys_sorter_spec.rb
179
+ - spec/lib/hash/squasher_spec.rb
180
+ - spec/lib/hash/to_hash_mapper_spec.rb
143
181
  - spec/lib/hash_spec.rb
144
182
  - spec/lib/math_spec.rb
145
183
  - spec/lib/numeric_spec.rb
@@ -151,20 +189,22 @@ files:
151
189
  - spec/support/models/default_value.rb
152
190
  - spec/support/models/hash/value_changer/dummy.rb
153
191
  - spec/support/models/hash/value_changer/dummy_iteractor.rb
154
- - spec/support/shared_examples/array_random.rb
155
- - spec/support/shared_examples/chain_fetch.rb
156
- - spec/support/shared_examples/chain_hash_keys_changer.rb
192
+ - spec/support/shared_examples/array/array_random.rb
157
193
  - spec/support/shared_examples/clean.rb
158
194
  - spec/support/shared_examples/date.rb
159
195
  - spec/support/shared_examples/expected.rb
160
- - spec/support/shared_examples/hash_keys_changer.rb
161
- - spec/support/shared_examples/hash_transpose.rb
162
- - spec/support/shared_examples/keys_appender.rb
163
- - spec/support/shared_examples/keys_camelizer.rb
164
- - spec/support/shared_examples/keys_underscorer.rb
165
- - spec/support/shared_examples/map_to_hash.rb
166
- - spec/support/shared_examples/remap.rb
167
- - spec/support/shared_examples/value_changer.rb
196
+ - spec/support/shared_examples/hash/chain_fetch.rb
197
+ - spec/support/shared_examples/hash/chain_hash_keys_changer.rb
198
+ - spec/support/shared_examples/hash/hash_keys_changer.rb
199
+ - spec/support/shared_examples/hash/hash_squasher.rb
200
+ - spec/support/shared_examples/hash/hash_transpose.rb
201
+ - spec/support/shared_examples/hash/keys_appender.rb
202
+ - spec/support/shared_examples/hash/keys_camelizer.rb
203
+ - spec/support/shared_examples/hash/keys_sorter.rb
204
+ - spec/support/shared_examples/hash/keys_underscorer.rb
205
+ - spec/support/shared_examples/hash/map_to_hash.rb
206
+ - spec/support/shared_examples/hash/remap.rb
207
+ - spec/support/shared_examples/hash/value_changer.rb
168
208
  homepage: https://github.com/darthjee/core_ext
169
209
  licenses: []
170
210
  metadata: {}
@@ -192,8 +232,12 @@ test_files:
192
232
  - spec/lib/array_spec.rb
193
233
  - spec/lib/date_spec.rb
194
234
  - spec/lib/enumerable_spec.rb
235
+ - spec/lib/hash/chain_fetcher_spec.rb
195
236
  - spec/lib/hash/deep_hash_constructor_spec.rb
196
237
  - spec/lib/hash/key_changer_spec.rb
238
+ - spec/lib/hash/keys_sorter_spec.rb
239
+ - spec/lib/hash/squasher_spec.rb
240
+ - spec/lib/hash/to_hash_mapper_spec.rb
197
241
  - spec/lib/hash_spec.rb
198
242
  - spec/lib/math_spec.rb
199
243
  - spec/lib/numeric_spec.rb
@@ -205,17 +249,19 @@ test_files:
205
249
  - spec/support/models/default_value.rb
206
250
  - spec/support/models/hash/value_changer/dummy.rb
207
251
  - spec/support/models/hash/value_changer/dummy_iteractor.rb
208
- - spec/support/shared_examples/array_random.rb
209
- - spec/support/shared_examples/chain_fetch.rb
210
- - spec/support/shared_examples/chain_hash_keys_changer.rb
252
+ - spec/support/shared_examples/array/array_random.rb
211
253
  - spec/support/shared_examples/clean.rb
212
254
  - spec/support/shared_examples/date.rb
213
255
  - spec/support/shared_examples/expected.rb
214
- - spec/support/shared_examples/hash_keys_changer.rb
215
- - spec/support/shared_examples/hash_transpose.rb
216
- - spec/support/shared_examples/keys_appender.rb
217
- - spec/support/shared_examples/keys_camelizer.rb
218
- - spec/support/shared_examples/keys_underscorer.rb
219
- - spec/support/shared_examples/map_to_hash.rb
220
- - spec/support/shared_examples/remap.rb
221
- - spec/support/shared_examples/value_changer.rb
256
+ - spec/support/shared_examples/hash/chain_fetch.rb
257
+ - spec/support/shared_examples/hash/chain_hash_keys_changer.rb
258
+ - spec/support/shared_examples/hash/hash_keys_changer.rb
259
+ - spec/support/shared_examples/hash/hash_squasher.rb
260
+ - spec/support/shared_examples/hash/hash_transpose.rb
261
+ - spec/support/shared_examples/hash/keys_appender.rb
262
+ - spec/support/shared_examples/hash/keys_camelizer.rb
263
+ - spec/support/shared_examples/hash/keys_sorter.rb
264
+ - spec/support/shared_examples/hash/keys_underscorer.rb
265
+ - spec/support/shared_examples/hash/map_to_hash.rb
266
+ - spec/support/shared_examples/hash/remap.rb
267
+ - spec/support/shared_examples/hash/value_changer.rb
data/circle.yml DELETED
@@ -1,10 +0,0 @@
1
- dependencies:
2
- post:
3
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
4
- - chmod +x ./cc-test-reporter
5
-
6
- test:
7
- pre:
8
- - ./cc-test-reporter before-build
9
- override:
10
- - bundle exec rspec; ./cc-test-reporter after-build --exit-code $?
@@ -1,43 +0,0 @@
1
- shared_examples 'a class with append_keys method' do
2
- describe :prepend_to_keys do
3
- it 'accepts block to change the keys' do
4
- expect({ a: 1, 'b' => 2 }.prepend_to_keys('foo_')).to eq(foo_a: 1, 'foo_b' => 2)
5
- end
6
- it 'applies the block recursively' do
7
- expect({ 'a' => 1, b: { c: 3, 'd' => 4 } }.prepend_to_keys('foo_')).to eq('foo_a' => 1, foo_b: { foo_c: 3, 'foo_d' => 4 })
8
- end
9
- it 'changes type when type option is passed' do
10
- expect({ 'a' => 1, b: 2 }.prepend_to_keys('foo_', type: :string)).to eq('foo_a' => 1, 'foo_b' => 2)
11
- end
12
- it 'changes type when type option is passed' do
13
- expect({ 'a' => 1, b: 2 }.prepend_to_keys('foo_', type: :symbol)).to eq(foo_a: 1, foo_b: 2)
14
- end
15
- it 'keep type when type option is passed as keep' do
16
- expect({ 'a' => 1, b: 2 }.prepend_to_keys('foo_', type: :keep)).to eq('foo_a' => 1, foo_b: 2)
17
- end
18
- it 'applies to array as well' do
19
- expect({ 'a' => 1, b: [{ c: 2 }, { d: 3 }] }.prepend_to_keys('foo_', type: :keep)).to eq('foo_a' => 1, foo_b: [{ foo_c: 2 }, { foo_d: 3 }])
20
- end
21
- end
22
-
23
- describe :append_to_keys do
24
- it 'accepts block to change the keys' do
25
- expect({ a: 1, 'b' => 2 }.append_to_keys('_bar')).to eq(a_bar: 1, 'b_bar' => 2)
26
- end
27
- it 'applies the block recursively' do
28
- expect({ 'a' => 1, b: { c: 3, 'd' => 4 } }.append_to_keys('_bar')).to eq('a_bar' => 1, b_bar: { c_bar: 3, 'd_bar' => 4 })
29
- end
30
- it 'changes type when type option is passed' do
31
- expect({ 'a' => 1, b: 2 }.append_to_keys('_bar', type: :string)).to eq('a_bar' => 1, 'b_bar' => 2)
32
- end
33
- it 'changes type when type option is passed' do
34
- expect({ 'a' => 1, b: 2 }.append_to_keys('_bar', type: :symbol)).to eq(a_bar: 1, b_bar: 2)
35
- end
36
- it 'keep type when type option is passed as keep' do
37
- expect({ 'a' => 1, b: 2 }.append_to_keys('_bar', type: :keep)).to eq('a_bar' => 1, b_bar: 2)
38
- end
39
- it 'applies to array as well' do
40
- expect({ 'a' => 1, b: [{ c: 2 }, { d: 3 }] }.append_to_keys('_bar', type: :keep)).to eq('a_bar' => 1, b_bar: [{ c_bar: 2 }, { d_bar: 3 }])
41
- end
42
- end
43
- end