burner 1.0.0.pre.alpha.2 → 1.0.0.pre.alpha.7

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/README.md +57 -25
  4. data/burner.gemspec +3 -0
  5. data/exe/burner +2 -3
  6. data/lib/burner.rb +11 -0
  7. data/lib/burner/cli.rb +11 -9
  8. data/lib/burner/job.rb +29 -9
  9. data/lib/burner/job_with_register.rb +24 -0
  10. data/lib/burner/jobs.rb +21 -23
  11. data/lib/burner/library.rb +32 -0
  12. data/lib/burner/library/collection/arrays_to_objects.rb +75 -0
  13. data/lib/burner/library/collection/graph.rb +42 -0
  14. data/lib/burner/library/collection/objects_to_arrays.rb +88 -0
  15. data/lib/burner/library/collection/shift.rb +42 -0
  16. data/lib/burner/library/collection/transform.rb +66 -0
  17. data/lib/burner/library/collection/unpivot.rb +53 -0
  18. data/lib/burner/library/collection/validate.rb +89 -0
  19. data/lib/burner/library/collection/values.rb +49 -0
  20. data/lib/burner/library/deserialize/csv.rb +27 -0
  21. data/lib/burner/{jobs → library}/deserialize/json.rb +7 -6
  22. data/lib/burner/{jobs → library}/deserialize/yaml.rb +14 -8
  23. data/lib/burner/{jobs → library}/dummy.rb +4 -4
  24. data/lib/burner/{jobs → library}/echo.rb +5 -5
  25. data/lib/burner/{jobs → library}/io/base.rb +4 -10
  26. data/lib/burner/{jobs → library}/io/exist.rb +13 -11
  27. data/lib/burner/{jobs → library}/io/read.rb +9 -8
  28. data/lib/burner/{jobs → library}/io/write.rb +11 -8
  29. data/lib/burner/library/serialize/csv.rb +37 -0
  30. data/lib/burner/{jobs → library}/serialize/json.rb +7 -6
  31. data/lib/burner/{jobs → library}/serialize/yaml.rb +7 -6
  32. data/lib/burner/{jobs/set.rb → library/set_value.rb} +9 -8
  33. data/lib/burner/{jobs → library}/sleep.rb +4 -4
  34. data/lib/burner/modeling.rb +13 -0
  35. data/lib/burner/modeling/attribute.rb +29 -0
  36. data/lib/burner/modeling/attribute_renderer.rb +32 -0
  37. data/lib/burner/modeling/key_index_mapping.rb +29 -0
  38. data/lib/burner/modeling/validations.rb +23 -0
  39. data/lib/burner/modeling/validations/base.rb +35 -0
  40. data/lib/burner/modeling/validations/blank.rb +31 -0
  41. data/lib/burner/modeling/validations/present.rb +31 -0
  42. data/lib/burner/payload.rb +55 -10
  43. data/lib/burner/pipeline.rb +25 -6
  44. data/lib/burner/side_effects.rb +10 -0
  45. data/lib/burner/side_effects/written_file.rb +28 -0
  46. data/lib/burner/step.rb +2 -8
  47. data/lib/burner/util.rb +11 -0
  48. data/lib/burner/util/arrayable.rb +30 -0
  49. data/lib/burner/util/string_template.rb +42 -0
  50. data/lib/burner/version.rb +1 -1
  51. metadata +81 -16
  52. data/lib/burner/string_template.rb +0 -40
  53. data/lib/burner/written_file.rb +0 -28
@@ -8,14 +8,15 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  module Deserialize
13
13
  # Take a JSON string and deserialize into object(s).
14
- class Json < Job
15
- def perform(_output, payload, _params)
16
- payload.value = JSON.parse(payload.value)
17
-
18
- nil
14
+ #
15
+ # Expected Payload#value input: string of JSON data.
16
+ # Payload#value output: anything, as specified by the JSON de-serializer.
17
+ class Json < JobWithRegister
18
+ def perform(_output, payload)
19
+ payload[register] = JSON.parse(payload[register])
19
20
  end
