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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +116 -1
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +2 -0
- data/lib/eco/api/common/loaders/config/block.rb +78 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +39 -7
- data/lib/eco/api/common/loaders/config.rb +3 -26
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +1 -4
- data/lib/eco/api/common/people/entries.rb +23 -6
- data/lib/eco/api/common/people/entry_factory.rb +1 -1
- data/lib/eco/api/common/people/person_entry.rb +104 -27
- data/lib/eco/api/common/people/person_parser.rb +50 -16
- data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
- data/lib/eco/api/common/session/base_session.rb +75 -81
- data/lib/eco/api/common/session/environment.rb +49 -55
- data/lib/eco/api/common/session/file_manager.rb +132 -135
- data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
- data/lib/eco/api/common/session/helpers.rb +10 -15
- data/lib/eco/api/common/session/logger/cache.rb +89 -96
- data/lib/eco/api/common/session/logger/channels.rb +24 -32
- data/lib/eco/api/common/session/logger/log.rb +38 -46
- data/lib/eco/api/common/session/logger.rb +50 -54
- data/lib/eco/api/common/session/mailer/aws_provider.rb +63 -71
- data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
- data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
- data/lib/eco/api/common/session/mailer.rb +78 -83
- data/lib/eco/api/common/session/s3_uploader.rb +132 -138
- data/lib/eco/api/common/session/sftp.rb +202 -208
- data/lib/eco/api/common.rb +0 -3
- data/lib/eco/api/custom/mailer.rb +4 -2
- data/lib/eco/api/error/handlers.rb +1 -1
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
- data/lib/eco/api/microcases/people/manage/search.rb +1 -1
- data/lib/eco/api/organization/people/similarity.rb +3 -3
- data/lib/eco/api/session/batch/base_policy.rb +42 -27
- data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
- data/lib/eco/api/session/batch/launcher.rb +16 -3
- data/lib/eco/api/session/config/api.rb +4 -3
- data/lib/eco/api/session/config/apis/one_off.rb +1 -1
- data/lib/eco/api/session/config/files.rb +13 -12
- data/lib/eco/api/session/config/workflow.rb +1 -373
- data/lib/eco/api/session/config.rb +30 -9
- data/lib/eco/api/usecases/base_case/model.rb +6 -6
- data/lib/eco/api/usecases/base_case.rb +1 -1
- data/lib/eco/api/usecases/cli.rb +1 -1
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +8 -9
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
- data/lib/eco/api/usecases/lib/base/env.rb +21 -23
- data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
- data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
- data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
- data/lib/eco/api/usecases/lib/files.rb +1 -0
- data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
- data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
- data/lib/eco/api/usecases/lib/locations.rb +7 -0
- data/lib/eco/api/usecases/lib/people/base.rb +20 -0
- data/lib/eco/api/usecases/lib/people.rb +6 -0
- data/lib/eco/api/usecases/lib.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +1 -0
- data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
- data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
- data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
- data/lib/eco/api/usecases/service/sftp.rb +7 -1
- data/lib/eco/api/usecases/use_case.rb +3 -2
- data/lib/eco/api/usecases/workflow.rb +5 -0
- data/lib/eco/api/usecases.rb +12 -5
- data/lib/eco/cli/scripting/args_helpers.rb +1 -9
- data/lib/eco/cli_default/options.rb +98 -68
- data/lib/eco/cli_default/workflow/end.rb +22 -0
- data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
- data/lib/eco/cli_default/workflow/load/data.rb +27 -0
- data/lib/eco/cli_default/workflow/load/input.rb +28 -0
- data/lib/eco/cli_default/workflow/load.rb +13 -0
- data/lib/eco/cli_default/workflow/options.rb +10 -0
- data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
- data/lib/eco/cli_default/workflow/report.rb +17 -0
- data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
- data/lib/eco/cli_default/workflow/usecases.rb +23 -0
- data/lib/eco/cli_default/workflow.rb +24 -180
- data/lib/eco/data/count_trace.rb +51 -0
- data/lib/eco/data/files/content.rb +39 -0
- data/lib/eco/data/files/directory.rb +78 -45
- data/lib/eco/data/files/encoding.rb +12 -21
- data/lib/eco/data/files/file_pattern.rb +15 -8
- data/lib/eco/data/files/folder.rb +196 -0
- data/lib/eco/data/files/relative_path.rb +54 -0
- data/lib/eco/data/files/timestamp.rb +18 -0
- data/lib/eco/data/files.rb +46 -5
- data/lib/eco/data/fuzzy_match.rb +1 -1
- data/lib/eco/data/hashes/array_diff.rb +11 -5
- data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
- data/lib/eco/data/mapper.rb +5 -1
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/delegation/delegating_missing.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
- data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
- data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
- data/lib/eco/language/klass/auto_loader.rb +129 -0
- data/lib/eco/language/klass/builder.rb +6 -6
- data/lib/eco/language/klass/const.rb +19 -0
- data/lib/eco/language/klass/helpers_built.rb +3 -1
- data/lib/eco/language/klass/hierarchy.rb +5 -1
- data/lib/eco/language/klass/naming.rb +5 -2
- data/lib/eco/language/klass/resolver.rb +21 -6
- data/lib/eco/language/klass/uid.rb +12 -0
- data/lib/eco/language/klass/when_inherited.rb +30 -6
- data/lib/eco/language/klass.rb +5 -2
- data/lib/eco/language/methods/access_modifier.rb +23 -0
- data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
- data/lib/eco/language/methods.rb +1 -0
- data/lib/eco/language/models/hierarchy.rb +41 -0
- data/lib/eco/language/models/workflow.rb +385 -0
- data/lib/eco/language/models.rb +2 -1
- data/lib/eco/version.rb +1 -1
- metadata +31 -7
- data/lib/eco/api/common/class_auto_loader.rb +0 -114
- data/lib/eco/api/common/class_helpers.rb +0 -9
- data/lib/eco/api/common/class_hierarchy.rb +0 -45
- data/lib/eco/data/files/helpers.rb +0 -152
- 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
|
@@ -209,8 +209,8 @@ module Eco
|
|
209
209
|
|
210
210
|
def require(file = nil, match: nil)
|
211
211
|
if match
|
212
|
-
file_manager.dir.dir_files(pattern: match).each do |
|
213
|
-
require_relative File.expand_path(
|
212
|
+
file_manager.dir.dir_files(pattern: match).each do |filename|
|
213
|
+
require_relative File.expand_path(filename)
|
214
214
|
end
|
215
215
|
else
|
216
216
|
target = File.expand_path(file_manager.dir.file(file))
|
@@ -235,15 +235,36 @@ module Eco
|
|
235
235
|
def location_codes
|
236
236
|
org['location_codes']
|
237
237
|
end
|
238
|
+
alias_method :locations_map_file, :location_codes
|
239
|
+
|
240
|
+
# @param internal [Symbol] either `:first` (default) or `:last`
|
241
|
+
# @param insensitive [Boolean] default `false`. Whether lookups are
|
242
|
+
# case sensitive.
|
243
|
+
# @param maps_file [String] the location maps file (default: `locations_map_file`).
|
244
|
+
# - Via `file_manager` it will try to spot the most recently changed.
|
245
|
+
# - The lookup to spot the **path** of the file, tries first as a **relative**
|
246
|
+
# path from `env/config/...`. If it fails, it tries it as an absolute path.
|
247
|
+
# @return [Eco::Data::Mapper, NilClass]
|
248
|
+
def locations_mapper(**kargs)
|
249
|
+
kargs = {
|
250
|
+
internal: :first,
|
251
|
+
insensitive: false,
|
252
|
+
maps_file: nil
|
253
|
+
}.merge(kargs)
|
238
254
|
|
239
|
-
|
240
|
-
|
255
|
+
kargs[:maps_file] ||= locations_map_file
|
256
|
+
kargs[:maps_file] = file_manager.newest(kargs[:maps_file])
|
241
257
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
258
|
+
return unless kargs[:maps_file]
|
259
|
+
|
260
|
+
@locations_mapper ||= {}
|
261
|
+
|
262
|
+
return @locations_mapper[kargs] if @locations_mapper.key?(kargs)
|
263
|
+
|
264
|
+
@locations_mapper[kargs] = Eco::Data::Mapper.new(
|
265
|
+
file_manager.load_json(kargs[:maps_file]),
|
266
|
+
internal: kargs[:internal],
|
267
|
+
insensitive: kargs[:insensitive]
|
247
268
|
)
|
248
269
|
end
|
249
270
|
|
@@ -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
|
data/lib/eco/api/usecases/cli.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
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
|
5
|
+
name 'tagtree-extract'
|
7
6
|
type :other
|
8
7
|
|
9
8
|
include Eco::Data::Files
|
10
9
|
|
11
|
-
OUT_FOLDER =
|
10
|
+
OUT_FOLDER = 'sftp'.freeze
|
12
11
|
OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
|
13
|
-
OUT_FILENAME =
|
12
|
+
OUT_FILENAME = 'live_tree'.freeze
|
14
13
|
|
15
14
|
def process
|
16
15
|
case format
|
@@ -39,7 +38,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
|
|
39
38
|
private
|
40
39
|
|
41
40
|
def compact_name(str)
|
42
|
-
str.gsub(/\s+/,
|
41
|
+
str.gsub(/\s+/, '_').gsub(/\W/, '')[0..30]
|
43
42
|
end
|
44
43
|
|
45
44
|
def str_node_attrs
|
@@ -80,7 +79,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
|
|
80
79
|
end
|
81
80
|
|
82
81
|
def indentation
|
83
|
-
options.dig(:output, :indent) ||
|
82
|
+
options.dig(:output, :indent) || ' '
|
84
83
|
end
|
85
84
|
|
86
85
|
def output_file_format
|
@@ -169,7 +168,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
|
|
169
168
|
out_str = str_ary.join("\n") unless str_ary.empty?
|
170
169
|
|
171
170
|
unless tree.top?
|
172
|
-
node_name = tree.as_json(include_children: false).values_at(*attrs.map(&:to_s)).join(
|
171
|
+
node_name = tree.as_json(include_children: false).values_at(*attrs.map(&:to_s)).join(' ## ')
|
173
172
|
out_head = "#{indent * level}#{node_name}"
|
174
173
|
out_str = out_str ? "#{out_head}\n#{out_str}" : out_head
|
175
174
|
end
|
@@ -178,7 +177,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
|
|
178
177
|
end
|
179
178
|
|
180
179
|
def csv(filename, header = [])
|
181
|
-
CSV.open(filename,
|
180
|
+
CSV.open(filename, 'w') do |csv|
|
182
181
|
csv << header unless header.empty?
|
183
182
|
|
184
183
|
yield(csv)
|
@@ -188,7 +187,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
|
|
188
187
|
end
|
189
188
|
|
190
189
|
def file(filename, &block)
|
191
|
-
File.open(filename,
|
190
|
+
File.open(filename, 'w', &block)
|
192
191
|
ensure
|
193
192
|
log(:info) { "Created file: #{filename}" }
|
194
193
|
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(
|
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)
|
@@ -17,8 +17,8 @@ class Eco::API::UseCases::GraphQL::Samples::Location
|
|
17
17
|
# end
|
18
18
|
# end
|
19
19
|
def inputs(*_args, force_continue: force_continue?, **_kargs, &_block) # rubocop:disable Lint/UnusedMethodArgument
|
20
|
-
msg = "You should implement this method in your child class.\n
|
21
|
-
msg << 'Which should yield the input Hash and the stage or descriptor.
|
20
|
+
msg = "You should implement this method in your child class.\n"
|
21
|
+
msg << 'Which should yield the input Hash and the stage or descriptor.'
|
22
22
|
raise Eco::API::UseCases::GraphQL::Base::NotImplementedMethod, msg
|
23
23
|
end
|
24
24
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Eco::API::UseCases::Lib::Base
|
2
2
|
# Basic stuff you would need in any use case
|
3
|
-
# @note this is intended to be at the foremost part upfront
|
3
|
+
# @note this is intended to be at the foremost part upfront: with **prepend**.
|
4
4
|
module Env
|
5
5
|
class << self
|
6
6
|
def included(base)
|
@@ -14,32 +14,30 @@ module Eco::API::UseCases::Lib::Base
|
|
14
14
|
module InstanceMethods
|
15
15
|
private
|
16
16
|
|
17
|
-
def config
|
18
|
-
session.config
|
19
|
-
end
|
20
|
-
|
21
17
|
def session(required: true)
|
22
|
-
if instance_variable_defined?(:@session) && !@session.nil?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
elsif required
|
29
|
-
raise 'Missing session object'
|
30
|
-
end
|
18
|
+
return @session if instance_variable_defined?(:@session) && !@session.nil?
|
19
|
+
return super() if defined?(super()) && !super().nil?
|
20
|
+
return ASSETS.session if Object.const_defined?(:ASSETS)
|
21
|
+
return unless required
|
22
|
+
|
23
|
+
raise 'Missing session object'
|
31
24
|
end
|
32
25
|
|
33
26
|
def options(required: true)
|
34
|
-
if instance_variable_defined?(:@options) && !@options.nil?
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
return @options if instance_variable_defined?(:@options) && !@options.nil?
|
28
|
+
return super() if defined?(super()) && !super().nil?
|
29
|
+
return ASSETS.cli.options if Object.const_defined?(:ASSETS)
|
30
|
+
return unless required
|
31
|
+
|
32
|
+
raise 'Missing options object'
|
33
|
+
end
|
34
|
+
|
35
|
+
def config
|
36
|
+
session.config
|
37
|
+
end
|
38
|
+
|
39
|
+
def micro
|
40
|
+
session.micro
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|