eco-helpers 3.0.37 → 3.1.2

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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +132 -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 +49 -6
  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 +70 -70
  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 +94 -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 +64 -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 +2 -2
  36. data/lib/eco/api/organization/people/similarity.rb +3 -3
  37. data/lib/eco/api/organization/people.rb +2 -2
  38. data/lib/eco/api/session/batch/base_policy.rb +42 -27
  39. data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
  40. data/lib/eco/api/session/batch/launcher.rb +16 -3
  41. data/lib/eco/api/session/config/api.rb +4 -3
  42. data/lib/eco/api/session/config/apis/one_off.rb +1 -1
  43. data/lib/eco/api/session/config/files.rb +13 -12
  44. data/lib/eco/api/session/config/workflow.rb +1 -373
  45. data/lib/eco/api/session/config.rb +45 -10
  46. data/lib/eco/api/session.rb +7 -9
  47. data/lib/eco/api/usecases/base_case/model.rb +6 -6
  48. data/lib/eco/api/usecases/base_case.rb +1 -1
  49. data/lib/eco/api/usecases/cli.rb +1 -1
  50. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +22 -13
  51. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
  52. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +6 -3
  53. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  54. data/lib/eco/api/usecases/lib/base/env.rb +21 -23
  55. data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
  56. data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
  57. data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
  58. data/lib/eco/api/usecases/lib/files.rb +1 -0
  59. data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
  60. data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
  61. data/lib/eco/api/usecases/lib/locations.rb +7 -0
  62. data/lib/eco/api/usecases/lib/people/base.rb +20 -0
  63. data/lib/eco/api/usecases/lib/people.rb +6 -0
  64. data/lib/eco/api/usecases/lib.rb +2 -0
  65. data/lib/eco/api/usecases/ooze_cases.rb +1 -1
  66. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
  67. data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +3 -3
  68. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -1
  69. data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +1 -1
  70. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +6 -2
  71. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +7 -6
  72. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +14 -4
  73. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +11 -8
  74. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
  75. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
  76. data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
  77. data/lib/eco/api/usecases/service/sftp.rb +7 -1
  78. data/lib/eco/api/usecases/use_case.rb +3 -2
  79. data/lib/eco/api/usecases/workflow.rb +5 -0
  80. data/lib/eco/api/usecases.rb +12 -5
  81. data/lib/eco/cli/scripting/args_helpers.rb +1 -9
  82. data/lib/eco/cli_default/options.rb +98 -68
  83. data/lib/eco/cli_default/workflow/end.rb +22 -0
  84. data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
  85. data/lib/eco/cli_default/workflow/load/data.rb +27 -0
  86. data/lib/eco/cli_default/workflow/load/input.rb +28 -0
  87. data/lib/eco/cli_default/workflow/load.rb +13 -0
  88. data/lib/eco/cli_default/workflow/options.rb +18 -0
  89. data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
  90. data/lib/eco/cli_default/workflow/report.rb +17 -0
  91. data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
  92. data/lib/eco/cli_default/workflow/usecases.rb +23 -0
  93. data/lib/eco/cli_default/workflow.rb +24 -180
  94. data/lib/eco/data/count_trace.rb +51 -0
  95. data/lib/eco/data/files/content.rb +39 -0
  96. data/lib/eco/data/files/directory.rb +78 -45
  97. data/lib/eco/data/files/encoding.rb +12 -21
  98. data/lib/eco/data/files/file_pattern.rb +15 -8
  99. data/lib/eco/data/files/folder.rb +196 -0
  100. data/lib/eco/data/files/relative_path.rb +54 -0
  101. data/lib/eco/data/files/timestamp.rb +18 -0
  102. data/lib/eco/data/files.rb +46 -5
  103. data/lib/eco/data/fuzzy_match.rb +1 -1
  104. data/lib/eco/data/hashes/array_diff.rb +11 -5
  105. data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
  106. data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
  107. data/lib/eco/data/mapper.rb +8 -1
  108. data/lib/eco/data.rb +1 -0
  109. data/lib/eco/language/auxiliar_logger.rb +6 -11
  110. data/lib/eco/language/delegation/delegating_missing.rb +1 -1
  111. data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
  112. data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
  113. data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
  114. data/lib/eco/language/klass/auto_loader.rb +129 -0
  115. data/lib/eco/language/klass/builder.rb +6 -6
  116. data/lib/eco/language/klass/const.rb +19 -0
  117. data/lib/eco/language/klass/helpers_built.rb +3 -1
  118. data/lib/eco/language/klass/hierarchy.rb +5 -1
  119. data/lib/eco/language/klass/naming.rb +5 -2
  120. data/lib/eco/language/klass/resolver.rb +21 -6
  121. data/lib/eco/language/klass/uid.rb +12 -0
  122. data/lib/eco/language/klass/when_inherited.rb +30 -6
  123. data/lib/eco/language/klass.rb +5 -2
  124. data/lib/eco/language/methods/access_modifier.rb +23 -0
  125. data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
  126. data/lib/eco/language/methods.rb +1 -0
  127. data/lib/eco/language/models/hierarchy.rb +41 -0
  128. data/lib/eco/language/models/workflow.rb +385 -0
  129. data/lib/eco/language/models.rb +2 -1
  130. data/lib/eco/version.rb +1 -1
  131. metadata +31 -7
  132. data/lib/eco/api/common/class_auto_loader.rb +0 -114
  133. data/lib/eco/api/common/class_helpers.rb +0 -9
  134. data/lib/eco/api/common/class_hierarchy.rb +0 -45
  135. data/lib/eco/data/files/helpers.rb +0 -152
  136. data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -2,9 +2,7 @@ module Eco