20
21
  end
21
22
  end
@@ -8,14 +8,20 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  module Deserialize
13
- # Take a YAML string and deserialize into object(s).
14
- class Yaml < Job
13
+ # Take a YAML string and deserialize into object(s). It uses YAML#safe_load by default,
14
+ # which ensures only a limited number of Ruby object constants can be hydrated by the
15
+ # YAML. If you wish to ease this restriction, for example if you have custom serialization
16
+ # for custom classes, then you can pass in safe: false.
17
+ #
18
+ # Expected Payload#value input: string of YAML data.
19
+ # Payload#value output: anything as specified by the YAML de-serializer.
20
+ class Yaml < JobWithRegister
15
21
  attr_reader :safe
16
22
 
17
- def initialize(name:, safe: true)
18
- super(name: name)
23
+ def initialize(name:, register: '', safe: true)
24
+ super(name: name, register: register)
19
25
 
20
26
  @safe = safe
21
27
 
@@ -27,12 +33,12 @@ module Burner
27
33
  # in a sandbox. By default, though, we will try and drive them towards using it
28
34
  # in the safer alternative.
29
35
  # rubocop:disable Security/YAMLLoad
30
- def perform(output, payload, _params)
36
+ def perform(output, payload)
31
37
  output.detail('Warning: loading YAML not using safe_load.') unless safe
32
38
 
33
- payload.value = safe ? YAML.safe_load(payload.value) : YAML.load(payload.value)
39
+ value = payload[register]
34
40
 
35
- nil
41
+ payload[register] = safe ? YAML.safe_load(value) : YAML.load(value)
36
42
  end
37
43
  # rubocop:enable Security/YAMLLoad
38
44
  end
@@ -8,12 +8,12 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  # Do nothing.
13
+ #
14
+ # Note: this does not use Payload#value.
13
15
  class Dummy < Job
14
- def perform(_output, _payload, _params)
15
- nil
16
- end
16
+ def perform(_output, _payload); end
17
17
  end
18
18
  end
19
19
  end
@@ -8,8 +8,10 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  # Output a simple message to the output.
13
+ #
14
+ # Note: this does not use Payload#value.
13
15
  class Echo < Job
14
16
  attr_reader :message
15
17
 
@@ -21,12 +23,10 @@ module Burner
21
23
  freeze
22
24
  end
23
25
 
24
- def perform(output, _payload, params)
25
- compiled_message = eval_string_template(message, params)
26
+ def perform(output, payload)
27
+ compiled_message = job_string_template(message, output, payload)
26
28
 
27
29
  output.detail(compiled_message)
28
-
29
- nil
30
30
  end
31
31
  end
32
32
  end
@@ -8,25 +8,19 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  module IO
13
13
  # Common configuration/code for all IO Job subclasses.
14
- class Base < Job
14
+ class Base < JobWithRegister
15
15
  attr_reader :path
16
16
 
17
- def initialize(name:, path:)
18
- super(name: name)
17
+ def initialize(name:, path:, register: '')
18
+ super(name: name, register: register)
19
19
 
20
20
  raise ArgumentError, 'path is required' if path.to_s.empty?
21
21
 
22
22
  @path = path.to_s
23
23
  end
24
-
25
- private
26
-
27
- def compile_path(params)
28
- eval_string_template(path, params)
29
- end
30
24
  end
31
25
  end
32
26
  end
@@ -10,32 +10,34 @@
10
10
  require_relative 'base'
11
11
 
12
12
  module Burner
13
- class Jobs
13
+ module Library
14
14
  module IO
15
15
  # Check to see if a file exists. If short_circuit is set to true and the file
16
16
  # does not exist then the job will return false and short circuit the pipeline.
17
- class Exist < Base
18
- attr_reader :short_circuit
17
+ #
18
+ # Note: this does not use Payload#value.
19
+ class Exist < Job
20
+ attr_reader :path, :short_circuit
19
21
 
