transproc 1.0.0 → 1.1.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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +15 -0
  3. data/.gitignore +3 -0
  4. data/.travis.yml +14 -10
  5. data/CHANGELOG.md +61 -17
  6. data/Gemfile +9 -18
  7. data/README.md +17 -19
  8. data/Rakefile +1 -0
  9. data/lib/transproc.rb +3 -4
  10. data/lib/transproc/all.rb +2 -0
  11. data/lib/transproc/array.rb +9 -51
  12. data/lib/transproc/array/combine.rb +61 -0
  13. data/lib/transproc/class.rb +2 -0
  14. data/lib/transproc/coercions.rb +2 -0
  15. data/lib/transproc/compiler.rb +45 -0
  16. data/lib/transproc/composer.rb +2 -0
  17. data/lib/transproc/composite.rb +2 -0
  18. data/lib/transproc/conditional.rb +2 -0
  19. data/lib/transproc/constants.rb +5 -0
  20. data/lib/transproc/error.rb +2 -0
  21. data/lib/transproc/function.rb +4 -1
  22. data/lib/transproc/functions.rb +2 -0
  23. data/lib/transproc/hash.rb +105 -45
  24. data/lib/transproc/proc.rb +2 -0
  25. data/lib/transproc/recursion.rb +2 -0
  26. data/lib/transproc/registry.rb +4 -2
  27. data/lib/transproc/store.rb +1 -0
  28. data/lib/transproc/support/deprecations.rb +2 -0
  29. data/lib/transproc/transformer.rb +7 -1
  30. data/lib/transproc/transformer/class_interface.rb +32 -65
  31. data/lib/transproc/transformer/deprecated/class_interface.rb +81 -0
  32. data/lib/transproc/transformer/dsl.rb +51 -0
  33. data/lib/transproc/version.rb +3 -1
  34. data/spec/spec_helper.rb +21 -10
  35. data/spec/unit/array/combine_spec.rb +224 -0
  36. data/spec/unit/array_transformations_spec.rb +1 -52
  37. data/spec/unit/class_transformations_spec.rb +10 -7
  38. data/spec/unit/coercions_spec.rb +1 -1
  39. data/spec/unit/composer_spec.rb +1 -1
  40. data/spec/unit/conditional_spec.rb +1 -1
  41. data/spec/unit/function_not_found_error_spec.rb +1 -1
  42. data/spec/unit/function_spec.rb +16 -1
  43. data/spec/unit/hash_transformations_spec.rb +12 -1
  44. data/spec/unit/proc_transformations_spec.rb +3 -1
  45. data/spec/unit/recursion_spec.rb +1 -1
  46. data/spec/unit/registry_spec.rb +9 -1
  47. data/spec/unit/store_spec.rb +2 -1
  48. data/spec/unit/transformer/class_interface_spec.rb +364 -0
  49. data/spec/unit/transformer/dsl_spec.rb +15 -0
  50. data/spec/unit/transformer/instance_methods_spec.rb +25 -0
  51. data/spec/unit/transformer_spec.rb +128 -40
  52. data/spec/unit/transproc_spec.rb +1 -1
  53. data/transproc.gemspec +1 -5
  54. metadata +19 -54
  55. data/.rubocop.yml +0 -66
  56. data/.rubocop_todo.yml +0 -11
  57. data/rakelib/mutant.rake +0 -16
  58. data/rakelib/rubocop.rake +0 -18
  59. data/spec/support/mutant.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ca6a7b97e58a3d28f1c9ebeb9303a52926c94d39
4
- data.tar.gz: f1255fcec0934e3f096a6b47252d1ab6937df70e
2
+ SHA256:
3
+ metadata.gz: c5e373dbeb3ba726459c3cf12238ba1e9fd096e308bdfcbf9799045653c053db
4
+ data.tar.gz: b761e23e9e7c630db6e08ee7e317758fe2bd53cb6a8a49bb7799902b657ffbc3
5
5
  SHA512:
6
- metadata.gz: f9a87bded9276d2be3f4847bd59528a29e26c54333518ead773f304b8c342a9dc63b8f18bc681483e10cd70c7717194cbc56d74b921d7228fd28b991339ec949
7
- data.tar.gz: 6ef8c827fd903e226c3c1660091aac9fa231108ab7b7cecda5c438d142b633b81428000fa43802b51258d4033d774ac4f5ba90e0c97dbf77bbe42d66b30955da
6
+ metadata.gz: 3aee819e93702794f280d6f5578670494fb28e3661f7c2bac311530363ac52aa83897cdc00ee2c591eadae86d3dcf4147805bfc9805f24dc6034314df2d8aacd
7
+ data.tar.gz: 55eb18ed05667309ee936ac75b6146940ca45c64cc215225a894e42b84ffddaea571d1a7675554cc8802f31b197dc2810886cdb0685c2473c9902e5c0aacf6bb
data/.codeclimate.yml ADDED
@@ -0,0 +1,15 @@
1
+ version: "2"
2
+
3
+ prepare:
4
+ fetch:
5
+ - url: "https://raw.githubusercontent.com/dry-rb/devtools/master/.rubocop.yml"
6
+ path: ".rubocop.yml"
7
+
8
+ exclude_patterns:
9
+ - "benchmarks/"
10
+ - "examples/"
11
+ - "spec/"
12
+
13
+ plugins:
14
+ rubocop:
15
+ enabled: true
data/.gitignore CHANGED
@@ -13,3 +13,6 @@
13
13
  *.o
14
14
  *.a
15
15
  mkmf.log
16
+ .rubocop.yml
17
+ .rubocop_todo.yml
18
+
data/.travis.yml CHANGED
@@ -1,18 +1,22 @@
1
- dist: trusty
2
1
  language: ruby
3
- sudo: required
4
2
  cache: bundler
5
3
  bundler_args: --without tools
4
+ before_script:
5
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
6
+ - chmod +x ./cc-test-reporter
7
+ - ./cc-test-reporter before-build
8
+ after_script:
9
+ - "[ -d coverage ] && ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
6
10
  script: 'bundle exec rake spec'
7
- after_success:
8
- - '[ "$TRAVIS_RUBY_VERSION" = "2.3.1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter'
9
11
  rvm:
10
- - 2.0
11
- - 2.2
12
- - 2.1
13
- - 2.3.1
14
- - rbx-3
15
- - jruby-9.1.5.0
12
+ - 2.3.8
13
+ - 2.6.3
14
+ - 2.5.5
15
+ - 2.4.6
16
+ - jruby-9.2.7.0
17
+ env:
18
+ global:
19
+ - COVERAGE='true'
16
20
  notifications:
17
21
  webhooks:
18
22
  urls:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,48 @@