2
2
  module API
3
3
  class Session
4
4
  class Config
5
- class Workflow
6
- extend Eco::API::Common::ClassHierarchy
7
-
5
+ class Workflow < Eco::API::UseCases::Workflow
8
6
  WORKFLOW_MODEL = [
9
7
  :options,
10
8
  {load: [{input: %i[get filter]}, {data: %i[get filter]}, :filter]},
@@ -16,377 +14,7 @@ module Eco
16
14
  :close
17
15
  ].freeze
18
16
 
19
- class << self
20
- def stages
21
- model_attrs
22
- end
23
-
24
- def model
25
- super || {}
26
- end
27
-
28
- def validate_stage!(stage)
29
- return true if stages.include?(stage)
30
-
31
- msg = "Unknown Workflow stage '#{stage}'. Should be any of #{stages}"
32
- raise ArgumentError, msg
33
- end
34
-
35
- def workflow_class(key)
36
- class_name = to_constant(key.to_s)
37
-
38
- new_class(class_name, inherits: Eco::API::Session::Config::Workflow) do |klass|
39
- klass.model = model[key]
40
- end
41
- end
42
- end
43
-
44
17
  self.model = WORKFLOW_MODEL
45
- attr_reader :config
46
-
47
- def initialize(name = nil, config:, _parent: self) # rubocop:disable Lint/UnderscorePrefixedVariableName
48
- @config = config
49
- @name = name
50
-
51
- @stages = {}
52
- @_parent = _parent
53
-
54
- @pending = true
55
- # moments
56
- @on = nil
57
- @before = []
58
- @after = []
59
- end
60
-
61
- def name(with_path: false)
62
- return @name if !with_path || root?
63
-
64
- [@_parent.name(with_path: true), @name].compact.join('.')
65
- end
66
-
67
- # Has this stage run yet?
68
- # @note it does **not** include _sub-stages_ that run `before`
69
- # @return [Boolean] `true` if it has run, `false` otherwise
70
- def pending?
71
- @pending
72
- end
73
-
74
- # Do not run this stage!
75
- def skip!
76
- @skip = true
77
- @pending = false
78
- end
79
-
80
- # Has this stage been marked as to be skipped
81
- # @return [Boolean] depends on this order:
82
- # - `true` if `skip!` was called
83
- # - `false` if the current _stage_ is `root?` (the top stage of the hierarchy)
84
- # - `true` if its parent task is to be skipped
85
- def skip?
86
- return @skip if instance_variable_defined?(:@skip)
87
- return false if root?
88
-
89
- @_parent.skip?
90
- end
91
-
92
- # Used in **configuration** time **to configure** the _workflow_ of the target (sub)stage `key`
93
- # @note
94
- # 1. if a `block` is provided it will `yield` the target stage immediately
95
- # 2. a `block` is only required when `key` has not been specified.
96
- # @param key [Symbol, nil] cases:
97
- # - if `key` is not provided, it targets the _current stage_
98
- # - if `key` is provided, it targets the specific _sub-stage_
99
- # @yield [stage_workflow] further _workflow_ configuration `for` the target stage `key`
100
- # @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
101
- # @return [Eco::API::Session::Config::Workflow]
102
- # 1. if block is provided provided, it returns the **current stage** object (to ease chainig).
103
- # 2. if block is not provided, it returns the **stage** referred by `key`
104
- def for(key = nil, &block)
105
- msg = "With no 'key', a block should be given."
106
- raise ArgumentError, msg unless key || block_given?
107
-
108
- tap do
109
- next yield(self) unless key
110
- next stage(key).for(&block) if block_given?
111
-
112
- return stage(key)
113
- end
114
- end
115
- alias_method :with, :for
116
-
117
- # Used in **configuration** time **to define** the **behaviour** the target (sub)stage `key`
118
- # @note if a `block` is provided it will **not** `yield` the target stage immediately,
119
- # but when the _workflow_ reaches the stage
120
- # @param key [Symbol, nil] cases:
121
- # - if `key` is not provided, it targets the _current stage_
122
- # - if `key` is provided, it targets the specific _sub-stage_
123
- # @yield [stage_workflow, io] the behaviour of the target stage `key` when the _workflow_ reaches it
124
- # @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
125
- # @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
126
- # @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
127
- # @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
128
- def on(key = nil, &block)
129
- msg = 'A block should be given.'
130
- raise ArgumentError, msg unless block_given?
131
-
132
- if key
133
- stage(key).on(&block)
134
- else
135
- @on = block
136
- end
137
-
138
- self
139
- end
140
-
141
- # When there is an `Exception`, you might have defined some `callback`
142
- # to do something with it (i.e. register, email)
143
- # @yield [exception, io] the `callback` to do something with
144
- # an `Exception` raised within this _workflow_ stage
145
- # @yieldparam exception [Exception] the exception object that was raised
146
- # @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
147
- # @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
148
- # @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
149
- def rescue(&block)
150
- return @rescue unless block_given?
151
-
152
- @rescue = block
153
- self
154
- end
155
- # Prevent reserved word clash on DSL
156
- alias_method :exception, :rescue
157
-
158
- # Called on `SystemExit` exception
159
- def exit_handle(&block)
160
- return @exit_handle unless block_given?
161
-
162
- @exit_handle = block
163
- self
164
- end
165
-
166
- # Used in **configuration** time **add previous** `callbacks`
167
- # **before** the `on` _callback_ of the (sub)stage `key` is actually `run`
168
- # @note
169
- # - it will **not** `yield` it immediately, but when the _workflow_ reaches the target stage
170
- # - in this case, you can define multiple `callbacks`
171
- # @param key [Symbol, nil] cases:
172
- # - if `key` is not provided, it targets the _current stage_
173
- # - if `key` is provided, it targets the specific _sub-stage_
174
- # @yield [stage_workflow, io] one of the things to do **before** the
175
- # `on` _callback_ of the (sub)stage `key` is actually `run`
176
- # @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
177
- # @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
178
- # @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
179
- # @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
180
- def before(key = nil, &block)
181
- msg = 'A block should be given.'
182
- raise ArgumentError, msg unless block_given?
183
-
184
- if key
185
- stage(key).before(&block)
186
- else
187
- @before.push(block)
188
- end
189
-
190
- self
191
- end
192
-
193
- # Used in **configuration** time **add previous** `callbacks` **after** the `on` _callback_
194
- # of the (sub)stage `key` is actually `run`
195
- # @note
196
- # - it will **not** `yield` it immediately, but when the _workflow_ reaches the target stage
197
- # - in this case, you can define multiple `callbacks`
198
- # @param key [Symbol, nil] cases:
199
- # - if `key` is not provided, it targets the _current stage_
200
- # - if `key` is provided, it targets the specific _sub-stage_
201
- # @yield [stage_workflow, io] one of the things to do **after** the
202
- # `on` _callback_ of the (sub)stage `key` is actually `run`
203
- # @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
204
- # @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
205
- # @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
206
- # @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
207
- def after(key = nil, &block)
208
- msg = 'A block should be given.'
209
- raise ArgumentError, msg unless block_given?
210
-
211
- if key
212
- stage(key).after(&block)
213
- else
214
- @after.push(block)
215
- end
216
-
217
- self
218
- end
219
-
220
- # Used in run time to **execute the workflow** of the (sub)stage `key`
221
- # @note if a `block` is **not** provided:
222
- # - it will run the `before` _callbacks_ defined during the configuration time
223
- # - it will run the _workflow_ of any defined _**substage**_ of the `key` stage
224
- # - it will run the `on` _callback_ defined during the configuration time
225
- # - it will mark the stage as **not** `pending?`.
226
- # - it will run the `after` _callbacks_ defined during the configuration time
227
- # @note if a `block` is provided:
228
- # - it will **not** run the workflow of the substages to `key` stage
229
- # - it will **not** run the `callback` for `on` defined during the configuration time
230
- # - it will rather `yield` the target stage after all the `before` _callbacks_ have been run
231
- # - aside of this, the rest will be the same as when the _block_ is provided (see previous note)
232
- # @note [if the object returned by `before`, `after` and `run` callbacks
233
- # is not an `Eco::API::UseCases::BaseIO`, the original `io` object will be returned instead.
234
- # @param key [Symbol, nil] cases:
235
- # - if `key` is not provided, it targets the _current stage_
236
- # - if `key` is provided, it targets the specific _sub-stage_
237
- # @param io [Eco::API::UseCases::BaseIO] the input/output object
238
- # @yield [stage_workflow, io] if a `block` is provided, see `note`
239
- # @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
240
- # @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
241
- # @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
242
- # @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
243
- def run(key = nil, io:, &block)
244
- raise 'Missing BaseIO object' unless io.is_a?(Eco::API::UseCases::BaseIO)
245
-
246
- rescuable(io) do
247
- if key
248
- io = io_result(io: io) do
249
- stage(key).run(io: io, &block)
250
- end
251
- elsif pending?
252
- io = run_before(io)
253
- io = run_it(io, &block) unless skip?
254
- io = run_after(io)
255
- end
256
- io
257
- ensure
258
- @pending = false
259
- end
260
- end
261
-
262
- protected
263
-
264
- def root?
265
- @_parent == self
266
- end
267
-
268
- def path
269
- return name if root?
270
-
271
- "#{@_parent.path}:#{name}"
272
- end
273
-
274
- def ready?
275
- !!@on
276
- end
277
-
278
- def run_before(io)
279
- @before.each do |c|
280
- io = io_result(io: io) do
281
- io.evaluate(self, io, &c)
282
- end
283
- end
284
-
285
- io
286
- end
287
-
288
- def run_after(io)
289
- @after.each do |c|
290
- io = io_result(io: io) do
291
- io.evaluate(self, io, &c)
292
- end
293
- end
294
-
295
- io
296
- end
297
-
298
- def run_it(io, &block)
299
- io.session.log(:debug) {
300
- "(Workflow: #{path}) running now"
301
- }
302
-
303
- if block
304
- io = io_result(io: io) do
305
- io.evaluate(self, io, &block)
306
- end
307
- else
308
- existing_stages.each do |stg|
309
- io = io_result(io: io) do
310
- stg.run(io: io)
311
- end
312
- end
313
-
314
- unless ready?
315
- io.session.log(:debug) {
316
- "(Workflow: #{path}) 'on' callback is not defined, nor block given"
317
- }
318
- end
319
-
320
- io = io_result(io: io) do
321
- io.evaluate(self, io, &@on)
322
- end
323
- end
324
-
325
- io
326
- ensure
327
- @pending = false
328
- end
329
-
330
- # It ensures an `Eco::API::UseCases::BaseIO` is returned
331
- # @note it always brings the IO to be a `BaseIO`.
332
- # As the `output` and the type is captured, it just cleans usecase related
333
- # logic from the object.
334
- # @raise ArgumentError if `klass` isn't child of `Eco::API::UseCases::BaseIO`
335
- # @return [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout the _workflow_
336
- def io_result(io:, klass: Eco::API::UseCases::BaseIO)
337
- msg = "Expecting class to be child of Eco::API::UseCases::BaseIO. Given: #{klass}"
338
- raise ErrorArgument, msg unless klass <= Eco::API::UseCases::BaseIO
339
-
340
- result = yield
341
- io = result if result.is_a?(klass)
342
- io.instance_of?(klass) ? io : io.base
343
- end
344
-
345
- def existing_stages
346
- # sort defined stages by stage order
347
- sorted_keys = self.class.stages & @stages.keys
348
- sorted_keys.map {|k| stage(k)}
349
- end
350
-
351
- def ready_stages
352
- exiting_stages.select(&:ready?)
353
- end
354
-
355
- def stages_ready?
356
- existing_stages.all?(&:ready?)
357
- end
358
-
359
- def stage(key)
360
- self.class.validate_stage!(key)
361
- @stages[key] ||= self.class.workflow_class(key).new(
362
- key,
363
- _parent: self,
364
- config: config
365
- )
366
- end
367
-
368
- # helper to treat trigger the exit and rescue handlers
369
- def rescuable(io)
370
- yield
371
- # rescue SystemStackError => err
372
- # puts err.patch_full_message(trace_count: 100)
373
- # exit 1
374
- rescue SystemExit => err
375
- io = io_result(io: io) do
376
- io.evaluate(err, io, &exit_handle)
377
- end
378
-
379
- exit err.status
380
- rescue Interrupt => _int
381
- raise
382
- rescue StandardError => err
383
- # raise unless self.rescue
384
- io = io_result(io: io) do
385
- io.evaluate(err, io, &self.rescue)
386
- end
387
-
388
- raise
389
- end
390
18
  end