20
22
  def initialize(name:, path:, short_circuit: false)
21
- super(name: name, path: path)
23
+ super(name: name)
22
24
 
23
- @short_circuit = short_circuit || false
25
+ raise ArgumentError, 'path is required' if path.to_s.empty?
24
26
 
25
- freeze
27
+ @path = path.to_s
28
+ @short_circuit = short_circuit || false
26
29
  end
27
30
 
28
- def perform(output, _payload, params)
29
- compiled_path = compile_path(params)
31
+ def perform(output, payload)
32
+ compiled_path = job_string_template(path, output, payload)
30
33
 
31
34
  exists = File.exist?(compiled_path)
32
35
  verb = exists ? 'does' : 'does not'
33
36
 
34
37
  output.detail("The path: #{compiled_path} #{verb} exist")
35
38
 
36
- # if anything but false is returned then the pipeline will not short circuit. So
37
- # we need to make sure we explicitly return false.
38
- short_circuit && !exists ? false : nil
39
+ # if anything but false is returned then the pipeline will not short circuit.
40
+ payload.halt_pipeline if short_circuit && !exists
39
41
  end
40
42
  end
41
43
  end
@@ -10,28 +10,29 @@
10
10
  require_relative 'base'
11
11
 
12
12
  module Burner
13
- class Jobs
13
+ module Library
14
14
  module IO
15
15
  # Read value from disk.
16
+ #
17
+ # Expected Payload#value input: nothing.
18
+ # Payload#value output: contents of the specified file.
16
19
  class Read < Base
17
20
  attr_reader :binary
18
21
 
19
- def initialize(name:, path:, binary: false)
20
- super(name: name, path: path)
22
+ def initialize(name:, path:, binary: false, register: '')
23
+ super(name: name, path: path, register: register)
21
24
 
22
25
  @binary = binary || false
23
26
 
24
27
  freeze
25
28
  end
26
29
 
27
- def perform(output, payload, params)
28
- compiled_path = compile_path(params)
30
+ def perform(output, payload)
31
+ compiled_path = job_string_template(path, output, payload)
29
32
 
30
33
  output.detail("Reading: #{compiled_path}")
31
34
 
32
- payload.value = File.open(compiled_path, mode, &:read)
33
-
34
- nil
35
+ payload[register] = File.open(compiled_path, mode, &:read)
35
36
  end
36
37
 
37
38
  private
@@ -10,38 +10,41 @@
10
10
  require_relative 'base'
11
11
 
12
12
  module Burner
13
- class Jobs
13
+ module Library
14
14
  module IO
15
15
  # Write value to disk.
16
+ #
17
+ # Expected Payload#value input: anything.
18
+ # Payload#value output: whatever was passed in.
16
19
  class Write < Base
17
20
  attr_reader :binary
18
21
 
19
- def initialize(name:, path:, binary: false)
20
- super(name: name, path: path)
22
+ def initialize(name:, path:, binary: false, register: '')
23
+ super(name: name, path: path, register: register)
21
24
 
22
25
  @binary = binary || false
23
26
 
24
27
  freeze
25
28
  end
26
29
 
27
- def perform(output, payload, params)
28
- compiled_path = compile_path(params)
30
+ def perform(output, payload)
31
+ compiled_path = job_string_template(path, output, payload)
29
32
 
30
33
  ensure_directory_exists(output, compiled_path)
31
34
 
32
35
  output.detail("Writing: #{compiled_path}")
33
36
 
34
37
  time_in_seconds = Benchmark.measure do
35
- File.open(compiled_path, mode) { |io| io.write(payload.value) }
38
+ File.open(compiled_path, mode) { |io| io.write(payload[register]) }
36
39
  end.real
37
40
 
38
- payload.add_written_file(
41
+ side_effect = SideEffects::WrittenFile.new(
39
42
  logical_filename: compiled_path,
40
43
  physical_filename: compiled_path,
41
44
  time_in_seconds: time_in_seconds
42
45
  )
43
46
 
44
- nil
47
+ payload.add_side_effect(side_effect)
45
48
  end
46
49
 
47
50
  private
@@ -0,0 +1,37 @@
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 Serialize
13
+ # Take an array of arrays and create a CSV.
14
+ #
15
+ # Expected Payload#value input: array of arrays.
16
+ # Payload#value output: a serialized CSV string.
17
+ class Csv < JobWithRegister
18
+ def perform(_output, payload)
19
+ payload[register] = CSV.generate(options) do |csv|
20
+ array(payload[register]).each do |row|
21
+ csv << row
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def options
29
+ {
30
+ headers: false,
31
+ write_headers: false
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -8,14 +8,15 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  module Serialize
13
13
  # Treat value like a Ruby object and serialize it using JSON.
14
- class Json < Job
15
- def perform(_output, payload, _params)
16
- payload.value = payload.value.to_json
17
-
18
- nil
14
+ #
15
+ # Expected Payload#value input: anything.
16
+ # Payload#value output: string representing the output of the JSON serializer.
17
+ class Json < JobWithRegister
18
+ def perform(_output, payload)
19
+ payload[register] = payload[register].to_json
19
20
  end
20
21
  end
21
22
  end
@@ -8,14 +8,15 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  module Serialize
13
13
  # Treat value like a Ruby object and serialize it using YAML.
14
- class Yaml < Job
15
- def perform(_output, payload, _params)
16
- payload.value = payload.value.to_yaml
17
-
18
- nil
14
+ #
15
+ # Expected Payload#value input: anything.
16
+ # Payload#value output: string representing the output of the YAML serializer.
17
+ class Yaml < JobWithRegister
18
+ def perform(_output, payload)
19
+ payload[register] = payload[register].to_yaml
19
20
  end
20
21
  end
21
22
  end
@@ -8,23 +8,24 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  # Arbitrarily set value
13
- class Set < Job
13
+ #
14
+ # Expected Payload#value input: anything.
15
+ # Payload#value output: whatever value was specified in this job.
16
+ class SetValue < JobWithRegister
14
17
  attr_reader :value
15
18
 
16
- def initialize(name:, value: nil)
17
- super(name: name)
19
+ def initialize(name:, register: '', value: nil)
20
+ super(name: name, register: register)
18
21
 
19
22
  @value = value
20
23
 
21
24
  freeze
22
25
  end
23
26
 
24
- def perform(_output, payload, _params)
25
- payload.value = value
26
-
27
- nil
27
+ def perform(_output, payload)
28
+ payload[register] = value
28
29
  end
29
30
  end
30
31
  end
@@ -8,8 +8,10 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- class Jobs
11
+ module Library
12
12
  # Arbitrarily put thread to sleep for X number of seconds
13
+ #
14
+ # Payload#value output: whatever value was specified in this job.
13
15
  class Sleep < Job
14
16
  attr_reader :seconds
15
17
 
@@ -21,12 +23,10 @@ module Burner
21
23
  freeze
22
24
  end
23
25
 
24
- def perform(output, _payload, _params)
26
+ def perform(output, _payload)
25
27
  output.detail("Going to sleep for #{seconds} second(s)")
26
28
 
27
29
  Kernel.sleep(seconds)
28
-
29
- nil
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,13 @@
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 'modeling/attribute'
11
+ require_relative 'modeling/attribute_renderer'
12
+ require_relative 'modeling/key_index_mapping'
13
+ 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
+ # Defines a top-level key and the associated transformers for deriving the final value
13
+ # to set the key to.
14
+ class Attribute
15
+ acts_as_hashable
16
+
17
+ attr_reader :key, :transformers
18
+
19
+ def initialize(key:, transformers: [])
20
+ raise ArgumentError, 'key is required' if key.to_s.empty?
21
+
22
+ @key = key.to_s
23
+ @transformers = Realize::Transformers.array(transformers)
24
+
25
+ freeze
26
+ end
27
+ end
28
+ end
29
+ end