pdi 1.0.0.pre.alpha

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.
@@ -0,0 +1,34 @@
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 PDI
11
+ class Spoon
12
+ # This class subclasses Ruby's StandardError and provides a mapping to custom Kitchen
13
+ # specific error codes to messages.
14
+ class KitchenError < StandardError
15
+ MESSAGES = {
16
+ '1' => 'Errors occurred during processing',
17
+ '2' => 'An unexpected error occurred during loading or running of the job',
18
+ '7' => "The job couldn't be loaded from XML or the Repository",
19
+ '8' => 'Error loading steps or plugins (error in loading one of the plugins mostly)',
20
+ '9' => 'Command line usage printing'
21
+ }.freeze
22
+
23
+ attr_reader :execution
24
+
25
+ def initialize(execution)
26
+ @execution = execution
27
+
28
+ message = MESSAGES[execution.code.to_s] || 'Unknown'
29
+
30
+ super(message)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,93 @@
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 'kitchen_error'
11
+ require_relative 'options/level'
12
+ require_relative 'options/param'
13
+ require_relative 'pan_error'
14
+
15
+ module PDI
16
+ class Spoon
17
+ # This class serves as the input for executing a transformation or job through Pan or Kitchen.
18
+ class Options
19
+ acts_as_hashable
20
+
21
+ module Type
22
+ JOB = :job
23
+ TRANSFORMATION = :transformation
24
+ end
25
+
26
+ TYPES_TO_ERRORS = {
27
+ Type::JOB => KitchenError,
28
+ Type::TRANSFORMATION => PanError
29
+ }.freeze
30
+
31
+ TYPES_TO_KEYS = {
32
+ Type::JOB => Arg::Key::JOB,
33
+ Type::TRANSFORMATION => Arg::Key::TRANS
34
+ }.freeze
35
+
36
+ attr_reader :level,
37
+ :name,
38
+ :params,
39
+ :repository,
40
+ :type
41
+
42
+ def initialize(
43
+ level: Level::BASIC,
44
+ name:,
45
+ params: {},
46
+ repository:,
47
+ type:
48
+ )
49
+ raise ArgumentError, 'name is required' if name.to_s.empty?
50
+ raise ArgumentError, 'repository is required' if repository.to_s.empty?
51
+ raise ArgumentError, 'type is required' if type.to_s.empty?
52
+
53
+ @level = constant(Level, level)
54
+ @name = name.to_s
55
+ @params = params || {}
56
+ @repository = repository.to_s
57
+ @type = constant(Type, type)
58
+
59
+ freeze
60
+ end
61
+
62
+ def to_args
63
+ base_args + param_args
64
+ end
65
+
66
+ def error_constant
67
+ TYPES_TO_ERRORS.fetch(type)
68
+ end
69
+
70
+ private
71
+
72
+ def key
73
+ TYPES_TO_KEYS.fetch(type)
74
+ end
75
+
76
+ def base_args
77
+ [
78
+ Arg.new(Arg::Key::REP, repository),
79
+ Arg.new(key, name),
80
+ Arg.new(Arg::Key::LEVEL, level)
81
+ ]
82
+ end
83
+
84
+ def param_args
85
+ params.map { |key, value| Param.new(key, value) }
86
+ end
87
+
88
+ def constant(constant, value)
89
+ constant.const_get(value.to_s.upcase.to_sym)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,68 @@
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 PDI
11
+ class Spoon
12
+ class Options
13
+ # This class can form Pentaho-specific command-line arguments.
14
+ class Arg
15
+ COLON = ':'
16
+ DOUBLE_QUOTE = '"'
17
+ EMPTY = ''
18
+ HYPHEN = '-'
19
+ SPACE = ' '
20
+
21
+ module Key
22
+ JOB = :job
23
+ LEVEL = :level
24
+ PARAM = :param
25
+ REP = :rep
26
+ TRANS = :trans
27
+ VERSION = :version
28
+ end
29
+
30
+ attr_reader :key, :value
31
+
32
+ def initialize(key, value = '')
33
+ raise ArgumentError, 'key is required' if key.to_s.empty?
34
+
35
+ @key = Key.const_get(key.to_s.upcase.to_sym)
36
+ @value = value.to_s
37
+
38
+ freeze
39
+ end
40
+
41
+ def to_s
42
+ separator = value.to_s.empty? ? EMPTY : COLON
43
+ wrapper = wrap?(key, value) ? DOUBLE_QUOTE : EMPTY
44
+ prefix = HYPHEN
45
+
46
+ "#{wrapper}#{prefix}#{key}#{separator}#{value}#{wrapper}"
47
+ end
48
+
49
+ def hash
50
+ [key, value].hash
51
+ end
52
+
53
+ def ==(other)
54
+ other.instance_of?(self.class) &&
55
+ key == other.key &&
56
+ value == other.value
57
+ end
58
+ alias eql? ==
59
+
60
+ private
61
+
62
+ def wrap?(key, value)
63
+ key.to_s.include?(SPACE) || value.to_s.include?(SPACE)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,23 @@
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 PDI
11
+ class Spoon
12
+ class Options
13
+ module Level
14
+ BASIC = 'Basic'
15
+ DETAILED = 'Detailed'
16
+ DEBUG = 'Debug'
17
+ ERROR = 'Error'
18
+ NOTHING = 'Nothing'
19
+ ROW_LEVEL = 'Rowlevel'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -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
+ require_relative 'arg'
11
+
12
+ module PDI
13
+ class Spoon
14
+ class Options
15
+ # This class sub-classes Arg and knows how to form param key-value pair arguments.
16
+ class Param < Arg
17
+ EQUALS = '='
18
+
19
+ attr_reader :key, :value
20
+
21
+ def initialize(key, value = '')
22
+ super(Key::PARAM, "#{key}#{EQUALS}#{value}")
23
+
24
+ freeze
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
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 PDI
11
+ class Spoon
12
+ # This class subclasses Ruby's StandardError and provides a mapping to custom Pan
13
+ # specific error codes to messages.
14
+ class PanError < StandardError
15
+ MESSAGES = {
16
+ '1' => 'Errors occurred during processing',
17
+ '2' => 'An unexpected error occurred during loading / running of the transformation',
18
+ '3' => 'Unable to prepare and initialize this transformation',
19
+ '7' => "The transformation couldn't be loaded from XML or the Repository",
20
+ '8' => 'Error loading steps or plugins (error in loading one of the plugins mostly)',
21
+ '9' => 'Command line usage printing'
22
+ }.freeze
23
+
24
+ attr_reader :execution
25
+
26
+ def initialize(execution)
27
+ @execution = execution
28
+
29
+ message = MESSAGES[execution.code.to_s] || 'Unknown'
30
+
31
+ super(message)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
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 PDI
11
+ class Spoon
12
+ # This class knows how to parse the output of a Pan#version call.
13
+ class Parser
14
+ NEW_LINE = "\n"
15
+
16
+ def version(string)
17
+ string.to_s
18
+ .chomp
19
+ .split(NEW_LINE)
20
+ .last
21
+ .to_s
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
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 PDI
11
+ class Spoon
12
+ # General return object for wrapping up a execution call result (execution) and
13
+ # a usable result (value)
14
+ class Result
15
+ attr_reader :execution, :value
16
+
17
+ def initialize(execution, value)
18
+ @execution = execution
19
+ @value = value
20
+
21
+ freeze
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
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 PDI
11
+ VERSION = '1.0.0-alpha'
12
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/pdi/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'pdi'
7
+ s.version = PDI::VERSION
8
+ s.summary = 'Fill out summary'
9
+
10
+ s.description = <<-DESCRIPTION
11
+ Fill out description.
12
+ DESCRIPTION
13
+
14
+ s.authors = ['Matthew Ruggio']
15
+ s.email = ['mruggio@bluemarblepayroll.com']
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.homepage = 'https://github.com/bluemarblepayroll/pdi'
20
+ s.license = 'MIT'
21
+
22
+ s.required_ruby_version = '>= 2.3.8'
23
+
24
+ s.add_dependency('acts_as_hashable', '~>1')
25
+
26
+ s.add_development_dependency('guard-rspec', '~>4.7')
27
+ s.add_development_dependency('pry', '~>0')
28
+ s.add_development_dependency('rake', '~> 13')
29
+ s.add_development_dependency('rspec')
30
+ s.add_development_dependency('rubocop', '~>0.79.0')
31
+ s.add_development_dependency('simplecov', '~>0.17.0')
32
+ s.add_development_dependency('simplecov-console', '~>0.6.0')
33
+ end
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ error(){
4
+ echo "$1" >&2
5
+ }
6
+
7
+ output(){
8
+ echo "$1"
9
+ }
10
+
11
+ output "output to stdout"
12
+ error "output to sterr"
13
+
14
+ exit 0
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ error(){
4
+ echo "$1" >&2
5
+ }
6
+
7
+ output(){
8
+ echo "$1"
9
+ }
10
+
11
+ output "output to stdout"
12
+ error "output to sterr"
13
+
14
+ exit 1
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ error(){
4
+ echo "$1" >&2
5
+ }
6
+
7
+ output(){
8
+ echo "$1"
9
+ }
10
+
11
+ output "output to stdout"
12
+ error "output to sterr"
13
+
14
+ exit 2
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ error(){
4
+ echo "$1" >&2
5
+ }
6
+
7
+ output(){
8
+ echo "$1"
9
+ }
10
+
11
+ output "output to stdout"
12
+ error "output to sterr"
13
+
14
+ exit 3