391
19
  end
392
20
  end
@@ -114,7 +114,21 @@ module Eco
114
114
  yield(ApiDefChain.new(self, name, params))
115
115
  end
116
116
 
117
- ApiDefChain.new(self, name, {space: :other})
117
+ ApiDefChain.new(self, name, {space: :other}).tap do
118
+ next unless kargs[:host].to_s.downcase == 'live.ecoportal.com'
119
+ next unless kargs[:space].nil? || kargs[:space].to_sym == :default
120
+
121
+ %w[
122
+ beta.dev.ecoportal.com
123
+ staging.dev.ecoportal.com
124
+ pre.dev.ecoportal.com
125
+ ].each do |env|
126
+ spa = env.split('.', 2).first.to_sym
127
+ next if apis.defined?(name, space: spa)
128
+
129
+ apis.add(name, **kargs, host: env, space: spa)
130
+ end
131
+ end
118
132
  end
119
133
 
120
134
  # Set the active api by `name`
@@ -209,8 +223,8 @@ module Eco
209
223
 
210
224
  def require(file = nil, match: nil)
211
225
  if match
212
- file_manager.dir.dir_files(pattern: match).each do |file|
213
- require_relative File.expand_path(file)
226
+ file_manager.dir.dir_files(pattern: match).each do |filename|
227
+ require_relative File.expand_path(filename)
214
228
  end
