eco-helpers 3.0.37 → 3.1.1

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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +116 -1
  4. data/lib/eco/api/common/loaders/base.rb +2 -2
  5. data/lib/eco/api/common/loaders/case_base.rb +2 -0
  6. data/lib/eco/api/common/loaders/config/block.rb +78 -0
  7. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +39 -7
  8. data/lib/eco/api/common/loaders/config.rb +3 -26
  9. data/lib/eco/api/common/loaders/error_handler.rb +2 -0
  10. data/lib/eco/api/common/loaders/parser.rb +1 -4
  11. data/lib/eco/api/common/people/entries.rb +23 -6
  12. data/lib/eco/api/common/people/entry_factory.rb +1 -1
  13. data/lib/eco/api/common/people/person_entry.rb +104 -27
  14. data/lib/eco/api/common/people/person_parser.rb +50 -16
  15. data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
  16. data/lib/eco/api/common/session/base_session.rb +75 -81
  17. data/lib/eco/api/common/session/environment.rb +49 -55
  18. data/lib/eco/api/common/session/file_manager.rb +132 -135
  19. data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
  20. data/lib/eco/api/common/session/helpers.rb +10 -15
  21. data/lib/eco/api/common/session/logger/cache.rb +89 -96
  22. data/lib/eco/api/common/session/logger/channels.rb +24 -32
  23. data/lib/eco/api/common/session/logger/log.rb +38 -46
  24. data/lib/eco/api/common/session/logger.rb +50 -54
  25. data/lib/eco/api/common/session/mailer/aws_provider.rb +63 -71
  26. data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
  27. data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
  28. data/lib/eco/api/common/session/mailer.rb +78 -83
  29. data/lib/eco/api/common/session/s3_uploader.rb +132 -138
  30. data/lib/eco/api/common/session/sftp.rb +202 -208
  31. data/lib/eco/api/common.rb +0 -3
  32. data/lib/eco/api/custom/mailer.rb +4 -2
  33. data/lib/eco/api/error/handlers.rb +1 -1
  34. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
  35. data/lib/eco/api/microcases/people/manage/search.rb +1 -1
  36. data/lib/eco/api/organization/people/similarity.rb +3 -3
  37. data/lib/eco/api/session/batch/base_policy.rb +42 -27
  38. data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
  39. data/lib/eco/api/session/batch/launcher.rb +16 -3
  40. data/lib/eco/api/session/config/api.rb +4 -3
  41. data/lib/eco/api/session/config/apis/one_off.rb +1 -1
  42. data/lib/eco/api/session/config/files.rb +13 -12
  43. data/lib/eco/api/session/config/workflow.rb +1 -373
  44. data/lib/eco/api/session/config.rb +30 -9
  45. data/lib/eco/api/usecases/base_case/model.rb +6 -6
  46. data/lib/eco/api/usecases/base_case.rb +1 -1
  47. data/lib/eco/api/usecases/cli.rb +1 -1
  48. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +8 -9
  49. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
  50. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  51. data/lib/eco/api/usecases/lib/base/env.rb +21 -23
  52. data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
  53. data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
  54. data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
  55. data/lib/eco/api/usecases/lib/files.rb +1 -0
  56. data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
  57. data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
  58. data/lib/eco/api/usecases/lib/locations.rb +7 -0
  59. data/lib/eco/api/usecases/lib/people/base.rb +20 -0
  60. data/lib/eco/api/usecases/lib/people.rb +6 -0
  61. data/lib/eco/api/usecases/lib.rb +2 -0
  62. data/lib/eco/api/usecases/ooze_cases.rb +1 -1
  63. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +1 -0
  64. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +1 -0
  65. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
  66. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
  67. data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
  68. data/lib/eco/api/usecases/service/sftp.rb +7 -1
  69. data/lib/eco/api/usecases/use_case.rb +3 -2
  70. data/lib/eco/api/usecases/workflow.rb +5 -0
  71. data/lib/eco/api/usecases.rb +12 -5
  72. data/lib/eco/cli/scripting/args_helpers.rb +1 -9
  73. data/lib/eco/cli_default/options.rb +98 -68
  74. data/lib/eco/cli_default/workflow/end.rb +22 -0
  75. data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
  76. data/lib/eco/cli_default/workflow/load/data.rb +27 -0
  77. data/lib/eco/cli_default/workflow/load/input.rb +28 -0
  78. data/lib/eco/cli_default/workflow/load.rb +13 -0
  79. data/lib/eco/cli_default/workflow/options.rb +10 -0
  80. data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
  81. data/lib/eco/cli_default/workflow/report.rb +17 -0
  82. data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
  83. data/lib/eco/cli_default/workflow/usecases.rb +23 -0
  84. data/lib/eco/cli_default/workflow.rb +24 -180
  85. data/lib/eco/data/count_trace.rb +51 -0
  86. data/lib/eco/data/files/content.rb +39 -0
  87. data/lib/eco/data/files/directory.rb +78 -45
  88. data/lib/eco/data/files/encoding.rb +12 -21
  89. data/lib/eco/data/files/file_pattern.rb +15 -8
  90. data/lib/eco/data/files/folder.rb +196 -0
  91. data/lib/eco/data/files/relative_path.rb +54 -0
  92. data/lib/eco/data/files/timestamp.rb +18 -0
  93. data/lib/eco/data/files.rb +46 -5
  94. data/lib/eco/data/fuzzy_match.rb +1 -1
  95. data/lib/eco/data/hashes/array_diff.rb +11 -5
  96. data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
  97. data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
  98. data/lib/eco/data/mapper.rb +5 -1
  99. data/lib/eco/data.rb +1 -0
  100. data/lib/eco/language/delegation/delegating_missing.rb +1 -1
  101. data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
  102. data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
  103. data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
  104. data/lib/eco/language/klass/auto_loader.rb +129 -0
  105. data/lib/eco/language/klass/builder.rb +6 -6
  106. data/lib/eco/language/klass/const.rb +19 -0
  107. data/lib/eco/language/klass/helpers_built.rb +3 -1
  108. data/lib/eco/language/klass/hierarchy.rb +5 -1
  109. data/lib/eco/language/klass/naming.rb +5 -2
  110. data/lib/eco/language/klass/resolver.rb +21 -6
  111. data/lib/eco/language/klass/uid.rb +12 -0
  112. data/lib/eco/language/klass/when_inherited.rb +30 -6
  113. data/lib/eco/language/klass.rb +5 -2
  114. data/lib/eco/language/methods/access_modifier.rb +23 -0
  115. data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
  116. data/lib/eco/language/methods.rb +1 -0
  117. data/lib/eco/language/models/hierarchy.rb +41 -0
  118. data/lib/eco/language/models/workflow.rb +385 -0
  119. data/lib/eco/language/models.rb +2 -1
  120. data/lib/eco/version.rb +1 -1
  121. metadata +31 -7
  122. data/lib/eco/api/common/class_auto_loader.rb +0 -114
  123. data/lib/eco/api/common/class_helpers.rb +0 -9
  124. data/lib/eco/api/common/class_hierarchy.rb +0 -45
  125. data/lib/eco/data/files/helpers.rb +0 -152
  126. data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -1,152 +0,0 @@
