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
@@ -10,7 +10,7 @@ module Eco::API::UseCases::Lib::Files
|
|
10
10
|
|
11
11
|
# Can't pass this via CLI option, as it breaks the regular expression
|
12
12
|
def file_pattern(required: true)
|
13
|
-
fpc =
|
13
|
+
fpc = file_pattern_from_const
|
14
14
|
return fpc if fpc
|
15
15
|
return unless required
|
16
16
|
|
@@ -19,21 +19,48 @@ module Eco::API::UseCases::Lib::Files
|
|
19
19
|
raise WrongConst, msg
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
22
|
+
def file_pattern_from_const
|
23
|
+
as_regex(insensitive: true) do
|
24
|
+
value = fetch_pattern_const(file_pattern_const_from_options)
|
25
|
+
|
26
|
+
next value unless value.nil?
|
27
|
+
next self.class::FILE_PATTERN if self.class.const_defined?(:FILE_PATTERN)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_pattern_const_from_options
|
32
|
+
return unless (fpc = options.dig(:sftp, :file_pattern_const))
|
33
|
+
|
34
|
+
fpc
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_pattern_const(name, exception: true)
|
38
|
+
return if name.to_s.strip.empty?
|
39
|
+
|
40
|
+
msg = "(#{self.class}) Invalid file pattern const referral: #{name}"
|
41
|
+
raise WrongConst, msg unless name.match(CONST_REFERRAL)
|
42
|
+
|
43
|
+
begin
|
44
|
+
self.eval(name)
|
45
|
+
rescue NameError
|
46
|
+
self.class.const_get(name)
|
34
47
|
end
|
35
48
|
rescue NameError
|
36
|
-
raise WrongConst, "(#{self.class}) Unknown constant: #{
|
49
|
+
raise WrongConst, "(#{self.class}) Unknown constant: #{name}" if exception
|
50
|
+
end
|
51
|
+
|
52
|
+
def as_regex(value = nil, insensitive: true)
|
53
|
+
value = yield if block_given?
|
54
|
+
|
55
|
+
case value
|
56
|
+
when Regexp
|
57
|
+
value
|
58
|
+
when String
|
59
|
+
esub = Regexp.escape(value)
|
60
|
+
return /#{esub}/i if insensitive
|
61
|
+
|
62
|
+
/#{esub}/
|
63
|
+
end
|
37
64
|
end
|
38
65
|
end
|
39
66
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::Files
|
2
|
+
# @note Assumes that, if **Cli** invoked, there could be **Cli** `options` defined
|
3
|
+
# under `:input` `:file`:
|
4
|
+
# - `:name`
|
5
|
+
# - `:format` (overriding `INPUT_FORMAT` const)
|
6
|
+
# - `:encoding`
|
7
|
+
# - `:pattern` (target pattern const)
|
8
|
+
# @note it includes and extends `FilePattern`:
|
9
|
+
# - `file_pattern_from_const` would prioritize constants as accepted
|
10
|
+
# in `INPUT_FILENAME_CONSTS`
|
11
|
+
# - `file_pattern_const_from_options` would prioritize `:input` `:file` `:pattern`
|
12
|
+
module InputFile
|
13
|
+
INPUT_FILENAME_CONSTS = %i[
|
14
|
+
INPUT_FILENAME IN_FILENAME INPUT_FILE_PATTERN IN_FILE_PATTERN
|
15
|
+
]
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def included(base)
|
19
|
+
super
|
20
|
+
|
21
|
+
base.send :include, Eco::API::UseCases::Lib::Base::Env unless base.include?(Eco::API::UseCases::Lib::Base::Env)
|
22
|
+
base.send :extend, Eco::Data::Files::Folder
|
23
|
+
base.send :include, Eco::API::UseCases::Lib::Files::FilePattern
|
24
|
+
base.send :include, InstanceMethods
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
private
|
30
|
+
|
31
|
+
# @todo REVIEW: in practice, it collides with Sftp#local_folder
|
32
|
+
# @todo it is not clear if it should join onto `config.active_enviro`
|
33
|
+
def input_folder
|
34
|
+
File.join(
|
35
|
+
config.active_enviro,
|
36
|
+
self.class::IN_FOLDER
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def input_file
|
41
|
+
@input_file ||= (input_file_from_options || newest_file).tap do |file|
|
42
|
+
if file
|
43
|
+
log(:info) { "Using input file '#{file}'" }
|
44
|
+
else
|
45
|
+
log(:warn) { 'Could not find any input file' }
|
46
|
+
exit 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def input_file_from_options
|
52
|
+
options.dig(:input, :file, :name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @note assuming filenames hold a name pattern `YYYY-MM-dd`.
|
56
|
+
def newest_file
|
57
|
+
@newest_file ||= input_files.last
|
58
|
+
end
|
59
|
+
|
60
|
+
# @note based on `input_folder` && `input_file_pattern`
|
61
|
+
# @todo it some cases it has been used/defined as csv_files
|
62
|
+
def input_files(&block)
|
63
|
+
self.class.folder_files(
|
64
|
+
input_folder,
|
65
|
+
input_format,
|
66
|
+
regexp: input_file_pattern,
|
67
|
+
&block
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def input_encoding
|
72
|
+
options.dig(:input, :file, :encoding) || 'utf-8'
|
73
|
+
end
|
74
|
+
|
75
|
+
# It helps to identify the extension of the input file.
|
76
|
+
# @note it may not be essential, but good practice as a safe-guard.
|
77
|
+
def input_format
|
78
|
+
frm = options.dig(:input, :file, :format)
|
79
|
+
return frm if frm
|
80
|
+
return self.class::INPUT_FORMAT.to_sym if self.class.const_defined?(:INPUT_FORMAT)
|
81
|
+
|
82
|
+
:csv
|
83
|
+
end
|
84
|
+
|
85
|
+
def input_file_pattern
|
86
|
+
file_pattern
|
87
|
+
end
|
88
|
+
|
89
|
+
# Overrides to FilePattern
|
90
|
+
|
91
|
+
def file_pattern_from_const
|
92
|
+
as_regex(insensitive: true) do
|
93
|
+
value = INPUT_FILENAME_CONSTS.detect do |const|
|
94
|
+
next self.class.const_get(const) if self.class.const_defined?(const)
|
95
|
+
end
|
96
|
+
|
97
|
+
next value if value
|
98
|
+
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def file_pattern_const_from_options
|
104
|
+
return super unless (fpc = options.dig(:input, :file, :pattern))
|
105
|
+
|
106
|
+
fpc
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -74,10 +74,10 @@ module Eco::API::UseCases::Lib::Files
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def sftp_archive_file!(filename,
|
77
|
+
def sftp_archive_file!(filename, subfolder: 'Archive')
|
78
78
|
basename = File.basename(filename)
|
79
79
|
remote_file = to_remote_path(basename)
|
80
|
-
archive_folder = to_remote_path(
|
80
|
+
archive_folder = to_remote_path(subfolder)
|
81
81
|
archived_file = "#{archive_folder}/#{basename}"
|
82
82
|
|
83
83
|
sftp_move_file(remote_file, archived_file)
|
@@ -124,6 +124,9 @@ module Eco::API::UseCases::Lib::Files
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
# @note it can be used for both:
|
128
|
+
# - for pulling files to
|
129
|
+
# - and for pushing files from
|
127
130
|
def local_folder
|
128
131
|
return super if defined?(super) && !super.nil?
|
129
132
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::Locations
|
2
|
+
module Base
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
super
|
6
|
+
|
7
|
+
base.send :include, Eco::API::UseCases::Lib::Base::Env unless base.included?(Eco::API::UseCases::Lib::Base::Env)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def location?(value)
|
14
|
+
locations.tag?(value)
|
15
|
+
end
|
16
|
+
alias_method :tag?, :location?
|
17
|
+
|
18
|
+
def locations
|
19
|
+
config.tagtree
|
20
|
+
end
|
21
|
+
alias_method :tagtree, :locations
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::Locations
|
2
|
+
module Mapping
|
3
|
+
LOCATION_MAPPING = true
|
4
|
+
LOCATION_MAPS_FILE = nil
|
5
|
+
LOCATION_MAPS_INTERNAL = :first
|
6
|
+
LOCATION_MAPS_INSENSITIVE = true
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def included(base)
|
10
|
+
super
|
11
|
+
|
12
|
+
base.send :include, Locations::Base
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def unknown_locations
|
17
|
+
@unknown_locations ||=
|
18
|
+
Eco::Data::CountTrace.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def report_unknown_locations!(msg: nil, level: :warn)
|
22
|
+
unknown_locations.report!(msg: msg, level: level)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def to_location(value)
|
28
|
+
value = value.to_s.strip
|
29
|
+
return if value.empty?
|
30
|
+
|
31
|
+
if location_mapping? && locations_mapper.external?(value)
|
32
|
+
locations_mapper.to_internal(value)
|
33
|
+
elsif location?(value)
|
34
|
+
value
|
35
|
+
else
|
36
|
+
unknown_locations.trace!(value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias_method :to_tag, :to_location
|
40
|
+
|
41
|
+
def to_location_code(value)
|
42
|
+
value = value.to_s.strip
|
43
|
+
return if value.empty?
|
44
|
+
|
45
|
+
if location_mapping? && locations_mapper.internal?(value)
|
46
|
+
locations_mapper.to_external(value)
|
47
|
+
else
|
48
|
+
value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def locations_mapper(
|
53
|
+
internal: loc_maps_internal_order,
|
54
|
+
insensitive: loc_maps_insensitive,
|
55
|
+
maps_file: loc_maps_file
|
56
|
+
)
|
57
|
+
return @locations_mapper if instance_variable_defined?(:@locations_mapper)
|
58
|
+
|
59
|
+
@locations_mapper = config.locations_mapper(
|
60
|
+
internal: internal,
|
61
|
+
insensitive: insensitive,
|
62
|
+
maps_file: maps_file
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def location_mapping?
|
67
|
+
return false unless self.class::LOCATION_MAPPING
|
68
|
+
return false unless loc_maps_file
|
69
|
+
return false unless locations_mapper
|
70
|
+
return false unless locatoins_mapper.empty?
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def loc_maps_file
|
76
|
+
return @loc_maps_file if instance_variable_defined?(:@loc_maps_file)
|
77
|
+
|
78
|
+
@loc_maps_file = loc_maps_file_const
|
79
|
+
@loc_maps_file ||= config.locations_map_file
|
80
|
+
end
|
81
|
+
|
82
|
+
def loc_maps_file_const
|
83
|
+
self.class::LOCATION_MAPS_FILE if self.class.const_defined?(:MAPS_FILE)
|
84
|
+
end
|
85
|
+
|
86
|
+
def loc_maps_internal_order
|
87
|
+
self.class::LOCATION_MAPS_INTERNAL
|
88
|
+
end
|
89
|
+
|
90
|
+
def loc_maps_insensitive
|
91
|
+
self.class::LOCATION_MAPS_INSENSITIVE
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eco::API::UseCases::Lib::People
|
2
|
+
module Base
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
super
|
6
|
+
|
7
|
+
base.send :include, Eco::API::UseCases::Lib::Base::Env unless base.included?(Eco::API::UseCases::Lib::Base::Env)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def people
|
14
|
+
return @people if instance_variable_defined?(:@people) && !@people.nil?
|
15
|
+
return super if defined?(super) && !super.nil?
|
16
|
+
|
17
|
+
@people ||= micro.people_load(modifier: %i[newest save])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/eco/api/usecases/lib.rb
CHANGED
@@ -57,6 +57,8 @@ class Eco::API::UseCases::Samples::Drivers::Sftp < Eco::API::Common::Loaders::Us
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
# @todo when `sftp_move_file` fails, it still `puts` the message
|
61
|
+
# that it moved the file(s) to the `archive_subfolder`
|
60
62
|
def archive_files
|
61
63
|
with_remote_files(pattern: file_pattern) do |file|
|
62
64
|
source = to_remote_path(file.name) # should probably be file.longname
|
@@ -62,7 +62,12 @@ class Eco::API::UseCases::Samples::Drivers::UrlPull < Eco::API::Common::Loaders:
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def http_start(uri, &block)
|
65
|
-
Net::HTTP.start(
|
65
|
+
Net::HTTP.start(
|
66
|
+
uri.hostname,
|
67
|
+
uri.port,
|
68
|
+
request_options(uri),
|
69
|
+
&block
|
70
|
+
)
|
66
71
|
end
|
67
72
|
|
68
73
|
def base_request(uri, user: nil, pass: '')
|
@@ -95,7 +100,8 @@ class Eco::API::UseCases::Samples::Drivers::UrlPull < Eco::API::Common::Loaders:
|
|
95
100
|
|
96
101
|
def target_url_const
|
97
102
|
if (fpc = options.dig(:url_pull, :target_url_const))
|
98
|
-
|
103
|
+
msg = "(#{self.class}) Invalid file pattern const referral: #{fpc}"
|
104
|
+
raise WrongConst, msg unless fpc.match(CONST_REFERRAL)
|
99
105
|
|
100
106
|
begin
|
101
107
|
self.eval(fpc)
|
@@ -36,39 +36,6 @@ module Eco::API::UseCases::Service
|
|
36
36
|
self.class::ENV_PATHS if self.class.const_defined?(:ENV_PATHS)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
# module ClassMethods
|
41
|
-
# def wrap_with_target_sftp(*mtds)
|
42
|
-
# mtds.map(&:to_sym).each do |method_name|
|
43
|
-
# msg = "#{self} does not have instance method '#{method_name}'"
|
44
|
-
# has_method = instance_method?(name: method_name, include_private: true, inherited: true)
|
45
|
-
# raise ArgumentError, msg unless has_method
|
46
|
-
#
|
47
|
-
# method_was_inherited = instance_inherited_method?(name: method_name)
|
48
|
-
# method_is_public = instance_method?(name: method_name, include_private: false)
|
49
|
-
# original_method = :"method_to_wrap_with_target_sftp_#{method_name}"
|
50
|
-
#
|
51
|
-
# # don't over-override
|
52
|
-
# next if instance_method?(name: original_method, include_private: true, inherited: true)
|
53
|
-
#
|
54
|
-
# method_def = proc do |*args, **kargs, &block|
|
55
|
-
# with_target_sftp_config do
|
56
|
-
# if method_was_inherited
|
57
|
-
# super(*args, **kargs, &block)
|
58
|
-
# else
|
59
|
-
# send(original_method, *args, **kargs, &block)
|
60
|
-
# end
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# alias_method(original_method, method_name) unless method_was_inherited
|
65
|
-
# define_method(method_name, &method_def)
|
66
|
-
# private method_name unless method_is_public
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# self
|
70
|
-
# end
|
71
|
-
# end
|
72
39
|
end
|
73
40
|
end
|
74
41
|
end
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require_relative 'sftp/with_target_config'
|
2
2
|
module Eco::API::UseCases::Service
|
3
3
|
# Class that pulls configuration from the subject (i.e. `remote_folder`)
|
4
|
+
# @note It accepts modify the targt SFTP in subclasses by defining two constants:
|
5
|
+
# - `BASE_PATH` (String)
|
6
|
+
# - `ENV_PATHS` (Hash)
|
7
|
+
# @note it makes public all methods of the `Files::Sftp` module.
|
4
8
|
class Sftp
|
9
|
+
include Eco::Language::Methods::AccessModifier
|
5
10
|
include Eco::API::UseCases::Lib::Files::Sftp
|
6
|
-
|
11
|
+
|
12
|
+
make_public_all from: Eco::API::UseCases::Lib::Files::Sftp, inherited: false
|
7
13
|
|
8
14
|
include WithTargetConfig
|
9
15
|
|
@@ -26,7 +26,7 @@ module Eco
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def source_object
|
29
|
-
return
|
29
|
+
return unless callback_from_loader?
|
30
30
|
|
31
31
|
callback_self
|
32
32
|
end
|
@@ -77,7 +77,7 @@ module Eco
|
|
77
77
|
attr_reader :callback
|
78
78
|
|
79
79
|
def callback_self
|
80
|
-
eval(
|
80
|
+
eval('self', callback.binding, __FILE__, __LINE__)
|
81
81
|
end
|
82
82
|
|
83
83
|
def callback_from_loader?
|
@@ -86,6 +86,7 @@ module Eco
|
|
86
86
|
|
87
87
|
# Set the instance variables `@session` and `@options`
|
88
88
|
# in the use case definition
|
89
|
+
# @todo check if this method shouldn't really just be part of `uio`
|
89
90
|
# @note this only works when the use case was defined
|
90
91
|
# via an children class of `Eco::API::Common::Loaders::Base`
|
91
92
|
def set_session_n_options(uio) # rubocop:disable Naming/AccessorMethodName
|
data/lib/eco/api/usecases.rb
CHANGED
@@ -19,7 +19,7 @@ module Eco
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
extend Eco::
|
22
|
+
extend Eco::Language::Klass::AutoLoader
|
23
23
|
include Enumerable
|
24
24
|
|
25
25
|
autoloads_children_of 'Eco::API::Common::Loaders::UseCase'
|
@@ -29,6 +29,7 @@ module Eco
|
|
29
29
|
@usecases = {}
|
30
30
|
@cache_init = false
|
31
31
|
@cases_by_name = {}
|
32
|
+
|
32
33
|
init_caches
|
33
34
|
end
|
34
35
|
|
@@ -52,6 +53,7 @@ module Eco
|
|
52
53
|
|
53
54
|
def defined?(name, type: nil)
|
54
55
|
return to_h.key?(key(name, type)) if type
|
56
|
+
|
55
57
|
name?(name)
|
56
58
|
end
|
57
59
|
|
@@ -83,7 +85,8 @@ module Eco
|
|
83
85
|
puts "Warning: overriding '#{type}' case #{name}" if self.defined?(name, type: type)
|
84
86
|
|
85
87
|
to_h[key(name, type)] = usecase
|
86
|
-
@cache_init
|
88
|
+
@cache_init = false
|
89
|
+
|
87
90
|
usecase
|
88
91
|
end
|
89
92
|
|
@@ -102,7 +105,9 @@ module Eco
|
|
102
105
|
msg = "Expected a Eco::API::UseCases object. Given #{cases.class}"
|
103
106
|
raise msg unless cases.is_a?(Eco::API::UseCases)
|
104
107
|
|
105
|
-
to_h.merge!(
|
108
|
+
to_h.merge!(
|
109
|
+
cases.to_h
|
110
|
+
).transform_values do |usecase|
|
106
111
|
usecase.root = self
|
107
112
|
end
|
108
113
|
|
@@ -126,6 +131,7 @@ module Eco
|
|
126
131
|
elsif type
|
127
132
|
raise UseCases::UnknownCase.new(case_name: name, type: type)
|
128
133
|
end
|
134
|
+
|
129
135
|
raise UseCases::UnknownCase.new(case_name: name, type: type) unless (cases = by_name[name])
|
130
136
|
raise UseCases::AmbiguousCaseReference.new(case_name: name) if cases.length > 1
|
131
137
|
|
@@ -148,10 +154,10 @@ module Eco
|
|
148
154
|
|
149
155
|
def init_caches
|
150
156
|
# first, make sure it loads pending `:custom_children` children to be loaded
|
151
|
-
re_init = self.class.autoload_children(self)
|
157
|
+
re_init = self.class.autoload_children!(self)
|
152
158
|
return true if @cache_init && !re_init
|
153
159
|
|
154
|
-
@by_name
|
160
|
+
@by_name = @usecases.values.group_by(&:name)
|
155
161
|
@cache_init = true
|
156
162
|
end
|
157
163
|
|
@@ -176,6 +182,7 @@ require_relative 'usecases/use_case_chain'
|
|
176
182
|
require_relative 'usecases/base_io'
|
177
183
|
require_relative 'usecases/use_case_io'
|
178
184
|
require_relative 'usecases/cli'
|
185
|
+
require_relative 'usecases/workflow'
|
179
186
|
require_relative 'usecases/lib'
|
180
187
|
require_relative 'usecases/service'
|
181
188
|
require_relative 'usecases/graphql'
|
@@ -105,7 +105,7 @@ module Eco
|
|
105
105
|
if required && !filename
|
106
106
|
puts "You need to specify a file or folder '#{key} file_or_folder'"
|
107
107
|
exit(1)
|
108
|
-
elsif should_exist && filename && !
|
108
|
+
elsif should_exist && filename && !File.exist?(filename)
|
109
109
|
puts "This file/folder doesn't exist '#{filename}'"
|
110
110
|
exit(1)
|
111
111
|
end
|
@@ -113,14 +113,6 @@ module Eco
|
|
113
113
|
filename = File.expand_path(filename) if filename && should_exist
|
114
114
|
filename
|
115
115
|
end
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
def file_exists?(filename)
|
120
|
-
return false if filename.nil?
|
121
|
-
|
122
|
-
File.exist?(filename) || File.exist?(File.expand_path(filename))
|
123
|
-
end
|
124
116
|
end
|
125
117
|
end
|
126
118
|
end
|