215
229
  else
216
230
  target = File.expand_path(file_manager.dir.file(file))
@@ -235,15 +249,36 @@ module Eco
235
249
  def location_codes
236
250
  org['location_codes']
237
251
  end
252
+ alias_method :locations_map_file, :location_codes
253
+
254
+ # @param internal [Symbol] either `:first` (default) or `:last`
255
+ # @param insensitive [Boolean] default `false`. Whether lookups are
256
+ # case sensitive.
257
+ # @param maps_file [String] the location maps file (default: `locations_map_file`).
258
+ # - Via `file_manager` it will try to spot the most recently changed.
259
+ # - The lookup to spot the **path** of the file, tries first as a **relative**
260
+ # path from `env/config/...`. If it fails, it tries it as an absolute path.
261
+ # @return [Eco::Data::Mapper, NilClass]
262
+ def locations_mapper(**kargs)
263
+ kargs = {
264
+ internal: :first,
265
+ insensitive: false,
266
+ maps_file: nil
267
+ }.merge(kargs)
238
268
 
239
- def locations_mapper(insensitive: false)
240
- return @locations_mapper if instance_variable_defined?(:@locations_mapper)
269
+ kargs[:maps_file] ||= locations_map_file
270
+ kargs[:maps_file] = file_manager.newest(kargs[:maps_file])
241
271
 
