burner 1.7.0 → 1.8.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: 59c9f86d7e38af602d55db6f13473ef3943e7bb860bc531a49025c1cc42a4686
4
- data.tar.gz: 732a8127ec38ea3e4160331fa05046d9fec8e4057a48ecefb309c12821f67254
3
+ metadata.gz: 9f7acc476043a573e329d1f0dc07e3b6f8a90f456517d4b98c66ac3e370f26fe
4
+ data.tar.gz: 8317c42ba254babbb8b72c7468dab2ca132e809a812625241d8f393077a8ba2f
5
5
  SHA512:
6
- metadata.gz: 96c17f4c33e6aa21d9f6b5b075cee2d0fd456bef4b7b02c9401b9439925e2ae8b91c44ebae1e8bc1185d22215516b1f6d27ed6362760e14d8ddc069cceb8e22a
7
- data.tar.gz: 71ddb54a2f7c286adf6c457aeffbb897989fe2d0d3a1c95cfbb0e86bb69db4dcae5bc06190485e43a6655ba664d02d2fce90977d9d391597261ccf4944986aeb
6
+ metadata.gz: 93a1a11b8b7506c2e5508e9e34c34224a1b988cf49364f29a487103e331396a0852636fc83615bf53a963df29f34393e9f69fd4a66c2062ede0ec4620680a6db
7
+ data.tar.gz: c82edbbe587a36c30573720908688cebf046ef7a13c864682a16b14fd14de5e6f19bc48d676fe568ccc35cdbdae25e4c64b2f835249d819d1bc2c415c330ad45
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.6.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 1.8.0 (March 31st, 2021)
2
+
3
+ Added Jobs:
4
+
5
+ * b/param/from_register
6
+ * b/param/to_register
7
+
8
+ Other:
9
+
10
+ * Payload#param was added to access a param key's value.
11
+ * Payload#update_param was added to update a param key's value.
12
+
13
+ Internal Notes:
14
+
15
+ Payload#register and Payload#params data stores have been internally consolidated while still maintaining the same public API surface area.
1
16
 
2
17
  # 1.7.0 (January 22nd, 2021)
3
18
 
data/README.md CHANGED
@@ -297,6 +297,11 @@ By default all jobs will use the `Burner::Disks::Local` disk for its persistence
297
297
  * **b/io/row_reader** [data_key, disk, ignore_blank_path, ignore_file_not_found, path_key, register, separator]: Iterates over an array of objects, extracts a filepath from a key in each object, and attempts to load the file's content for each record. The file's content will be stored at the specified data_key. By default missing paths or files will be treated as hard errors. If you wish to ignore these then pass in true for ignore_blank_path and/or ignore_file_not_found.
298
298
  * **b/io/write** [binary, disk, path, register, supress_side_effect]: Write to a local file. The path parameter can be interpolated using `Payload#params`. If the contents are binary, pass in `binary: true` to open it up in binary+write mode. By default, written files are also logged as WrittenFile instances to the Payload#side_effects array. You can pass in supress_side_effect: true to disable this behavior.
299
299
 
300
+ #### Parameters
301
+
302
+ * **b/param/from_register** [param_key, register]: Copy the value of a register to a param key.
303
+ * **b/param/to_register** [param_key, register]: Copy the value of a param key to a register.
304
+
300
305
  #### Serialization
301
306
 
302
307
  * **b/serialize/csv** [byte_order_mark, register]: Take an array of arrays and create a CSV. You can optionally pre-pend a byte order mark, see Burner::Modeling::ByteOrderMark for acceptable options.
@@ -0,0 +1,46 @@
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
+ # Defines a key value pair data store per our library. It is basically a composite
12
+ # object around a hash with indifferent key typing.
13
+ class Data
14
+ extend Forwardable
15
+
16
+ def_delegators :internal_hash, :transform_keys
17
+
18
+ def initialize(hash = {})
19
+ @internal_hash = {}
20
+
21
+ (hash || {}).each { |k, v| self[k] = v }
22
+ end
23
+
24
+ def []=(key, value)
25
+ internal_hash[key.to_s] = value
26
+ end
27
+
28
+ def [](key)
29
+ internal_hash[key.to_s]
30
+ end
31
+
32
+ def to_h
33
+ internal_hash
34
+ end
35
+
36
+ def ==(other)
37
+ other.instance_of?(self.class) &&
38
+ to_h == other.to_h
39
+ end
40
+ alias eql? ==
41
+
42
+ private
43
+
44
+ attr_reader :internal_hash
45
+ end
46
+ end
data/lib/burner/job.rb CHANGED
@@ -46,15 +46,9 @@ module Burner
46
46
  protected
47
47
 
48
48
  def job_string_template(expression, output, payload)
49
- templatable_params = payload.params
50
- .merge(__id: output.id)
51
- .merge(templatable_register_values(payload))
49
+ templatable_params = payload.params_and_registers_hash.merge(__id: output.id)
52
50
 
53
51
  Util::StringTemplate.instance.evaluate(expression, templatable_params)
54
52
  end
55
-
56
- def templatable_register_values(payload)
57
- payload.registers.transform_keys { |key| "__#{key}_register" }
58
- end
59
53
  end
60
54
  end
data/lib/burner/jobs.rb CHANGED
@@ -48,6 +48,9 @@ module Burner
48
48
  register 'b/io/row_reader', Library::IO::RowReader
49
49
  register 'b/io/write', Library::IO::Write
50
50
 
51
+ register 'b/param/from_register', Library::Param::FromRegister
52
+ register 'b/param/to_register', Library::Param::ToRegister
53
+
51
54
  register 'b/serialize/csv', Library::Serialize::Csv
52
55
  register 'b/serialize/json', Library::Serialize::Json
53
56
  register 'b/serialize/yaml', Library::Serialize::Yaml
@@ -39,6 +39,9 @@ require_relative 'library/io/read'
39
39
  require_relative 'library/io/row_reader'
40
40
  require_relative 'library/io/write'
41
41
 
42
+ require_relative 'library/param/from_register'
43
+ require_relative 'library/param/to_register'
44
+
42
45
  require_relative 'library/serialize/csv'
43
46
  require_relative 'library/serialize/json'
44
47
  require_relative 'library/serialize/yaml'
@@ -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 Library
12
+ module Param
13
+ # Common logic shared across Param job subclasses.
14
+ class Base < JobWithRegister
15
+ BLANK = ''
16
+
17
+ attr_reader :param_key
18
+
19
+ def initialize(name: BLANK, param_key: BLANK, register: DEFAULT_REGISTER)
20
+ super(name: name, register: register)
21
+
22
+ @param_key = param_key.to_s
23
+
24
+ freeze
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
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 'base'
11
+
12
+ module Burner
13
+ module Library
14
+ module Param
15
+ # Copy a register's value into a param key. Generally speaking you should only be
16
+ # mutating registers, that way the params stay true to the passed in params for the
17
+ # pipeline. But this job is available in case a param needs to be updated.
18
+ #
19
+ # Expected Payload[register] input: anything.
20
+ # Payload.params(param_key) output: whatever value was specified in the register.
21
+ class FromRegister < Base
22
+ def perform(output, payload)
23
+ output.detail("Pushing value from register: #{register} to param: #{param_key}")
24
+
25
+ payload.update_param(param_key, payload[register])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ 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
+ require_relative 'base'
11
+
12
+ module Burner
13
+ module Library
14
+ module Param
15
+ # Copy a param key's value into a register.
16
+ #
17
+ # Expected Payload.param(param_key) input: anything.
18
+ # Payload[register] output: whatever value was specified as the param_key's value.
19
+ class ToRegister < Base
20
+ def perform(output, payload)
21
+ output.detail("Pushing value to register: #{register} from param: #{param_key}")
22
+
23
+ payload[register] = payload.param(param_key)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -7,6 +7,8 @@
7
7
  # LICENSE file in the root directory of this source tree.
8
8
  #
9
9
 
10
+ require_relative 'data'
11
+
10
12
  module Burner
11
13
  # The input for all Job#perform methods. The main notion of this object is its 'registers'
12
14
  # attribute. This registers attribute is a key-indifferent hash, accessible on Payload using
@@ -24,10 +26,15 @@ module Burner
24
26
  # The 'time' attribute is important in that it should for the replaying of pipelines and jobs.
25
27
  # Instead of having job's utilizing Time.now, Date.today, etc... they should rather opt to
26
28
  # use this value instead.
29
+ #
30
+ # The notion of params are somewhat conflated with registers here. Both are hashes and both
31
+ # serve as data stores. The difference is registers are really meant to be the shared-data
32
+ # repository across jobs, while params are, more or less, the input into the _pipeline_.
33
+ # It is debatable if mutation of the params should be allowed but the design decision was made
34
+ # early on to allow for params to be mutable albeit with registers being the preferred mutable
35
+ # store.
27
36
  class Payload
28
- attr_reader :params,
29
- :registers,
30
- :side_effects,
37
+ attr_reader :side_effects,
31
38
  :time
32
39
 
33
40
  def initialize(
@@ -36,12 +43,32 @@ module Burner
36
43
  side_effects: [],
37
44
  time: Time.now.utc
38
45
  )
39
- @params = params || {}
40
- @registers = {}
46
+ @params = Data.new(params)
47
+ @registers = Data.new(registers)
41
48
  @side_effects = side_effects || []
42
49
  @time = time || Time.now.utc
50
+ end
43
51
 
44
- add_registers(registers)
52
+ # Backwards compatibility. This allows for control over the underlying data structure
53
+ # while still maintaining the same public API as before.
54
+ def params
55
+ @params.to_h
56
+ end
57
+
58
+ # Backwards compatibility. This allows for control over the underlying data structure
59
+ # while still maintaining the same public API as before.
60
+ def registers
61
+ @registers.to_h
62
+ end
63
+
64
+ # Law of Demeter: While params is an accessible hash, it is preferred that the
65
+ # public class methods are used.
66
+ def param(key)
67
+ @params[key]
68
+ end
69
+
70
+ def update_param(key, value)
71
+ tap { @params[key] = value }
45
72
  end
46
73
 
47
74
  # Add a side effect of a job. This helps to keep track of things jobs do outside of its
@@ -52,12 +79,12 @@ module Burner
52
79
 
53
80
  # Set a register's value.
54
81
  def []=(key, value)
55
- set(key, value)
82
+ @registers[key] = value
56
83
  end
57
84
 
58
85
  # Retrieve a register's value.
59
86
  def [](key)
60
- registers[key.to_s]
87
+ @registers[key]
61
88
  end
62
89
 
63
90
  # Set halt_pipeline to true. This will indicate to the pipeline to stop all
@@ -71,14 +98,11 @@ module Burner
71
98
  @halt_pipeline || false
72
99
  end
73
100
 
74
- private
75
-
76
- def set(key, value)
77
- registers[key.to_s] = value
78
- end
101
+ def params_and_registers_hash
102
+ registers_hash = @registers.transform_keys { |key| "__#{key}_register" }
103
+ params_hash = @params.to_h
79
104
 
80
- def add_registers(registers)
81
- (registers || {}).each { |k, v| set(k, v) }
105
+ params_hash.merge(registers_hash)
82
106
  end
83
107
  end
84
108
  end
@@ -55,7 +55,7 @@ module Burner
55
55
  private
56
56
 
57
57
  def output_params(params, output)
58
- if params.keys.any?
58
+ if params.any?
59
59
  output.write('Parameters:')
60
60
  else
61
61
  output.write('No parameters passed in.')
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Burner
11
- VERSION = '1.7.0'
11
+ VERSION = '1.8.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.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_hashable
@@ -220,6 +220,7 @@ files:
220
220
  - ".gitignore"
221
221
  - ".rubocop.yml"
222
222
  - ".ruby-version"
223
+ - ".tool-versions"
223
224
  - ".travis.yml"
224
225
  - CHANGELOG.md
225
226
  - CODE_OF_CONDUCT.md
@@ -234,6 +235,7 @@ files:
234
235
  - exe/burner
235
236
  - lib/burner.rb
236
237
  - lib/burner/cli.rb
238
+ - lib/burner/data.rb
237
239
  - lib/burner/disks.rb
238
240
  - lib/burner/disks/local.rb
239
241
  - lib/burner/job.rb
@@ -266,6 +268,9 @@ files:
266
268
  - lib/burner/library/io/row_reader.rb
267
269
  - lib/burner/library/io/write.rb
268
270
  - lib/burner/library/nothing.rb
271
+ - lib/burner/library/param/base.rb
272
+ - lib/burner/library/param/from_register.rb
273
+ - lib/burner/library/param/to_register.rb
269
274
  - lib/burner/library/serialize/csv.rb
270
275
  - lib/burner/library/serialize/json.rb
271
276
  - lib/burner/library/serialize/yaml.rb
@@ -304,7 +309,7 @@ metadata:
304
309
  documentation_uri: https://www.rubydoc.info/gems/burner
305
310
  homepage_uri: https://github.com/bluemarblepayroll/burner
306
311
  source_code_uri: https://github.com/bluemarblepayroll/burner
307
- post_install_message:
312
+ post_install_message:
308
313
  rdoc_options: []
309
314
  require_paths:
310
315
  - lib
@@ -320,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
325
  version: '0'
321
326
  requirements: []
322
327
  rubygems_version: 3.0.3
323
- signing_key:
328
+ signing_key:
324
329
  specification_version: 4
325
330
  summary: Declarative and extendable processing pipeline
326
331
  test_files: []