burner 1.0.0 → 1.1.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3d251463ade2de965d0dd1e0d635967571d3d1d4cab46a7d1271ab057d1c2e3
4
- data.tar.gz: 2eac66d3f745888be07cf5d2d66f6e8429c61b0255ad0916f7c6f8c792194dcd
3
+ metadata.gz: 9dea13fe31b6e7bc97eafb25201508afc0a05d2d4e2eb86aeab00004695674f1
4
+ data.tar.gz: 6569debdcc9ad51a0e180ee6b0bac192029b95d59ad767ddae7c6711dba9830d
5
5
  SHA512:
6
- metadata.gz: c57dabbc95d1b58b5f0fe15429f36682d0dec0771951bb01b6e8c6345ddd9e95b5805ad57f0e0166e8e4e87d0296885915c022895818e46c3389049207e0e719
7
- data.tar.gz: f23ecf1374570ad2f5cc6dfb70c88c895e4d45e0c2eb7453878038dc507d1a808ca3894c50a320b4a259df09ad7f1368a4b8c7bd790624b27baac487df1b48cf
6
+ metadata.gz: 20cb03d16e9495edd35a9323f9507780b006f0be2ef61b0423e198ada1bdcc672e7a7fc471d606bc5cd47d3f727237922285bf71dd9648381b92bc5b90327174
7
+ data.tar.gz: 977cd155d3a717af7a4fc4876694f27b665844780fadf23556cdf1d7fb120a124741c341dbf1d4725fad8a0dbe12260f7475e36d9cd7e1415618929b73fb9794
@@ -1,3 +1,10 @@
1
+ # 1.1.0 (TBD)
2
+
3
+ Added Jobs:
4
+
5
+ * b/collection/coalesce
6
+ * b/collection/group
7
+
1
8
  # 1.0.0 (November 5th, 2020)
2
9
 
3
10
  Initial version publication.
data/README.md CHANGED
@@ -234,8 +234,10 @@ This library only ships with very basic, rudimentary jobs that are meant to just
234
234
  #### Collection
235
235
 
236
236
  * **b/collection/arrays_to_objects** [mappings, register]: Convert an array of arrays to an array of objects.
237
+ * **b/collection/coalesce** [register, grouped_register, key_mappings, keys, separator]: Merge two datasets together based on the key values of one dataset (array) with a grouped dataset (hash).
237
238
  * **b/collection/concatenate** [from_registers, to_register]: Concatenate each from_register's value and place the newly concatenated array into the to_register. Note: this does not do any deep copying and should be assumed it is shallow copying all objects.
