burner 1.9.0.pre.alpha → 1.12.0

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: eca471b05b356ad1e96f71c0173673109622e14dc7d7d46bdab0beccc1e03396
4
- data.tar.gz: 55f81d7080c1f0eb4a4cc1d51df7534376306362a1d97a8369f3fd85c0107a3b
3
+ metadata.gz: ce126372d1a0fa7d4873cb58c354372a13a013a56f89f4814950eb497e9fb095
4
+ data.tar.gz: 0efcd55a83ef5b1c0cc716cafeae2204f4207c894419a3e40450d46e505b8ca7
5
5
  SHA512:
6
- metadata.gz: bbd76fedb82b0499f7f8913e5530a1c35e2d4fc613ef11e95fb8ad6c759a28a7f4737d5ae29a71e0409dbd8f45b03de5b96dc22b84e3b85384cb256d1742eb9c
7
- data.tar.gz: 311f81afb55fdbf5548c9394ec1ee30e020833f205e4e1c53fef87630c2e77d0b6cbd6639689efaa8956ae7bb188555f35ffb1dca7c08c2cedb6881f959cd508
6
+ metadata.gz: 5ebf524b5794577e5d287a917a52207962241ad98aa68c75069aee65d0bfeb06ae4a20af84b4ce2568449f72c2611922f69cbc130fb91b859c60f3fd28e34465
7
+ data.tar.gz: 18db46b8876228fec2357672b6abe6cf07a86434ab1595667d18c230122d2dfac3ae03cf0794a097be7fc75c42444a368a7ede5ff8207eca5defec57c6022775
data/CHANGELOG.md CHANGED
@@ -1,4 +1,26 @@
1
- # 1.9.0 (TBD)
1
+ # 1.12.0 (August 12th, 2021)
2
+
3
+ Enhanced Job:
4
+
5
+ * b/collection/flat_file_parse now supports key mappings.
6
+
7
+ Added Jobs:
8
+
9
+ * b/collection/prepend (alias for unshift)
10
+ * b/collection/unshift
11
+
12
+ # 1.11.0 (May 17th, 2021)
13
+
14
+ Added Jobs:
15
+
16
+ * b/collection/flat_file_parse
17
+
18
+ # 1.10.0 (May 17th, 2021)
19
+
20
+ Added Jobs:
21
+
22
+ * b/collection/only_keys
23
+ # 1.9.0 (April 13th, 2021)
2
24
 
3
25
  Added Jobs:
4
26
 
data/README.md CHANGED
@@ -266,16 +266,20 @@ This library only ships with very basic, rudimentary jobs that are meant to just
266
266
  * **b/collection/arrays_to_objects** [mappings, register]: Convert an array of arrays to an array of objects.
267
267
  * **b/collection/coalesce** [grouped_register, insensitive, key_mappings, keys, register, separator]: Merge two datasets together based on the key values of one dataset (array) with a grouped dataset (hash). If insensitive (false by default) is true then each key's value will be converted/coerced to a lowercase string.
268
268
  * **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.
269
+ * **b/collection/flat_file_parse** [keys_register, register, separator, key_mappings]: Map an array of arrays to an array of hashes. These keys can be realized at run-time as they are pulled from the first entry in the array. The `keys_register` will also be set to the keys used for mapping. Only keys that are mapped will be included in the `keys_register` array if `key_mappings` are defined. Otherwise all keys that are pulled from the first entry in the `register` will be included in the `keys_register`.
269
270
  * **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.
270
271
  * **b/collection/group** [insensitive, keys, register, separator]: Take a register's value (an array of objects) and group the objects by the specified keys. If insensitive (false by default) is true then each key's value will be converted/coerced to a lowercase string.
271
272
  * **b/collection/nested_aggregate** [register, key_mappings, key, separator]: Traverse a set of objects, resolving key's value for each object, optionally copying down key_mappings to the child records, then merging all the inner records together.
272
273
  * **b/collection/number** [key, register, separator, start_at]: This job can iterate over a set of records and sequence them (set the specified key to a sequential index value.)
273
274
  * **b/collection/objects_to_arrays** [mappings, register]: Convert an array of objects to an array of arrays.
275
+ * **b/collection/only_keys** [keys_register, register, separator]: Limit an array of objects' keys to a specified set of keys. These keys can be realized at run-time as they are pulled from another register (`keys_register`) thus making it dynamic.
274
276
  * **b/collection/pivot** [unique_keys, insensitive, other_keys, pivot_key, pivot_value_key, register, separator]:
275
277
  Take an array of objects and pivot a key into multiple keys. It essentially takes all the values for a key and creates N number of keys (one per value.) Under the hood it uses HashMath's [Record](https://github.com/bluemarblepayroll/hash_math#record-the-hash-prototype) and [Table](https://github.com/bluemarblepayroll/hash_math#table-the-double-hash-hash-of-hashes) classes.
278
+ * **b/collection/prepend** [from_registers, to_register]: Alias for b\collection\unshift.
276
279
  * **b/collection/shift** [amount, register]: Remove the first N number of elements from an array.
277
280
  * **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. If an attribute is not set with `explicit: true` then it will automatically start from the key's value from the record. If `explicit: true` is started, then it will start from the record itself.
278
281
  * **b/collection/unpivot** [pivot_set, register]: Take an array of objects and unpivot specific sets of keys into rows. Under the hood it uses [HashMath's Unpivot class](https://github.com/bluemarblepayroll/hash_math#unpivot-hash-key-coalescence-and-row-extrapolation).
282
+ * **b/collection/unshift** [from_registers, register]: Adds the values of the `from_registers` to the `register` array. All existing elements in the `register` array will be shifted upwards.
279
283
  * **b/collection/validate** [invalid_register, join_char, message_key, register, separator, validations]: Take an array of objects, run it through each declared validator, and split the objects into two registers. The valid objects will be split into the current register while the invalid ones will go into the invalid_register as declared. Optional arguments, join_char and message_key, help determine the compiled error messages. The separator option can be utilized to use dot-notation for validating keys. See each validation's options by viewing their classes within the `lib/modeling/validations` directory.
280
284
  * **b/collection/values** [include_keys, register]: Take an array of objects and call `#values` on each object. If include_keys is true (it is false by default), then call `#keys` on the first object and inject that as a "header" object.
281
285
  * **b/collection/zip** [base_register, register, with_register]: Combines `base_register` and `with_register`s' data to form one single array in `register`. It will combine each element, positionally in each array to form the final array. For example: ['hello', 'bugs'] + ['world', 'bunny'] => [['hello', 'world'], ['bugs', 'bunny']]
@@ -0,0 +1,36 @@
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
+ require_relative 'job_with_register'
11
+
12
+ module Burner
13
+ # Add on a register attribute to the configuration for a job. This indicates that a job
14
+ # either accesses and/or mutates the payload's registers.
15
+ class JobWithDynamicKeys < JobWithRegister
16
+ attr_reader :key_mappings,
17
+ :keys_register,
18
+ :resolver
19
+
20
+ def initialize(
21
+ keys_register:,
22
+ name: '',
23
+ register: DEFAULT_REGISTER,
24
+ separator: BLANK,
25
+ key_mappings: []
26
+ )
27
+ super(name: name, register: register)
28
+
29
+ @key_mappings = Modeling::KeyMapping.array(key_mappings)
30
+ @keys_register = keys_register.to_s
31
+ @resolver = Objectable.resolver(separator: separator)
32
+
33
+ freeze
34
+ end
35
+ end
36
+ end
@@ -13,6 +13,8 @@ module Burner
13
13
  # Add on a register attribute to the configuration for a job. This indicates that a job
14
14
  # either accesses and/or mutates the payload's registers.
15
15
  class JobWithRegister < Job
16
+ BLANK = ''
17
+
16
18
  attr_reader :register
17
19
 
18
20
  def initialize(name: '', register: DEFAULT_REGISTER)
data/lib/burner/jobs.rb CHANGED
@@ -25,15 +25,19 @@ module Burner
25
25
  register 'b/collection/arrays_to_objects', Library::Collection::ArraysToObjects
26
26
  register 'b/collection/coalesce', Library::Collection::Coalesce
27
27
  register 'b/collection/concatenate', Library::Collection::Concatenate
28
- register 'b/collection/graph', Library::Collection::Graph
29
28
  register 'b/collection/group', Library::Collection::Group
29
+ register 'b/collection/flat_file_parse', Library::Collection::FlatFileParse
30
+ register 'b/collection/graph', Library::Collection::Graph
30
31
  register 'b/collection/nested_aggregate', Library::Collection::NestedAggregate
31
32
  register 'b/collection/number', Library::Collection::Number
32
33
  register 'b/collection/objects_to_arrays', Library::Collection::ObjectsToArrays
34
+ register 'b/collection/only_keys', Library::Collection::OnlyKeys
33
35
  register 'b/collection/pivot', Library::Collection::Pivot
36
+ register 'b/collection/prepend', Library::Collection::Unshift
34
37
  register 'b/collection/shift', Library::Collection::Shift
35
38
  register 'b/collection/transform', Library::Collection::Transform
36
39
  register 'b/collection/unpivot', Library::Collection::Unpivot
40
+ register 'b/collection/unshift', Library::Collection::Unshift
37
41
  register 'b/collection/values', Library::Collection::Values
38
42
  register 'b/collection/validate', Library::Collection::Validate
39
43
  register 'b/collection/zip', Library::Collection::Zip
@@ -7,7 +7,7 @@
7
7
  # LICENSE file in the root directory of this source tree.
8
8
  #
9
9
 
10
- require_relative 'job_with_register'
10
+ require_relative 'job_with_dynamic_keys'
11
11
 
12
12
  require_relative 'library/echo'
13
13
  require_relative 'library/nothing'
@@ -16,15 +16,18 @@ require_relative 'library/sleep'
16
16
  require_relative 'library/collection/arrays_to_objects'
17
17
  require_relative 'library/collection/coalesce'
18
18
  require_relative 'library/collection/concatenate'
19
+ require_relative 'library/collection/flat_file_parse'
19
20
  require_relative 'library/collection/graph'
20
21
  require_relative 'library/collection/group'
21
22
  require_relative 'library/collection/nested_aggregate'
22
23
  require_relative 'library/collection/number'
23
24
  require_relative 'library/collection/objects_to_arrays'
25
+ require_relative 'library/collection/only_keys'
24
26
  require_relative 'library/collection/pivot'
25
27
  require_relative 'library/collection/shift'
26
28
  require_relative 'library/collection/transform'
27
29
  require_relative 'library/collection/unpivot'
30
+ require_relative 'library/collection/unshift'
28
31
  require_relative 'library/collection/validate'
29
32
  require_relative 'library/collection/values'
30
33
  require_relative 'library/collection/zip'
@@ -0,0 +1,147 @@
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
+ # Convert an array of arrays to an array of objects. The difference between this
14
+ # job and ArraysToObjects is that this one does not require mappings and instead
15
+ # will use the first entry as the array of keys to positionally map to.
16
+ # If key mappings are specified then the keys register will only contain
17
+ # the keys that are mapped. The register will still contain mapped and unmapped keys.
18
+ #
19
+ # For example, if a register had this:
20
+ #
21
+ # [['id', 'first', 'last'], [1, 'frank', 'rizzo']]
22
+ #
23
+ # Then executing this job would result in this:
24
+ #
25
+ # [{ 'id' => 1, 'first' => frank, 'last' => rizzo }]
26
+ #
27
+ # As a side-effect, the keys_register would result in this, if no key mappings were specified:
28
+ #
29
+ # ['id', 'first', 'last']
30
+ #
31
+ # If key mappings are specified:
32
+ # [
33
+ #
34
+ # {
35
+ # from: 'first',
36
+ # to: 'first_name'
37
+ # }
38
+ # {
39
+ # from: 'iban',
40
+ # to: 'iban_number'
41
+ # }
42
+ # ]
43
+ # Then the register will now be:
44
+ # [{ 'id' => 1, 'first_name' => frank, 'last' => rizzo }]
45
+ #
46
+ # And the keys_register will now contain:
47
+ # ['first_name']
48
+ #
49
+ # Since 'last' did not have a key mapping entry it does not exist in the keys register.
50
+ # In addition, even though 'iban' does have a key mapping it does not exist in the
51
+ # register's payload, so it also does not exist in the keys register.
52
+ #
53
+ # Expected Payload[register] input: array of arrays.
54
+ # Payload[register] output: An array of hashes.
55
+ # Payload[keys_register] output; An array of key names.
56
+ class FlatFileParse < JobWithDynamicKeys
57
+ def perform(output, payload)
58
+ objects = array(payload[register])
59
+ keys = array(objects.shift)
60
+ count = objects.length
61
+ mapped_keys = update_keys_using_mappings(keys, output)
62
+
63
+ payload[register] = objects.map { |object| transform(object, mapped_keys, output) }
64
+ payload[keys_register] = get_mapped_keys(mapped_keys)
65
+
66
+ output.detail("Mapping #{count} array(s)")
67
+
68
+ output.detail("Mapping keys register array to: #{payload[keys_register].join(', ')}")
69
+ end
70
+
71
+ private
72
+
73
+ def transform(object, keys, output)
74
+ object.each_with_object({}).with_index do |(value, memo), index|
75
+ next if index >= keys.length
76
+
77
+ key_hash = keys[index]
78
+
79
+ key = key_hash[:unmapped_key_name]
80
+
81
+ mapped_key = key_hash[:mapped_key_name]
82
+
83
+ key = mapped_key if mapped_key
84
+
85
+ resolver.set(memo, key, value)
86
+
87
+ output.detail("Using key #{key}")
88
+ end
89
+ end
90
+
91
+ def get_mapped_keys(mapped_keys)
92
+ mapped_keys.each_with_object([]) do |mapped_key_hash, memo|
93
+ mapped_key = mapped_key_hash[:mapped_key_name]
94
+
95
+ memo << mapped_key if mapped_key
96
+ end
97
+ end
98
+
99
+ def update_keys_using_mappings(keys, output)
100
+ if key_mappings.count.positive?
101
+ populate_key_hashes_from_mappings(keys, output)
102
+ else
103
+ populate_key_hashes_without_mappings(keys)
104
+ end
105
+ end
106
+
107
+ def populate_key_hashes_from_mappings(keys, output)
108
+ keys.each_with_object([]) do |key, memo|
109
+ mapped_key_name = find_key_name_to_use_from_mappings(key, output)
110
+
111
+ mapped_key_name = nil if key == mapped_key_name
112
+
113
+ memo << create_key_hash(key, mapped_key_name)
114
+ end
115
+ end
116
+
117
+ def populate_key_hashes_without_mappings(keys)
118
+ keys.each_with_object([]) do |key, memo|
119
+ memo << create_key_hash(key, key)
120
+ end
121
+ end
122
+
123
+ def create_key_hash(unmapped_key_name, mapped_key_name)
124
+ { unmapped_key_name: unmapped_key_name, mapped_key_name: mapped_key_name }
125
+ end
126
+
127
+ def find_key_name_to_use_from_mappings(key, output)
128
+ key_to_use = key
129
+
130
+ key_mappings.each do |key_mapping|
131
+ next unless key_mapping.from.downcase == key.downcase
132
+
133
+ key_to_use = populate_key_to_use(key_mapping)
134
+ output.detail("Using key_mapping from key #{key} to #{key_to_use}")
135
+ break
136
+ end
137
+
138
+ key_to_use
139
+ end
140
+
141
+ def populate_key_to_use(key_mapping)
142
+ key_mapping.to unless key_mapping.to.empty?
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,42 @@
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 job knows how to take an array of objects and limit it to a specific set of keys.
14
+ # The keys are pulled from another register which helps make it dynamic (you can load
15
+ # up this other register with a dynamic list of keys at run-time.)
16
+ #
17
+ # Expected Payload[register] input: array of objects.
18
+ # Payload[register] output: An array of objects.
19
+ class OnlyKeys < JobWithDynamicKeys
20
+ def perform(output, payload)
21
+ objects = array(payload[register])
22
+ count = objects.length
23
+ keys = array(payload[keys_register])
24
+
25
+ output.detail("Dynamically limiting #{count} object(s) with key(s): #{keys.join(', ')}")
26
+
27
+ payload[register] = objects.map { |object| transform(object, keys) }
28
+ end
29
+
30
+ private
31
+
32
+ def transform(object, keys)
33
+ keys.each_with_object({}) do |key, memo|
34
+ value = resolver.get(object, key)
35
+
36
+ resolver.set(memo, key, value)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -21,8 +21,6 @@ module Burner
21
21
  # Expected Payload[register] input: array of objects.
22
22
  # Payload[register] output: An array of objects.
23
23
  class Transform < JobWithRegister
24
- BLANK = ''
25
-
26
24
  attr_reader :attribute_renderers,
27
25
  :exclusive,
28
26
  :resolver
@@ -0,0 +1,45 @@
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
+ # Adds the values of the from_registers to the to_register array.
14
+ # All existing elements in the register array will be shifted upwards.
15
+ #
16
+ # Expected Payload[from_registers] input: Array containing names of registers
17
+ # whose values to prepend.
18
+ # Payload[register] output: An array with the from_registers'
19
+ # payload added to the beginning.
20
+ class Unshift < JobWithRegister
21
+ attr_reader :from_registers
22
+
23
+ def initialize(from_registers: [], name: '', register: DEFAULT_REGISTER)
24
+ super(name: name, register: register)
25
+
26
+ @from_registers = Array(from_registers)
27
+
28
+ freeze
29
+ end
30
+
31
+ def perform(output, payload)
32
+ output.detail("Prepending registers: '#{from_registers}' to: '#{register}'")
33
+
34
+ payload_register = array(payload[register])
35
+
36
+ from_registers.each do |from_register|
37
+ from_register_value = payload[from_register]
38
+
39
+ payload_register.unshift(from_register_value)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -12,8 +12,6 @@ module Burner
12
12
  module Param
13
13
  # Common logic shared across Param job subclasses.
14
14
  class Base < JobWithRegister
15
- BLANK = ''
16
-
17
15
  attr_reader :param_key
18
16
 
19
17
  def initialize(name: BLANK, param_key: BLANK, register: DEFAULT_REGISTER)
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- VERSION = '1.9.0-alpha'
11
+ VERSION = '1.12.0'
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.9.0.pre.alpha
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-13 00:00:00.000000000 Z
11
+ date: 2021-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_hashable
@@ -240,21 +240,25 @@ files:
240
240
  - lib/burner/disks/local.rb
241
241
  - lib/burner/job.rb
242
242
  - lib/burner/job_set.rb
243
+ - lib/burner/job_with_dynamic_keys.rb
243
244
  - lib/burner/job_with_register.rb
244
245
  - lib/burner/jobs.rb
245
246
  - lib/burner/library.rb
246
247
  - lib/burner/library/collection/arrays_to_objects.rb
247
248
  - lib/burner/library/collection/coalesce.rb
248
249
  - lib/burner/library/collection/concatenate.rb
250
+ - lib/burner/library/collection/flat_file_parse.rb
249
251
  - lib/burner/library/collection/graph.rb
250
252
  - lib/burner/library/collection/group.rb
251
253
  - lib/burner/library/collection/nested_aggregate.rb
252
254
  - lib/burner/library/collection/number.rb
253
255
  - lib/burner/library/collection/objects_to_arrays.rb
256
+ - lib/burner/library/collection/only_keys.rb
254
257
  - lib/burner/library/collection/pivot.rb
255
258
  - lib/burner/library/collection/shift.rb
256
259
  - lib/burner/library/collection/transform.rb
257
260
  - lib/burner/library/collection/unpivot.rb
261
+ - lib/burner/library/collection/unshift.rb
258
262
  - lib/burner/library/collection/validate.rb
259
263
  - lib/burner/library/collection/values.rb
260
264
  - lib/burner/library/collection/zip.rb
@@ -321,9 +325,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
325
  version: '2.5'
322
326
  required_rubygems_version: !ruby/object:Gem::Requirement
323
327
  requirements:
324
- - - ">"
328
+ - - ">="
325
329
  - !ruby/object:Gem::Version
326
- version: 1.3.1
330
+ version: '0'
327
331
  requirements: []
328
332
  rubygems_version: 3.0.3
329
333
  signing_key: