darthjee-core_ext 1.3.0 → 1.3.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/.gitignore +1 -0
- data/README.md +5 -1
- data/circle.yml +10 -0
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/lib/hash/value_changer.rb +6 -5
- data/spec/support/models/hash/value_changer/dummy.rb +4 -0
- data/spec/support/models/hash/value_changer/dummy_iteractor.rb +1 -1
- data/spec/support/shared_examples/value_changer.rb +61 -6
- metadata +3 -3
- data/Gemfile.lock +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e4db49fb26170a6468253694dc8710568992db8
|
4
|
+
data.tar.gz: 903f2881ee71e1af4ee05d2e3715e9b3de77f347
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf30dc4d88125615001e78ee47801387b850df4923a002c18b8a00b28f611725c7c1ece40f29a85ee809d5ef44105f6943a0a8451537b8104d09142558462250
|
7
|
+
data.tar.gz: 918aad79466a050cd855c59eb48022314c0ac4532389b3f0b82b0bbefd5ab342544a6c71a3bec1d0edc46fe257e37f4db8c896e3bb4e58c847126b039a7f4c92
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
Core_Ext
|
2
2
|
========
|
3
3
|
|
4
|
+
[](https://codeclimate.com/github/darthjee/core_ext)
|
5
|
+
[](https://codeclimate.com/github/darthjee/core_ext/coverage)
|
6
|
+
[](https://codeclimate.com/github/darthjee/core_ext)
|
7
|
+
|
4
8
|
# Usage
|
5
9
|
This project adds some new methods to the core ruby classes
|
6
10
|
|
@@ -20,7 +24,7 @@ gem 'darthjee-core_ext'
|
|
20
24
|
bundle install darthjee-core_ext
|
21
25
|
```
|
22
26
|
|
23
|
-
#methods added
|
27
|
+
# methods added
|
24
28
|
|
25
29
|
## Array
|
26
30
|
[ARRAY_README.md](ARRAY_README.md)
|
data/circle.yml
ADDED
@@ -0,0 +1,10 @@
|
|
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 $?
|
data/lib/hash/value_changer.rb
CHANGED
@@ -30,15 +30,16 @@ class Hash::ValueChanger
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def change_array(array)
|
33
|
-
|
33
|
+
method = %w(map! map).find { |m| array.respond_to? m }
|
34
34
|
|
35
|
-
array.
|
35
|
+
array.public_send(method) do |value|
|
36
36
|
if value.respond_to?(:change_values)
|
37
|
-
value
|
37
|
+
value.change_values(options, &block)
|
38
38
|
elsif is_iterable?(value)
|
39
|
-
|
39
|
+
change_array(value)
|
40
|
+
else
|
41
|
+
new_value(value)
|
40
42
|
end
|
41
|
-
array[index] = value
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
shared_examples 'a class with change_values method' do
|
2
2
|
let(:subject) { { a: 1, b: 2, c: { d: 3, e: 4 } } }
|
3
|
+
let(:inner_hash) { subject[:c] }
|
3
4
|
|
4
5
|
describe :change_values do
|
5
6
|
it_behaves_like 'a method that change the hash values', :change_values
|
@@ -9,6 +10,23 @@ shared_examples 'a class with change_values method' do
|
|
9
10
|
subject.change_values { |value| value + 1 }
|
10
11
|
end.not_to change { subject }
|
11
12
|
end
|
13
|
+
|
14
|
+
it 'does not change original hash' do
|
15
|
+
expect do
|
16
|
+
subject.change_values { |value| value + 1 }
|
17
|
+
end.not_to change { inner_hash }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when using an array' do
|
21
|
+
let(:subject) { { a: [{ b: 1}]} }
|
22
|
+
let(:inner_array) { subject[:a] }
|
23
|
+
|
24
|
+
it 'does not change original hash' do
|
25
|
+
expect do
|
26
|
+
subject.change_values { |value| value + 1 }
|
27
|
+
end.not_to change { inner_array }
|
28
|
+
end
|
29
|
+
end
|
12
30
|
end
|
13
31
|
|
14
32
|
describe :change_values! do
|
@@ -19,6 +37,23 @@ shared_examples 'a class with change_values method' do
|
|
19
37
|
subject.change_values! { |value| value + 1 }
|
20
38
|
end.to change { subject }
|
21
39
|
end
|
40
|
+
|
41
|
+
it 'changes original hash' do
|
42
|
+
expect do
|
43
|
+
subject.change_values! { |value| value + 1 }
|
44
|
+
end.to change { inner_hash }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when using an array' do
|
48
|
+
let(:subject) { { a: [{ b: 1}]} }
|
49
|
+
let(:inner_array) { subject[:a] }
|
50
|
+
|
51
|
+
it 'changes original hash' do
|
52
|
+
expect do
|
53
|
+
subject.change_values! { |value| value + 1 }
|
54
|
+
end.to change { inner_array }
|
55
|
+
end
|
56
|
+
end
|
22
57
|
end
|
23
58
|
end
|
24
59
|
|
@@ -50,26 +85,26 @@ shared_examples 'a method that change the hash values' do |method|
|
|
50
85
|
end
|
51
86
|
|
52
87
|
context 'when using deeply nested arrays' do
|
53
|
-
let(:subject) { { a: 1, b: 2, c: [{ d: 3 }, { e: { f: 4 } } ] } }
|
88
|
+
let(:subject) { { a: 1, b: 2, c: [{ d: 3 }, { e: { f: 4 } }, 5 ] } }
|
54
89
|
|
55
90
|
it 'goes recursivly true arrays' do
|
56
|
-
expect(subject.public_send(method) { |value| value + 1 }).to eq(a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }])
|
91
|
+
expect(subject.public_send(method) { |value| value + 1 }).to eq(a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }, 6])
|
57
92
|
end
|
58
93
|
|
59
94
|
it 'does not work recursively when parameter is passed as false' do
|
60
|
-
expect(subject.public_send(method, recursive: false) { |value| value + 1 }).to eq(a: 2, b: 3, c: [{ d: 3 }, { e: { f: 4 } }])
|
95
|
+
expect(subject.public_send(method, recursive: false) { |value| value + 1 }).to eq(a: 2, b: 3, c: [{ d: 3 }, { e: { f: 4 } }, 5])
|
61
96
|
end
|
62
97
|
|
63
98
|
it 'does not ignore array when option is passed' do
|
64
|
-
expect(subject.public_send(method, skip_inner: false) { |value| value.is_a?(Array) ? 10 + value.size : value + 1 }).to eq(a: 2, b: 3, c:
|
99
|
+
expect(subject.public_send(method, skip_inner: false) { |value| value.is_a?(Array) ? 10 + value.size : value + 1 }).to eq(a: 2, b: 3, c: 13)
|
65
100
|
end
|
66
101
|
|
67
102
|
it 'ignores array when option is passed' do
|
68
|
-
expect(subject.public_send(method, skip_inner: true) { |value| value.is_a?(Array) ? 10 + value.size : value + 1 }).to eq(a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }])
|
103
|
+
expect(subject.public_send(method, skip_inner: true) { |value| value.is_a?(Array) ? 10 + value.size : value + 1 }).to eq(a: 2, b: 3, c: [{ d: 4 }, { e: { f: 5 } }, 6])
|
69
104
|
end
|
70
105
|
|
71
106
|
it 'ignore hash and does not work recursively when option is passed' do
|
72
|
-
expect(subject.public_send(method, skip_inner: false, recursive: false) { |value| value.is_a?(Array) ? value : value + 1 }).to eq(a: 2, b: 3, c: [{ d: 3 }, { e: { f: 4 } }])
|
107
|
+
expect(subject.public_send(method, skip_inner: false, recursive: false) { |value| value.is_a?(Array) ? value : value + 1 }).to eq(a: 2, b: 3, c: [{ d: 3 }, { e: { f: 4 } }, 5])
|
73
108
|
end
|
74
109
|
end
|
75
110
|
|
@@ -88,5 +123,25 @@ shared_examples 'a method that change the hash values' do |method|
|
|
88
123
|
end
|
89
124
|
end
|
90
125
|
|
126
|
+
context 'when using mapping inner array with inner object into a new hash' do
|
127
|
+
let(:object) { Hash::ValueChanger::Dummy.new(2) }
|
128
|
+
let(:array) { Hash::ValueChanger::DummyIteractor.new(object) }
|
129
|
+
let(:subject) { { a: 1, b: array } }
|
130
|
+
let(:result) do
|
131
|
+
subject.public_send(method, skip_inner: false) do |value|
|
132
|
+
if value.is_a?(Numeric)
|
133
|
+
value + 10
|
134
|
+
elsif value.is_a?(Hash) || value.is_a?(Hash::ValueChanger::DummyIteractor)
|
135
|
+
value
|
136
|
+
else
|
137
|
+
value.as_json
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'process the object after processing the array' do
|
143
|
+
expect(result).to eq(a: 11, b: [{ val: 12 }])
|
144
|
+
end
|
145
|
+
end
|
91
146
|
end
|
92
147
|
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -134,11 +134,11 @@ files:
|
|
134
134
|
- ARRAY_README.md
|
135
135
|
- ENUMERABLE_README.md
|
136
136
|
- Gemfile
|
137
|
-
- Gemfile.lock
|
138
137
|
- HASH_README.md
|
139
138
|
- LICENSE
|
140
139
|
- README.md
|
141
140
|
- Rakefile
|
141
|
+
- circle.yml
|
142
142
|
- core_ext.gemspec
|
143
143
|
- lib/array.rb
|
144
144
|
- lib/array/hash_builder.rb
|
data/Gemfile.lock
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
darthjee-core_ext (1.3.0)
|
5
|
-
activesupport (~> 5.1.1)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (5.1.1)
|
11
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (~> 0.7)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
tzinfo (~> 1.1)
|
15
|
-
coderay (1.1.1)
|
16
|
-
concurrent-ruby (1.0.5)
|
17
|
-
diff-lcs (1.2.5)
|
18
|
-
docile (1.1.5)
|
19
|
-
i18n (0.8.4)
|
20
|
-
json (2.1.0)
|
21
|
-
method_source (0.8.2)
|
22
|
-
minitest (5.10.2)
|
23
|
-
pry (0.10.4)
|
24
|
-
coderay (~> 1.1.0)
|
25
|
-
method_source (~> 0.8.1)
|
26
|
-
slop (~> 3.4)
|
27
|
-
pry-nav (0.2.4)
|
28
|
-
pry (>= 0.9.10, < 0.11.0)
|
29
|
-
rake (11.3.0)
|
30
|
-
rspec (2.99.0)
|
31
|
-
rspec-core (~> 2.99.0)
|
32
|
-
rspec-expectations (~> 2.99.0)
|
33
|
-
rspec-mocks (~> 2.99.0)
|
34
|
-
rspec-core (2.99.2)
|
35
|
-
rspec-expectations (2.99.2)
|
36
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
37
|
-
rspec-mocks (2.99.4)
|
38
|
-
simplecov (0.14.1)
|
39
|
-
docile (~> 1.1.0)
|
40
|
-
json (>= 1.8, < 3)
|
41
|
-
simplecov-html (~> 0.10.0)
|
42
|
-
simplecov-html (0.10.1)
|
43
|
-
slop (3.6.0)
|
44
|
-
thread_safe (0.3.6)
|
45
|
-
tzinfo (1.2.3)
|
46
|
-
thread_safe (~> 0.1)
|
47
|
-
|
48
|
-
PLATFORMS
|
49
|
-
ruby
|
50
|
-
|
51
|
-
DEPENDENCIES
|
52
|
-
bundler (~> 1.6)
|
53
|
-
darthjee-core_ext!
|
54
|
-
pry (~> 0.10.4)
|
55
|
-
pry-nav (~> 0.2.4)
|
56
|
-
rake (~> 11.3.0)
|
57
|
-
rspec (~> 2.14)
|
58
|
-
rspec-mocks (~> 2.99.4)
|
59
|
-
simplecov (~> 0.14.1)
|
60
|
-
|
61
|
-
BUNDLED WITH
|
62
|
-
1.15.1
|