1
- ## v1.0.0 2017-01-29
1
+ # v1.1.1 2019-12-21
2
+
3
+ ## Fixed
4
+
5
+ - Keyword warnings on Ruby 2.7 (flash-gordon)
6
+
7
+ [Compare v1.1.0...v1.1.1](https://github.com/solnic/transproc/compare/v1.1.0...v1.1.1)
8
+
9
+ # v1.1.0 2019-07-18
10
+
11
+ This is the last transproc release before the project will be forked to `dry-transformer`.
12
+
13
+ ## Added
14
+
15
+ * New DSL for defining transformers using `define!` method, which now supports instance methods as transformation functions (@solnic)
16
+ * Simplified transformer class definition - registry is auto-configured and you can use `import` at the transformer class level (@solnic)
17
+ * New `HashTransformation.deep_stringify_keys` function
18
+
19
+ [Compare v1.0.3...v1.1.0](https://github.com/solnic/transproc/compare/v1.0.3...v1.1.0)
20
+
21
+ # v1.0.3 2018-12-01
22
+
23
+ ## Changed
24
+
25
+ * [BREAKING] Added minimal Ruby version to the gemspec file. Transproc now works with Ruby 2.3 and above (flash-gordon)
26
+ * Performance improvements introduced by using new built-in methods in `Hash` (v-kolesnikov + flash-gordon)
27
+
28
+ [Compare v1.0.2...v1.0.3](https://github.com/solnic/transproc/compare/v1.0.2...v1.0.3)
29
+
30
+ # v1.0.2 2017-02-25
31
+
32
+ ## Fixed
33
+
34
+ * `combine` works fine when there are missing nodes for deeply nested arrays (Kukunin)
35
+
36
+ [Compare v1.0.1...v1.0.2](https://github.com/solnic/transproc/compare/v1.0.1...v1.0.2)
37
+
38
+ # v1.0.1 2017-02-25
39
+
40
+ * `combine` is now multiple times faster, depending on the level of nesting (Kukunin + splattael)
41
+ * `nest` (thus `wrap` too) is ~2x faster now (solnic)
42
+
43
+ [Compare v1.0.0...v1.0.1](https://github.com/solnic/transproc/compare/v1.0.0...v1.0.1)
44
+
45
+ # v1.0.0 2017-01-29
2
46
 
3
47
  ## Added
4
48
 
@@ -14,7 +58,7 @@
14
58
 
15
59
  [Compare v0.4.2...v1.0.0](https://github.com/solnic/transproc/compare/v0.4.2...v1.0.0)
16
60
 
17
- ## v0.4.2 2017-01-12
61
+ # v0.4.2 2017-01-12
18
62
 
19
63
  ## Added
20
64
 
@@ -26,7 +70,7 @@
26
70
 
27
71
  [Compare v0.4.1...v0.4.2](https://github.com/solnic/transproc/compare/v0.4.1...v0.4.2)
28
72
 
29
- ## v0.4.1 2016-11-08
73
+ # v0.4.1 2016-11-08
30
74
 
31
75
  ## Added
32
76
 
@@ -38,7 +82,7 @@
38
82
 
39
83
  [Compare v0.4.0...v0.4.1](https://github.com/solnic/transproc/compare/v0.4.0...v0.4.1)
40
84
 
41
- ## v0.4.0 2015-11-23
85
+ # v0.4.0 2015-11-23
42
86
 
43
87
  ## Fixed
44
88
 
@@ -50,7 +94,7 @@
50
94
 
51
95
  [Compare v0.3.2...v0.4.0](https://github.com/solnic/transproc/compare/v0.3.2...v0.4.0)
52
96
 
53
- ## v0.3.2 2015-08-17
97
+ # v0.3.2 2015-08-17
54
98
 
55
99
  ## Changed
56
100
 
@@ -62,7 +106,7 @@
62
106
 
63
107
  [Compare v0.3.1...v0.3.2](https://github.com/solnic/transproc/compare/v0.3.1...v0.3.2)
64
108
 
65
- ## v0.3.1 2015-08-06
109
+ # v0.3.1 2015-08-06
66
110
 
67
111
  ### Added
68
112
 
@@ -74,7 +118,7 @@
74
118
 
75
119
  [Compare v0.3.0...v0.3.1](https://github.com/solnic/transproc/compare/v0.3.0...v0.3.1)
76
120
 
77
- ## v0.3.0 2015-07-12
121
+ # v0.3.0 2015-07-12
78
122
 
79
123
  This release deprecates a couple of APIs and changes the way functions can be
80
124
  accessed. The global `Transproc()` function registry is now deprecated and you
@@ -104,7 +148,7 @@ in 1.0.0.
104
148
 
105
149
  [Compare v0.2.4...v0.3.0](https://github.com/solnic/transproc/compare/v0.2.4...v0.3.0)
106
150
 
107
- ## v0.2.4 2015-06-20
151
+ # v0.2.4 2015-06-20
108
152
 
109
153
  ### Added
110
154
 
@@ -118,7 +162,7 @@ in 1.0.0.
118
162
 
119
163
  [Compare v0.2.3...v0.2.4](https://github.com/solnic/transproc/compare/v0.2.3...v0.2.4)
120
164
 
121
- ## v0.2.3 2015-06-02
165
+ # v0.2.3 2015-06-02
122
166
 
123
167
  ### Added
124
168
 
@@ -134,7 +178,7 @@ in 1.0.0.
134
178
 
135
179
  [Compare v0.2.2...v0.2.3](https://github.com/solnic/transproc/compare/v0.2.2...v0.2.3)
136
180
 
137
- ## v0.2.2 2015-05-22
181
+ # v0.2.2 2015-05-22
138
182
 
139
183
  ### Added
140
184
 
@@ -148,7 +192,7 @@ in 1.0.0.
148
192
 
149
193
  [Compare v0.2.1...v0.2.2](https://github.com/solnic/transproc/compare/v0.2.1...v0.2.2)
150
194
 
151
- ## v0.2.1 2015-05-17
195
+ # v0.2.1 2015-05-17
152
196
 
153
197
  ### Added
154
198
 
@@ -177,7 +221,7 @@ in 1.0.0.
177
221
 
178
222
  [Compare v0.2.0...v0.2.1](https://github.com/solnic/transproc/compare/v0.2.0...v0.2.1)
179
223
 
180
- ## v0.2.0 2015-04-14
224
+ # v0.2.0 2015-04-14
181
225
 
182
226
  ### Added
183
227
 
@@ -199,7 +243,7 @@ in 1.0.0.
199
243
 
200
244
  [Compare v0.1.3...v0.2.0](https://github.com/solnic/transproc/compare/v0.1.3...v0.2.0)
201
245
 
202
- ## v0.1.3 2015-04-07
246
+ # v0.1.3 2015-04-07
203
247
 
204
248
  ### Added
205
249
 
@@ -212,7 +256,7 @@ in 1.0.0.
212
256
 
213
257
  [Compare v0.1.2...v0.1.3](https://github.com/solnic/transproc/compare/v0.1.2...v0.1.3)
214
258
 
215
- ## v0.1.2 2015-03-14
259
+ # v0.1.2 2015-03-14
216
260
 
217
261
  ### Changed
218
262
 
@@ -220,7 +264,7 @@ in 1.0.0.
220
264
 
221
265
  [Compare v0.1.1...v0.1.2](https://github.com/solnic/transproc/compare/v0.1.1...v0.1.2)
222
266
 
223
- ## v0.1.1 2015-03-13
267
+ # v0.1.1 2015-03-13
224
268
 
225
269
  ### Changed
226
270
 
@@ -234,7 +278,7 @@ in 1.0.0.
234
278
 
235
279
  [Compare v0.1.0...v0.1.1](https://github.com/solnic/transproc/compare/v0.1.0...v0.1.1)
236
280
 
237
- ## v0.1.0 2014-12-28
281
+ # v0.1.0 2014-12-28
238
282
 
239
283
  ### Added
240
284
 
@@ -247,6 +291,6 @@ in 1.0.0.
247
291
 
248
292
  [Compare v0.0.1...v0.1.0](https://github.com/solnic/transproc/compare/v0.0.1...v0.1.0)
249
293
 
250
- ## v0.0.1 2014-12-24
294
+ # v0.0.1 2014-12-24
251
295
 
252
296
  First public release \o/
data/Gemfile CHANGED
@@ -2,28 +2,19 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :test do
6
- gem 'equalizer'
7
-
8
- if RUBY_VERSION >= '2.1'
9
- gem 'anima'
10
- platform :mri do
11
- gem 'mutant', github: 'mbj/mutant', branch: 'master'
12
- gem 'mutant-rspec'
5
+ gem 'rake'
6
+ gem 'rspec', '~> 3.8'
7
+ gem 'dry-equalizer', '~> 0.2'
13
8
 
14
- gem 'codeclimate-test-reporter', require: false
15
- gem 'simplecov', require: false
16
- end
17
- else
18
- gem 'anima', '~> 0.2.0'
19
- end
9
+ platform :mri do
10
+ gem 'simplecov', require: false
20
11
  end
21
12
 
22
13
  group :tools do
23
- gem 'rubocop', '~> 0.30.0'
24
14
  gem 'byebug', platform: :mri
25
15
  gem 'benchmark-ips'
26
- gem 'guard'
27
- gem 'guard-rspec'
28
- gem 'guard-rubocop'
16
+ end
17
+
18
+ group :test do
19
+ gem 'warning' if defined? Warning
29
20
  end
data/README.md CHANGED
@@ -1,18 +1,16 @@
1
1
  [gem]: https://rubygems.org/gems/transproc
2
2
  [travis]: https://travis-ci.org/solnic/transproc
3
- [gemnasium]: https://gemnasium.com/solnic/transproc
4
3
  [codeclimate]: https://codeclimate.com/github/solnic/transproc
5
4
  [coveralls]: https://coveralls.io/r/solnic/transproc
6
- [inchpages]: http://inch-ci.org/github/solnic/transproc
5
+ [inchpages]: https://inch-ci.org/github/solnic/transproc
7
6
 
8
7
  # Transproc
9
8
 
10
9
  [![Gem Version](https://badge.fury.io/rb/transproc.svg)][gem]
11
10
  [![Build Status](https://travis-ci.org/solnic/transproc.svg?branch=master)][travis]
12
- [![Dependency Status](https://gemnasium.com/solnic/transproc.svg)][gemnasium]
13
11
  [![Code Climate](https://codeclimate.com/github/solnic/transproc/badges/gpa.svg)][codeclimate]
14
12
  [![Test Coverage](https://codeclimate.com/github/solnic/transproc/badges/coverage.svg)][codeclimate]
15
- [![Inline docs](http://inch-ci.org/github/solnic/transproc.svg?branch=master)][inchpages]
13
+ [![Inline docs](https://inch-ci.org/github/solnic/transproc.svg?branch=master)][inchpages]
16
14
 
17
15
  Transproc is a small library that allows you to compose procs into a functional pipeline using left-to-right function composition.
18
16
 
@@ -22,7 +20,7 @@ or `>>` in F#.
22
20
  `transproc` provides a mechanism to define and compose transformations,
23
21
  along with a number of built-in transformations.
24
22
 
25
- It's currently used as the data mapping backend in [Ruby Object Mapper](http://rom-rb.org).
23
+ It's currently used as the data mapping backend in [Ruby Object Mapper](https://rom-rb.org).
26
24
 
27
25
  ## Installation
28
26
 
@@ -45,15 +43,15 @@ Or install it yourself as:
45
43
  Simple transformations are defined as easy as:
46
44
 
47
45
  ```ruby
48
- increament = Transproc::Function.new(-> (data) { data + 1 })
49
- increament[1] # => 2
46
+ increment = Transproc::Function.new(-> (data) { data + 1 })
47
+ increment[1] # => 2
50
48
  ```
51
49
 
52
50
  It's easy to compose transformations:
53
51
 
54
52
  ```ruby
55
53
  to_string = Transproc::Function.new(:to_s.to_proc)
56
- (increament >> to_string)[1] => '2'
54
+ (increment >> to_string)[1] # => '2'
57
55
  ```
58
56
 
59
57
  It's easy to pass additional arguments to transformations:
@@ -94,13 +92,13 @@ M[:map_array, M[:to_string]].([1, 2, 3]) # => ['1', '2', '3']
94
92
  `transproc` comes with a lot of built-in functions. They come in the form of
95
93
  modules with class methods, which you can import into a registry:
96
94
 
97
- * [Coercions](http://www.rubydoc.info/gems/transproc/Transproc/Coercions)
98
- * [Array transformations](http://www.rubydoc.info/gems/transproc/Transproc/ArrayTransformations)
99
- * [Hash transformations](http://www.rubydoc.info/gems/transproc/Transproc/HashTransformations)
100
- * [Class transformations](http://www.rubydoc.info/gems/transproc/Transproc/ClassTransformations)
101
- * [Proc transformations](http://www.rubydoc.info/gems/transproc/Transproc/ProcTransformations)
102
- * [Conditional](http://www.rubydoc.info/gems/transproc/Transproc/Conditional)
103
- * [Recursion](http://www.rubydoc.info/gems/transproc/Transproc/Recursion)
95
+ * [Coercions](https://www.rubydoc.info/gems/transproc/Transproc/Coercions)
96
+ * [Array transformations](https://www.rubydoc.info/gems/transproc/Transproc/ArrayTransformations)
97
+ * [Hash transformations](https://www.rubydoc.info/gems/transproc/Transproc/HashTransformations)
98
+ * [Class transformations](https://www.rubydoc.info/gems/transproc/Transproc/ClassTransformations)
99
+ * [Proc transformations](https://www.rubydoc.info/gems/transproc/Transproc/ProcTransformations)
100
+ * [Conditional](https://www.rubydoc.info/gems/transproc/Transproc/Conditional)
101
+ * [Recursion](https://www.rubydoc.info/gems/transproc/Transproc/Recursion)
104
102
 
105
103
  You can import everything with:
106
104
 
@@ -197,9 +195,9 @@ transformation = t(:camel_case)
197
195
  transformation.call 'i_am_a_camel'
198
196
  # => "IAmACamel"
199
197
 
200
- transformation = t(:map_array, t(:symbolize_keys)
201
- .>> t(:rename_keys, user_name: :user))
202
- .>> t(:wrap, :address, [:city, :street, :zipcode])
198
+ transformation = t(:map_array, (
199
+ t(:symbolize_keys).>> t(:rename_keys, user_name: :user)
200
+ )).>> t(:wrap, :address, [:city, :street, :zipcode])
203
201
 
204
202
  transformation.call(
205
203
  [
@@ -237,7 +235,7 @@ transformation.call('[{"name":"Jane"}]')
237
235
 
238
236
  ## Credits
239
237
 
240
- This project is inspired by the work of following people:
238
+ This project is inspired by the work of the following people:
241
239
 
242
240
  * [Markus Schirp](https://github.com/mbj) and [morpher](https://github.com/mbj/morpher) project
243
241
  * [Josep M. Bach](https://github.com/txus) and [kleisli](https://github.com/txus/kleisli) project
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rspec/core/rake_task'
2
3
 
3
4
  task default: :spec
data/lib/transproc.rb CHANGED
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'transproc/version'
4
+ require 'transproc/constants'
2
5
  require 'transproc/function'
3
6
  require 'transproc/functions'
4
7
  require 'transproc/composer'
@@ -8,9 +11,5 @@ require 'transproc/registry'
8
11
  require 'transproc/transformer'
9
12
  require 'transproc/support/deprecations'
10
13
 
11
- module Transproc
12
- Undefined = Object.new.freeze
13
- end
14
-
15
14
  require 'transproc/array'
16
15
  require 'transproc/hash'
data/lib/transproc/all.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'transproc'
2
4
 
3
5
  require 'transproc/class'
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'transproc/coercions'
2
4
  require 'transproc/hash'
5
+ require 'transproc/array/combine'
3
6
 
4
7
  module Transproc
5
8
  # Transformation functions for Array objects
@@ -58,13 +61,13 @@ module Transproc
58
61
  # @api public
59
62
  def self.wrap(array, key, keys)
60
63
  nest = HashTransformations[:nest, key, keys]
61
- map_array(array, nest)
64
+ array.map { |element| nest.call(element) }
62
65
  end
63
66
 
64
67
  # Group array values using provided root key and value keys
65
68
  #
66
69
  # @example
67
- # fn = Transproc(:group, :tags, [:tag_name])
70
+ # fn = Transproc(:group, :tags, [:tag])
68
71
  #
69
72
  # fn.call [
70
73
  # { task: 'Group it', tag: 'task' },
@@ -97,10 +100,10 @@ module Transproc
97
100
  # Ungroup array values using provided root key and value keys
98
101
  #
99
102
  # @example
100
- # fn = Transproc(:group, :tags, [:tag_name])
103
+ # fn = Transproc(:ungroup, :tags, [:tag])
101
104
  #
102
105
  # fn.call [
103
- # { task: 'Group it', tags: [{ tag: 'task' }, { tag: 'important' }]
106
+ # { task: 'Group it', tags: [{ tag: 'task' }, { tag: 'important' }] }
104
107
  # ]
105
108
  # # => [
106
109
  # { task: 'Group it', tag: 'task' },
@@ -118,53 +121,8 @@ module Transproc
118
121
  array.flat_map { |item| HashTransformations.split(item, key, keys) }
119
122
  end
120
123
 
121
- CACHE = Hash.new { |h, k| h[k] = {} }
122
-
123
- def self.combine(array, mappings, cache = CACHE.dup)
124
- root, groups = array
125
-
126
- root.map do |parent|
127
- child_hash = {}
128
-
129
- for candidates in groups
130
- index = groups.index(candidates)
131
- data = mappings[index]
132
-
133
- key = data[0]
134
- keys = data[1]
135
-
136
- children =
137
- if data.size == 2
138
- candidates
139
- else
140
- combine(candidates, data[2])
141
- end
142
-
143
- child_keys = keys.size > 1 ? keys.values : keys.values[0]
144
- pk_names = keys.size > 1 ? keys.keys : keys.keys[0]
145
-
146
- pkey_value =
147
- if pk_names.is_a?(Array)
148
- parent.values_at(*pk_names)
149
- else
150
- parent[pk_names]
151
- end
152
-
153
- cache[key][child_keys] ||= children.group_by do |child|
154
- if child_keys.is_a?(Array)
155
- child.values_at(*child_keys)
156
- else
157
- child[child_keys]
158
- end
159
- end
160
-
161
- child_arr = cache[key][child_keys][pkey_value] || []
162
-
163
- child_hash[key] = child_arr
164
- end
165
-
166
- parent.merge(child_hash)
167
- end
124
+ def self.combine(array, mappings)
125
+ Combine.combine(array, mappings)
168
126
  end
169
127
 
170
128
  # Converts the array of hashes to array of values, extracted by given key