238
239
  * **b/collection/graph** [config, key, register]: Use [Hashematics](https://github.com/bluemarblepayroll/hashematics) to turn a flat array of objects into a deeply nested object tree.
240
+ * **b/collection/group** [keys, register, separator]: Take a register's value (an array of objects) and group the objects by the specified keys.
239
241
  * **b/collection/objects_to_arrays** [mappings, register]: Convert an array of objects to an array of arrays.
240
242
  * **b/collection/shift** [amount, register]: Remove the first N number of elements from an array.
241
243
  * **b/collection/transform** [attributes, exclusive, separator, register]: Iterate over all objects and transform each key per the attribute transformers specifications. If exclusive is set to false then the current object will be overridden/merged. Separator can also be set for key path support. This job uses [Realize](https://github.com/bluemarblepayroll/realize), which provides its own extendable value-transformation pipeline.
@@ -23,8 +23,10 @@ module Burner
23
23
  register 'b/sleep', Library::Sleep
24
24
 
25
25
  register 'b/collection/arrays_to_objects', Library::Collection::ArraysToObjects
26
+ register 'b/collection/coalesce', Library::Collection::Coalesce
26
27
  register 'b/collection/concatenate', Library::Collection::Concatenate
27
28
  register 'b/collection/graph', Library::Collection::Graph
29
+ register 'b/collection/group', Library::Collection::Group
28
30
  register 'b/collection/objects_to_arrays', Library::Collection::ObjectsToArrays
29
31
  register 'b/collection/shift', Library::Collection::Shift
30
32
  register 'b/collection/transform', Library::Collection::Transform
@@ -14,8 +14,10 @@ require_relative 'library/nothing'
14
14
  require_relative 'library/sleep'
15
15
 
16
16
  require_relative 'library/collection/arrays_to_objects'
17
+ require_relative 'library/collection/coalesce'
17
18
  require_relative 'library/collection/concatenate'
18
19
  require_relative 'library/collection/graph'
20
+ require_relative 'library/collection/group'
19
21
  require_relative 'library/collection/objects_to_arrays'
20
22
  require_relative 'library/collection/shift'
21
23
  require_relative 'library/collection/transform'
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Burner
11
+ module Library
12
+ module Collection
13
+ # This is generally used right after the Group job has been executed on a separate
14
+ # dataset in a separate register. This job can match up specified values in its dataset
15
+ # with lookup values in another. If it finds a match then it will (shallow) copy over
16
+ # the values into the respective dataset.
17
+ #
18
+ # Expected Payload[register] input: array of objects.
19
+ # Payload[register] output: array of objects.
20
+ class Coalesce < JobWithRegister
21
+ attr_reader :grouped_register, :key_mappings, :keys, :resolver
22
+
23
+ def initialize(
24
+ name:,
25
+ grouped_register:,
26
+ key_mappings: [],
27
+ keys: [],
28
+ register: DEFAULT_REGISTER,
29
+ separator: ''
30
+ )
31
+ super(name: name, register: register)
32
+
33
+ @grouped_register = grouped_register.to_s
34
+ @key_mappings = Modeling::KeyMapping.array(key_mappings)
35
+ @keys = Array(keys)
36
+ @resolver = Objectable.resolver(separator: separator.to_s)
37
+
38
+ raise ArgumentError, 'at least one key is required' if @keys.empty?
39
+
40
+ freeze
41
+ end
42
+
43
+ def perform(output, payload)
44
+ payload[register] = array(payload[register])
45
+ count = payload[register].length
46
+
47
+ output.detail("Coalescing based on key(s): #{keys} for #{count} records(s)")
48
+
49
+ payload[register].each do |record|
50
+ key = make_key(record)
51
+ lookup = find_lookup(payload, key)
52
+
53
+ key_mappings.each do |key_mapping|
54
+ value = resolver.get(lookup, key_mapping.from)
55
+
56
+ resolver.set(record, key_mapping.to, value)
57
+ end
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def find_lookup(payload, key)
64
+ (payload[grouped_register] || {})[key] || {}
65
+ end
66
+
67
+ def make_key(record)
68
+ keys.map { |key| resolver.get(record, key) }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -19,7 +19,8 @@ module Burner
19
19
  attr_reader :key, :groups
20
20
 
21
21
  def initialize(
22
- name:, key:,
22
+ name:,
23
+ key:,
23
24
  config: Hashematics::Configuration.new,
24
25
  register: DEFAULT_REGISTER
25
26
  )
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Burner
11
+ module Library
12
+ module Collection
13
+ # Take a register's value (an array of objects) and group the objects by the specified keys.
14
+ # It essentially creates a hash from an array. This is useful for creating a O(1) lookup
15
+ # which can then be used in conjunction with the Coalesce Job for another array of data.
16
+ #
17
+ # An example of this specific job:
18
+ #
19
+ # input: [{ id: 1, code: 'a' }, { id: 2, code: 'b' }]
20
+ # keys: [:code]
21
+ # output: { 'a' => { id: 1, code: 'a' }, 'b' => { id: 2, code: 'b' } }
22
+ #
23
+ # Expected Payload[register] input: array of objects.
24
+ # Payload[register] output: hash.
25
+ class Group < JobWithRegister
26
+ attr_reader :keys, :resolver
27
+
28
+ def initialize(
29
+ name:,
30
+ keys: [],
31
+ register: DEFAULT_REGISTER,
32
+ separator: ''
33
+ )
34
+ super(name: name, register: register)
35
+
36
+ @keys = Array(keys)
37
+ @resolver = Objectable.resolver(separator: separator.to_s)
38
+
39
+ raise ArgumentError, 'at least one key is required' if @keys.empty?
40
+
41
+ freeze
42
+ end
43
+
44
+ def perform(output, payload)
45
+ payload[register] = array(payload[register])
46
+ count = payload[register].length
47
+
48
+ output.detail("Grouping based on key(s): #{keys} for #{count} records(s)")
49
+
50
+ grouped_records = payload[register].each_with_object({}) do |record, memo|
51
+ key = make_key(record)
52
+ memo[key] = record
53
+ end
54
+
55
+ payload[register] = grouped_records
56
+ end
57
+
58
+ private
59
+
60
+ def make_key(record)
61
+ keys.map { |key| resolver.get(record, key) }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -10,4 +10,5 @@
10
10
  require_relative 'modeling/attribute'
11
11
  require_relative 'modeling/attribute_renderer'
12
12
  require_relative 'modeling/key_index_mapping'
13
+ require_relative 'modeling/key_mapping'
13
14
  require_relative 'modeling/validations'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module Burner
11
+ module Modeling
12
+ # Generic mapping from a key to another key.
13
+ class KeyMapping
14
+ acts_as_hashable
15
+
16
+ attr_reader :from, :to
17
+
18
+ def initialize(from:, to:)
19
+ raise ArgumentError, 'from is required' if from.to_s.empty?
20
+ raise ArgumentError, 'to is required' if to.to_s.empty?
21
+
22
+ @from = from.to_s
23
+ @to = to.to_s
24
+
25
+ freeze
26
+ end
27
+ end
28
+ end
29
+ end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- VERSION = '1.0.0'
11
+ VERSION = '1.1.0-alpha'
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: burner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2020-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_hashable
@@ -225,8 +225,10 @@ files:
225
225
  - lib/burner/jobs.rb
226
226
  - lib/burner/library.rb
227
227
  - lib/burner/library/collection/arrays_to_objects.rb
228
+ - lib/burner/library/collection/coalesce.rb
228
229
  - lib/burner/library/collection/concatenate.rb
229
230
  - lib/burner/library/collection/graph.rb
231
+ - lib/burner/library/collection/group.rb
230
232
  - lib/burner/library/collection/objects_to_arrays.rb
231
233
  - lib/burner/library/collection/shift.rb
232
234
  - lib/burner/library/collection/transform.rb
@@ -252,6 +254,7 @@ files:
252
254
  - lib/burner/modeling/attribute.rb
253
255
  - lib/burner/modeling/attribute_renderer.rb
254
256
  - lib/burner/modeling/key_index_mapping.rb
257
+ - lib/burner/modeling/key_mapping.rb
255
258
  - lib/burner/modeling/validations.rb
256
259
  - lib/burner/modeling/validations/base.rb
257
260
  - lib/burner/modeling/validations/blank.rb
@@ -286,9 +289,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
289
  version: '2.5'
287
290
  required_rubygems_version: !ruby/object:Gem::Requirement
288
291
  requirements:
289
- - - ">="
292
+ - - ">"
290
293
  - !ruby/object:Gem::Version
291
- version: '0'
294
+ version: 1.3.1
292
295
  requirements: []
293
296
  rubygems_version: 3.0.3
294
297
  signing_key: