burner 1.0.0.pre.alpha → 1.0.0.pre.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +320 -2
- data/burner.gemspec +3 -0
- data/lib/burner.rb +10 -0
- data/lib/burner/cli.rb +7 -7
- data/lib/burner/job.rb +4 -2
- data/lib/burner/jobs.rb +30 -10
- data/lib/burner/jobs/collection/arrays_to_objects.rb +43 -0
- data/lib/burner/jobs/collection/graph.rb +43 -0
- data/lib/burner/jobs/collection/objects_to_arrays.rb +54 -0
- data/lib/burner/jobs/collection/shift.rb +43 -0
- data/lib/burner/jobs/collection/transform.rb +64 -0
- data/lib/burner/jobs/collection/transform/attribute.rb +33 -0
- data/lib/burner/jobs/collection/transform/attribute_renderer.rb +36 -0
- data/lib/burner/jobs/collection/unpivot.rb +45 -0
- data/lib/burner/jobs/collection/values.rb +50 -0
- data/lib/burner/jobs/deserialize/csv.rb +28 -0
- data/lib/burner/jobs/deserialize/json.rb +1 -1
- data/lib/burner/jobs/deserialize/yaml.rb +1 -1
- data/lib/burner/jobs/dummy.rb +1 -1
- data/lib/burner/jobs/echo.rb +2 -2
- data/lib/burner/jobs/io/base.rb +3 -16
- data/lib/burner/jobs/io/exist.rb +43 -0
- data/lib/burner/jobs/io/read.rb +12 -2
- data/lib/burner/jobs/io/write.rb +25 -3
- data/lib/burner/jobs/serialize/csv.rb +38 -0
- data/lib/burner/jobs/serialize/json.rb +1 -1
- data/lib/burner/jobs/serialize/yaml.rb +1 -1
- data/lib/burner/jobs/set.rb +1 -1
- data/lib/burner/jobs/sleep.rb +1 -1
- data/lib/burner/modeling.rb +10 -0
- data/lib/burner/modeling/key_index_mapping.rb +29 -0
- data/lib/burner/payload.rb +19 -4
- data/lib/burner/pipeline.rb +10 -3
- data/lib/burner/step.rb +5 -3
- data/lib/burner/string_template.rb +6 -5
- data/lib/burner/version.rb +1 -1
- data/lib/burner/written_file.rb +28 -0
- metadata +59 -2
@@ -0,0 +1,43 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
# Convert an array of arrays to an array of objects.
|
14
|
+
# Expected Payload#value input: array of arrays.
|
15
|
+
# Payload#value output: An array of hashes.
|
16
|
+
class ArraysToObjects < Job
|
17
|
+
attr_reader :mappings
|
18
|
+
|
19
|
+
def initialize(name:, mappings: [])
|
20
|
+
super(name: name)
|
21
|
+
|
22
|
+
@mappings = Modeling::KeyIndexMapping.array(mappings)
|
23
|
+
|
24
|
+
freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
def perform(_output, payload)
|
28
|
+
payload.value = (payload.value || []).map { |array| index_to_key_map(array) }
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def index_to_key_map(array)
|
36
|
+
mappings.each_with_object({}) do |mapping, memo|
|
37
|
+
memo[mapping.key] = array[mapping.index]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
# Take an array of (denormalized) objects and create an object hierarchy from them.
|
14
|
+
# Under the hood it uses Hashematics: https://github.com/bluemarblepayroll/hashematics.
|
15
|
+
# Expected Payload#value input: array of objects.
|
16
|
+
# Payload#value output: An array of objects.
|
17
|
+
class Graph < Job
|
18
|
+
attr_reader :key, :groups
|
19
|
+
|
20
|
+
def initialize(name:, key:, config: Hashematics::Configuration.new)
|
21
|
+
super(name: name)
|
22
|
+
|
23
|
+
raise ArgumentError, 'key is required' if key.to_s.empty?
|
24
|
+
|
25
|
+
@groups = Hashematics::Configuration.new(config).groups
|
26
|
+
@key = key.to_s
|
27
|
+
|
28
|
+
freeze
|
29
|
+
end
|
30
|
+
|
31
|
+
def perform(output, payload)
|
32
|
+
graph = Hashematics::Graph.new(groups).add(payload.value || [])
|
33
|
+
|
34
|
+
output.detail("Graphing: #{key}")
|
35
|
+
|
36
|
+
payload.value = graph.data(key)
|
37
|
+
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
# Convert an array of objects to an array of arrays. You can leverage the separator
|
14
|
+
# option to support key paths and nested objects.
|
15
|
+
# Expected Payload#value input: array of hashes.
|
16
|
+
# Payload#value output: An array of arrays.
|
17
|
+
class ObjectsToArrays < Job
|
18
|
+
attr_reader :mappings
|
19
|
+
|
20
|
+
# If you wish to support nested objects you can pass in a string to use as a
|
21
|
+
# key path separator. For example: if you would like to recognize dot-notation for
|
22
|
+
# nested hashes then set separator to '.'.
|
23
|
+
def initialize(name:, mappings: [], separator: '')
|
24
|
+
super(name: name)
|
25
|
+
|
26
|
+
@mappings = Modeling::KeyIndexMapping.array(mappings)
|
27
|
+
@resolver = Objectable.resolver(separator: separator.to_s)
|
28
|
+
|
29
|
+
freeze
|
30
|
+
end
|
31
|
+
|
32
|
+
def perform(_output, payload)
|
33
|
+
payload.value = (payload.value || []).map { |object| key_to_index_map(object) }
|
34
|
+
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :resolver
|
41
|
+
|
42
|
+
def key_to_index_map(object)
|
43
|
+
mappings.each_with_object(prototype_array) do |mapping, memo|
|
44
|
+
memo[mapping.index] = resolver.get(object, mapping.key)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def prototype_array
|
49
|
+
Array.new(mappings.length)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
# Take an array and remove the first N elements, where N is specified by the amount
|
14
|
+
# attribute.
|
15
|
+
# Expected Payload#value input: nothing.
|
16
|
+
# Payload#value output: An array with N beginning elements removed.
|
17
|
+
class Shift < Job
|
18
|
+
DEFAULT_AMOUNT = 0
|
19
|
+
|
20
|
+
private_constant :DEFAULT_AMOUNT
|
21
|
+
|
22
|
+
attr_reader :amount
|
23
|
+
|
24
|
+
def initialize(name:, amount: DEFAULT_AMOUNT)
|
25
|
+
super(name: name)
|
26
|
+
|
27
|
+
@amount = amount.to_i
|
28
|
+
|
29
|
+
freeze
|
30
|
+
end
|
31
|
+
|
32
|
+
def perform(output, payload)
|
33
|
+
output.detail("Shifting #{amount} entries.")
|
34
|
+
|
35
|
+
payload.value ||= []
|
36
|
+
payload.value.shift(amount)
|
37
|
+
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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 'transform/attribute'
|
11
|
+
require_relative 'transform/attribute_renderer'
|
12
|
+
|
13
|
+
module Burner
|
14
|
+
class Jobs
|
15
|
+
module Collection
|
16
|
+
# Iterate over all objects and return a new set of transformed objects. Under the hood
|
17
|
+
# this uses the Realize library: https://github.com/bluemarblepayroll/realize
|
18
|
+
# Expected Payload#value input: array of objects.
|
19
|
+
# Payload#value output: An array of objects.
|
20
|
+
class Transform < Job
|
21
|
+
BLANK = ''
|
22
|
+
|
23
|
+
attr_reader :attribute_renderers,
|
24
|
+
:exclusive,
|
25
|
+
:resolver
|
26
|
+
|
27
|
+
def initialize(name:, attributes: [], exclusive: false, separator: BLANK)
|
28
|
+
super(name: name)
|
29
|
+
|
30
|
+
@resolver = Objectable.resolver(separator: separator)
|
31
|
+
@exclusive = exclusive || false
|
32
|
+
|
33
|
+
@attribute_renderers = Attribute.array(attributes)
|
34
|
+
.map { |a| AttributeRenderer.new(a, resolver) }
|
35
|
+
|
36
|
+
freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
def perform(output, payload)
|
40
|
+
payload.value = (payload.value || []).map { |row| transform(row, payload.time) }
|
41
|
+
|
42
|
+
attr_count = attribute_renderers.length
|
43
|
+
row_count = payload.value.length
|
44
|
+
|
45
|
+
output.detail("Transformed #{attr_count} attributes(s) for #{row_count} row(s)")
|
46
|
+
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def transform(row, time)
|
53
|
+
outgoing_row = exclusive ? {} : row
|
54
|
+
|
55
|
+
attribute_renderers.each_with_object(outgoing_row) do |attribute_renderer, memo|
|
56
|
+
value = attribute_renderer.transform(row, time)
|
57
|
+
|
58
|
+
resolver.set(memo, attribute_renderer.key, value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
class Transform < Job
|
14
|
+
# Defines a top-level key and the associated transformers for deriving the final value
|
15
|
+
# to set the key to.
|
16
|
+
class Attribute
|
17
|
+
acts_as_hashable
|
18
|
+
|
19
|
+
attr_reader :key, :transformers
|
20
|
+
|
21
|
+
def initialize(key:, transformers: [])
|
22
|
+
raise ArgumentError, 'key is required' if key.to_s.empty?
|
23
|
+
|
24
|
+
@key = key.to_s
|
25
|
+
@transformers = Realize::Transformers.array(transformers)
|
26
|
+
|
27
|
+
freeze
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -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
|
+
module Burner
|
11
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
class Transform < Job
|
14
|
+
# Composed of an Attribute instance and a Pipeline instance. It knows how to
|
15
|
+
# render/transform an Attribute. Since this library is data-first, these intermediary
|
16
|
+
# objects are necessary for non-data-centric modeling.
|
17
|
+
class AttributeRenderer
|
18
|
+
extend Forwardable
|
19
|
+
|
20
|
+
attr_reader :attribute, :pipeline
|
21
|
+
|
22
|
+
def_delegators :attribute, :key
|
23
|
+
|
24
|
+
def_delegators :pipeline, :transform
|
25
|
+
|
26
|
+
def initialize(attribute, resolver)
|
27
|
+
@attribute = attribute
|
28
|
+
@pipeline = Realize::Pipeline.new(attribute.transformers, resolver: resolver)
|
29
|
+
|
30
|
+
freeze
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
# Take an array of objects and un-pivot groups of keys into rows.
|
14
|
+
# Under the hood it uses HashMath's Unpivot class:
|
15
|
+
# https://github.com/bluemarblepayroll/hash_math
|
16
|
+
# Expected Payload#value input: array of objects.
|
17
|
+
# Payload#value output: An array of objects.
|
18
|
+
class Unpivot < Job
|
19
|
+
attr_reader :unpivot
|
20
|
+
|
21
|
+
def initialize(name:, pivot_set: HashMath::Unpivot::PivotSet.new)
|
22
|
+
super(name: name)
|
23
|
+
|
24
|
+
@unpivot = HashMath::Unpivot.new(pivot_set)
|
25
|
+
|
26
|
+
freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
def perform(output, payload)
|
30
|
+
pivot_count = unpivot.pivot_set.pivots.length
|
31
|
+
key_count = unpivot.pivot_set.pivots.map { |p| p.keys.length }.sum
|
32
|
+
object_count = payload.value&.length || 0
|
33
|
+
|
34
|
+
message = "#{pivot_count} Pivots, Key(s): #{key_count} key(s), #{object_count} objects(s)"
|
35
|
+
|
36
|
+
output.detail(message)
|
37
|
+
|
38
|
+
payload.value = (payload.value || []).flat_map { |object| unpivot.expand(object) }
|
39
|
+
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Collection
|
13
|
+
# Take an array of objects and call #values on each object.
|
14
|
+
# If include_keys is true (it is false by default), then call #keys on the first
|
15
|
+
# object and inject that as a "header" object.
|
16
|
+
# Expected Payload#value input: array of objects.
|
17
|
+
# Payload#value output: An array of arrays.
|
18
|
+
class Values < Job
|
19
|
+
attr_reader :include_keys
|
20
|
+
|
21
|
+
def initialize(name:, include_keys: false)
|
22
|
+
super(name: name)
|
23
|
+
|
24
|
+
@include_keys = include_keys || false
|
25
|
+
|
26
|
+
freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
def perform(_output, payload)
|
30
|
+
keys = include_keys ? [keys(payload.value&.first)] : []
|
31
|
+
values = (payload.value || []).map { |object| values(object) }
|
32
|
+
|
33
|
+
payload.value = keys + values
|
34
|
+
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def keys(object)
|
41
|
+
object.respond_to?(:keys) ? object.keys : []
|
42
|
+
end
|
43
|
+
|
44
|
+
def values(object)
|
45
|
+
object.respond_to?(:values) ? object.values : []
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
class Jobs
|
12
|
+
module Deserialize
|
13
|
+
# Take a CSV string and de-serialize into object(s).
|
14
|
+
# Expected Payload#value input: nothing.
|
15
|
+
# Payload#value output: an array of arrays. Each inner array represents one data row.
|
16
|
+
class Csv < Job
|
17
|
+
# This currently only supports returning an array of arrays, including the header row.
|
18
|
+
# In the future this could be extended to offer more customizable options, such as
|
19
|
+
# making it return an array of hashes with the columns mapped, etc.)
|
20
|
+
def perform(_output, payload)
|
21
|
+
payload.value = CSV.new(payload.value, headers: false).to_a
|
22
|
+
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|