1
- # rubocop:disable Style/SpecialGlobalVars
2
- module Eco
3
- module Data
4
- module Files
5
- DEFAULT_TIMESTAMP_PATTERN = '%Y-%m-%dT%H%M%S'.freeze
6
-
7
- class << self
8
- def included(base)
9
- super
10
-
11
- base.send :include, InstanceMethods
12
- base.extend ClassMethods
13
- end
14
- end
15
-
16
- module InstanceMethods
17
- include Eco::Language::AuxiliarLogger
18
- include Eco::Data::Files::Encoding
19
-
20
- # It offers a resilient way to read content from a file
21
- # @tolerance [Integer] the number of allowed encoding errors.
22
- # @return [String] the content of the file
23
- def get_file_content(file, encoding: nil, tolerance: 5)
24
- read_with_tolerance(file, encoding: encoding, tolerance: tolerance)
25
- end
26
-
27
- def read_with_tolerance(file, encoding:, tolerance: 5)
28
- content = get_file_content_with_encoding(file, encoding: encoding)
29
- return nil unless content
30
-
31
- content.scrub do |bytes|
32
- replacement = "<#{bytes.unpack1('H*')}>"
33
-
34
- if tolerance <= 0
35
- log(:error) {
36
- "There were more than 5 encoding errors in the file '#{file}'."
37
- }
38
- return content
39
- else
40
- tolerance -= 1
41
- log(:error) {
42
- "Encoding problem in file '#{file}': '#{replacement}'."
43
- }
44
- replacement
45
- end
46
- end
47
- end
48
- end
49
-
50
- module ClassMethods
51
- include Eco::Data::Files::Encoding
52
-
53
- def create_directory(path, includes_file: false)
54
- Directory.create(path, includes_file: includes_file)
55
- end
56
-
57
- def split(path)
58
- dir_path, file = File.split(path)
59
- dir_path = dir_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
60
- dir_path.split(File::ALT_SEPARATOR || File::SEPARATOR).push(file)
61
- end
62
-
63
- def file_name(fullname)
64
- return nil unless fullname
65
-
66
- File.basename(fullname)
67
- end
68
-
69
- def file_basename(fullname)
70
- return nil unless fullname
71
-
72
- File.basename(fullname, File.extname(fullname))
73
- end
74
-
75
- def file_fullpath(fullname)
76
- return nil unless fullname
77
-
78
- File.dirname(File.expand_path(fullname))
79
- end
80
-
81
- def file_exists?(file)
82
- return false unless file
83
-
84
- File.exist?(file) || File.exist?(File.expand_path(file))
85
- end
86
-
87
- def dir_exists?(path)
88
- Dir.exist?(path) || Dir.exist?(File.expand_path(path))
89
- end
90
-
91
- def timestamp(timestamp_pattern = DEFAULT_TIMESTAMP_PATTERN, date = Time.now)
92
- date.strftime(timestamp_pattern)
93
- end
94
-
95
- def timestamp_file(filename, timestamp_pattern = DEFAULT_TIMESTAMP_PATTERN)
96
- file_pattern = Eco::Data::Files::FilePattern.new(filename)
97
- file_pattern.resolve(start: timestamp(timestamp_pattern) + '_') # rubocop:disable Style/StringConcatenation
98
- end
99
-
100
- def copy_file(source_file, dest_file, time_stamp: false)
101
- dest_file = timestamp_file(dest_file) if time_stamp
102
- File.write(dest_file, File.read(source_file))
103
- end
104
-
105
- def file_empty?(path)
106
- return true unless File.file?(path)
107
-
108
- File.empty?(path)
109
- end
110
-
111
- def script_subfolder
112
- basename = File.basename($0, File.extname($0))
113
- path = File.dirname($0)
114
- File.join(path, basename)
115
- end
116
-
117
- def folder_files(folder = '.', pattern = '*', regexp: nil, older_than: nil)
118
- return [] unless folder.is_a?(String)
119
-
120
- target = File.join(File.expand_path(folder), pattern)
121
-
122
- Dir[target].tap do |dir_files|
123
- dir_files.select! {|f| File.file?(f)}
124
-
125
- if older_than
126
- dir_files.select! do |f|
127
- File.mtime(f) < (Time.now - (60*60*24*older_than))
128
- end
129
- end
130
-
131
- if regexp.is_a?(Regexp)
132
- dir_files.select! do |f|
133
- File.basename(f).match(regexp)
134
- end
135
- end
136
- end.sort
137
- end
138
-
139
- def csv_files(folder = '.', regexp: nil, older_than: nil)
140
- folder_files(folder, '*.csv', regexp: regexp, older_than: older_than).sort
141
- end
142
- end
143
-
144
- class << self
145
- include Files::InstanceMethods
146
- include Files::ClassMethods
147
- end
148
- end
149
- end
150
- end
151
-
152
- # rubocop:enable Style/SpecialGlobalVars
@@ -1,136 +0,0 @@
1
- module Eco
2
- module Language
3
- module Models
4
- module ClassHelpers
5
- NOT_USED = 'no_used!'.freeze
6
-
7
- def redef_without_warning(const, value)
8
- self.class.send(:remove_const, const) if self.class.const_defined?(const)
9
- self.class.const_set(const, value)
10
- end
11
-
12
- def class_resolver(name, klass)
13
- define_singleton_method(name) { resolve_class(klass) }
14
- define_method(name) { self.class.resolve_class(klass) }
15
- end
16
-
17
- # Class resolver
18
- # @note it caches the resolved `klass`es
19
- # @raise [Exception] when could not resolve if `exception` is `true`
20
- # @param klass [Class, String, Symbol] the class to resolve
21
- # @param source_class [Class] when the reference to `klass` belongs to a different inheritance chain.
22
- # @param exception [Boolean] if it should raise exception when could not resolve
23
- # @return [Class] the `Class` constant
24
- def resolve_class(klass, source_class: self, exception: true)
25
- @resolved ||= {}
26
- @resolved[klass] ||=
27
- case klass
28
- when Class
29
- klass
30
- when String
31
- begin
32
- Kernel.const_get(klass)
33
- rescue NameError
34
- raise if exception
35
- end
36
- when Symbol
37
- source_class.resolve_class(source_class.send(klass))
38
- when Hash
39
- referrer, referred = klass.first
40
- resolve_class(referred, source_class: referrer, exception: exception)
41
- else
42
- raise "Unknown class: #{klass}" if exception
43
- end
44
- end
45
-
46
- # Helper to normalize `key` into a correct `ruby` **constant name**
47
- # @note it removes namespace syntax `::`
48
- # @param key [String, Symbol] to be normalized
49
- # @return [String] a correct constant name
50
- def to_constant(key)
51
- key.to_s.strip.split('::').compact.map do |str|
52
- str.slice(0).upcase + str.slice(1..-1)
53
- end.join.split(/[\-\_ :]+/i).compact.map do |str|
54
- str.slice(0).upcase + str.slice(1..-1)
55
- end.join
56
- end
57
-
58
- # Helper to create an instance variable `name`
59
- # @param [String, Symbol] the name of the variable
60
- # @reutrn [String] the name of the created instance variable
61
- def instance_variable_name(name)
62
- str = name.to_s
63
- str = "@#{str}" unless str.start_with?("@")
64
- str
65
- end
66
-
67
- # If the class for `name` exists, it returns it. Otherwise it generates it.
68
- # @param name [String, Symbol] the name of the new class
69
- # @param inherits [Class] the parent class to _inherit_ from
70
- # @param namespace [Class, String] an existing `constant` (class or module) the new class will be namespaced on
71
- # @yield [child_class] configure the new class
72
- # @yieldparam child_class [Class] the new class
73
- # @return [Class] the new generated class
74
- def new_class(name = "Child#{uid}", inherits: self, namespace: inherits)
75
- name = name.to_s.to_sym.freeze
76
- class_name = to_constant(name)
77
-
78
- unless (target_class = resolve_class("#{namespace}::#{class_name}", exception: false))
79
- target_class = Class.new(inherits)
80
- Kernel.const_get(namespace.to_s).const_set class_name, target_class
81
- end
82
-
83
- target_class.tap do |klass|
84
- yield(klass) if block_given?
85
- end
86
- end
87
-
88
- # Helper to determine if a paramter has been used
89
- # @note to effectivelly use this helper, you should initialize your target
90
- # paramters with the constant `NOT_USED`
91
- # @param val [] the value of the paramter
92
- # @return [Boolean] `true` if value other than `NOT_USED`, `false` otherwise
93
- def used_param?(val)
94
- val != NOT_USED
95
- end
96
-
97
- # Keeps track on class instance variables that should be inherited by child classes.
98
- # @note
99
- # - subclasses will inherit the value as is at that moment
100
- # - any change afterwards will be only on the specific class (in line with class instance variables)
101
- # - adapted from https://stackoverflow.com/a/10729812/4352306
102
- # TODO: this separates the logic of the method to the instance var. Think if would be possible to join them somehow.
103
- def inheritable_class_vars(*vars)
104
- @inheritable_class_vars ||= [:inheritable_class_vars]
105
- @inheritable_class_vars += vars
106
- end
107
-
108
- # Builds the attr_reader and attr_writer of `attrs` and registers the associated instance variable as inheritable.
109
- def inheritable_attrs(*attrs)
110
- attrs.each do |attr|
111
- class_eval %( # rubocop:disable Style/DocumentDynamicEvalDefinition
112
- class << self; attr_accessor :#{attr} end
113
- ), __FILE__, __LINE__ - 2
114
- end
115
- inheritable_class_vars(*attrs)
116
- end
117
-
118
- # This callback method is called whenever a subclass of the current class is created.
119
- # @note
120
- # - values of the instance variables are copied as they are (no dups or clones)
121
- # - the above means: avoid methods that change the state of the mutable object on it
122
- # - mutating methods would reflect the changes on other classes as well
123
- # - therefore, `freeze` will be called on the values that are inherited.
124
- def inherited(subclass)
125
- super
126
-
127
- inheritable_class_vars.each do |var|
128
- instance_var = instance_variable_name(var)
129
- value = instance_variable_get(instance_var)
130
- subclass.instance_variable_set(instance_var, value.freeze)
131
- end
132
- end
133
- end
134
- end
135
- end
136
- end