242
- file = file_manager.newest(location_codes)
243
- @locations_mapper = Eco::Data::Mapper.new(
244
- file_manager.load_json(file),
245
- internal: :first,
246
- insensitive: insensitive
272
+ return unless kargs[:maps_file]
273
+
274
+ @locations_mapper ||= {}
275
+
276
+ return @locations_mapper[kargs] if @locations_mapper.key?(kargs)
277
+
278
+ @locations_mapper[kargs] = Eco::Data::Mapper.new(
279
+ file_manager.load_json(kargs[:maps_file]),
280
+ internal: kargs[:internal],
281
+ insensitive: kargs[:insensitive]
247
282
  )
248
283
  end
249
284
 
@@ -334,15 +334,13 @@ module Eco
334
334
  # Sends an email
335
335
  # @see Eco::API::Common::Session::Mailer#mail
336
336
  # @param (see Eco::API::Common::Session::Mailer#mail)
337
- def mail(**kargs)
338
- if mailer?
339
- mailer.mail(**kargs)
340
- else
341
- log(:error) {
342
- "You are trying to use the mailer, but it's not configured"
343
- }
344
- nil
345
- end
337
+ def mail(...)
338
+ return mailer.mail(...) if mailer?
339
+
340
+ log(:error) {
341
+ "You are trying to use the mailer, but it's not configured"
342
+ }
343
+ nil
346
344
  end
347
345
 
348
346
  # Uploads content into a file, a file or a directory to S3
@@ -1,5 +1,11 @@
1
1
  class Eco::API::UseCases::BaseCase
2
2
  module Model
3
+ MODELS = %i[
4
+ people
5
+ contractors
6
+ other
7
+ ].freeze
8
+
3
9
  class UnsupportedModel < ArgumentError
4
10
  def initialize(msg = nil, model:, models:)
5
11
  msg ||= "Unsupported model. "
@@ -8,12 +14,6 @@ class Eco::API::UseCases::BaseCase
8
14
  end
9
15
  end
10
16
 
11
- MODELS = %i[
12
- people
13
- contractors
14
- other
15
- ].freeze
16
-
17
17
  class << self
18
18
  def included(base)
19
19
  super
@@ -9,7 +9,7 @@ module Eco
9
9
  include Type
10
10
  include Model
11
11
 
12
- extend Eco::API::Common::ClassHelpers
12
+ extend Eco::Language::Klass::HelpersBuilt
13
13
  end
14
14
  end
15
15
  end
@@ -3,7 +3,7 @@ module Eco
3
3
  module API
4
4
  class UseCases
5
5
  class Cli
6
- extend Eco::API::Common::ClassHelpers
6
+ extend Eco::Language::Klass::HelpersBuilt
7
7
 
8
8
  require_relative 'cli/dsl'
9
9
  extend DSL
@@ -1,16 +1,20 @@
1
1
  # Use case to export an org tree into some of the offered forms.
2
2
  class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCases::GraphQL::Samples::Location
3
3
  require_relative 'cli/tagtree_extract_cli'
4
- #cli self::Cli
5
4
 
6
- name "tagtree-extract"
5
+ name 'tagtree-extract'
7
6
  type :other
8
7
 
9
8
  include Eco::Data::Files
10
9
 
11
- OUT_FOLDER = "sftp".freeze
10
+ OUT_FOLDER = 'sftp'.freeze
12
11
  OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
13
- OUT_FILENAME = "live_tree".freeze
12
+ OUT_FILENAME = 'live_tree'.freeze
13
+ FORMATS = %i[
14
+ csv_tree nodes csv_nodes list
15
+ excel_tree excel_nodes
16
+ json
17
+ ].freeze
14
18
 
15
19
  def process
16
20
  case format
@@ -24,14 +28,19 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
24
28
  end
25
29
  end
26
30
  end
27
- when :list, :nodes, :csv_tree, :json
31
+ when :list, :nodes, :csv_nodes, :csv_tree, :json
28
32
  tag_trees.each do |tree|
29
33
  file(output_filename(compact_name(tree.name))) do |fd|
30
34
  fd << tree_extract(tree)
31
35
  end
32
36
  end
33
37
  else
34
- log(:error) { "Unknown selected output format '#{format}'. Abort..." }
38
+ msg = 'Unknown selected output format '
39
+ msg << "'#{format}'. Correct formats:\n"
40
+ msg << " #{FORMATS.join(', ')}"
41
+ msg << ". \nAborting..."
42
+
43
+ log(:error) { msg }
35
44
  exit 1
36
45
  end
37
46
  end
@@ -39,7 +48,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
39
48
  private
40
49
 
41
50
  def compact_name(str)
42
- str.gsub(/\s+/, "_").gsub(/\W/, '')[0..30]
51
+ str.gsub(/\s+/, '_').gsub(/\W/, '')[0..30]
43
52
  end
44
53
 
45
54
  def str_node_attrs
@@ -54,7 +63,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
54
63
  with_ancestors(csv_tree(tree, attrs: str_node_attrs)).to_csv
55
64
  when :excel_tree
56
65
  with_ancestors(csv_tree(tree, attrs: str_node_attrs)).to_a
57
- when :nodes
66
+ when :nodes, :csv_nodes
58
67
  csv_list(tree).to_csv
59
68
  when :excel_nodes
60
69
  csv_list(tree).to_a
@@ -80,12 +89,12 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
80
89
  end
81
90
 
82
91
  def indentation
83
- options.dig(:output, :indent) || " "
92
+ options.dig(:output, :indent) || ' '
84
93
  end
85
94
 
86
95
  def output_file_format
87
96
  case format
88
- when :nodes, :csv_tree
97
+ when :nodes, :csv_nodes, :csv_tree
89
98
  'csv'
90
99
  when :json then 'json'
91
100
  when :excel_tree, :excel_nodes
@@ -169,7 +178,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
169
178
  out_str = str_ary.join("\n") unless str_ary.empty?
170
179
 
171
180
  unless tree.top?
172
- node_name = tree.as_json(include_children: false).values_at(*attrs.map(&:to_s)).join(" ## ")
181
+ node_name = tree.as_json(include_children: false).values_at(*attrs.map(&:to_s)).join(' ## ')
173
182
  out_head = "#{indent * level}#{node_name}"
174
183
  out_str = out_str ? "#{out_head}\n#{out_str}" : out_head
175
184
  end
@@ -178,7 +187,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
178
187
  end
179
188
 
180
189
  def csv(filename, header = [])
181
- CSV.open(filename, "w") do |csv|
190
+ CSV.open(filename, 'w') do |csv|
182
191
  csv << header unless header.empty?
183
192
 
184
193
  yield(csv)
@@ -188,7 +197,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
188
197
  end
189
198
 
190
199
  def file(filename, &block)
191
- File.open(filename, "w", &block)
200
+ File.open(filename, 'w', &block)
192
201
  ensure
193
202
  log(:info) { "Created file: #{filename}" }
194
203
  end
@@ -88,7 +88,10 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
88
88
  def out_filename
89
89
  return options_file unless options_folder?
90
90
 
91
- File.join(options_file, "#{config.active_enviro}_#{OUT_FILENAME}.csv")
91
+ File.join(
92
+ options_file,
93
+ "#{config.active_enviro}_#{OUT_FILENAME}.csv"
94
+ )
92
95
  end
93
96
 
94
97
  def in_folder(filename)
@@ -1,8 +1,10 @@
1
1
  module Eco::API::UseCases::GraphQL::Helpers::Location
2
2
  class TagsRemap
3
3
  def self.correct_pair?(pair)
4
- correct_pair = pair.is_a?(Array)
5
- correct_pair && pair.length == 2
4
+ return false unless pair.is_a?(Array)
5
+ return false unless pair.length == 2
6
+
7
+ true
6
8
  end
7
9
 
8
10
  include Enumerable
@@ -15,6 +17,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
15
17
 
16
18
  def each(&block)
17
19
  return to_enum(:each) unless block
20
+
18
21
  src_maps.each(&block)
19
22
  end
20
23
 
@@ -29,7 +32,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
29
32
  end
30
33
 
31
34
  def to_s
32
- "".tap do |str|
35
+ ''.tap do |str|
33
36
  each.map do |tags_map|
34
37
  from, to = tags_map.to_csv_row
35
38
  str << " * '#{from}' => '#{to}'\n"