eco-helpers 3.0.25 → 3.0.27

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -1
  3. data/eco-helpers.gemspec +1 -1
  4. data/lib/eco/api/common/loaders/base.rb +13 -1
  5. data/lib/eco/api/common/loaders/case_base.rb +1 -1
  6. data/lib/eco/api/common/loaders/error_handler.rb +1 -1
  7. data/lib/eco/api/common/loaders/parser.rb +2 -2
  8. data/lib/eco/api/common/loaders/policy.rb +1 -1
  9. data/lib/eco/api/common/loaders/use_case.rb +1 -1
  10. data/lib/eco/api/common/people/default_parsers/archived_parser.rb +19 -0
  11. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +4 -4
  12. data/lib/eco/api/common/people/default_parsers/date_parser.rb +3 -3
  13. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +6 -6
  14. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +3 -3
  15. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +4 -4
  16. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +9 -6
  17. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -5
  18. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +2 -2
  19. data/lib/eco/api/common/people/default_parsers.rb +1 -0
  20. data/lib/eco/api/common/people/entries.rb +16 -15
  21. data/lib/eco/api/common/people/person_entry.rb +53 -37
  22. data/lib/eco/api/common/people/person_parser.rb +8 -6
  23. data/lib/eco/api/common/session/logger/channels.rb +1 -1
  24. data/lib/eco/api/common/session/logger.rb +2 -2
  25. data/lib/eco/api/common/session/mailer/aws_provider.rb +3 -2
  26. data/lib/eco/api/common/session/mailer/provider_base.rb +6 -2
  27. data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +9 -9
  28. data/lib/eco/api/common/session/mailer.rb +8 -3
  29. data/lib/eco/api/common/session/sftp.rb +2 -2
  30. data/lib/eco/api/common/version_patches/object.rb +2 -1
  31. data/lib/eco/api/custom/mailer.rb +1 -1
  32. data/lib/eco/api/error/handlers.rb +3 -3
  33. data/lib/eco/api/error.rb +17 -17
  34. data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +3 -11
  35. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +4 -1
  36. data/lib/eco/api/microcases/people/manage/search.rb +3 -1
  37. data/lib/eco/api/organization/people.rb +1 -0
  38. data/lib/eco/api/policies.rb +2 -2
  39. data/lib/eco/api/session/batch/job.rb +2 -2
  40. data/lib/eco/api/session/batch/launcher.rb +4 -5
  41. data/lib/eco/api/session/batch/searcher.rb +4 -4
  42. data/lib/eco/api/session/config/api.rb +2 -2
  43. data/lib/eco/api/session/config/apis/enviro_spaces.rb +3 -3
  44. data/lib/eco/api/session/config/apis/space_helpers.rb +4 -4
  45. data/lib/eco/api/session/config/apis.rb +1 -1
  46. data/lib/eco/api/session/config/post_launch.rb +7 -4
  47. data/lib/eco/api/session/config/sftp.rb +1 -1
  48. data/lib/eco/api/session/config/tagtree.rb +1 -1
  49. data/lib/eco/api/session/config/workflow.rb +4 -4
  50. data/lib/eco/api/session/config.rb +25 -24
  51. data/lib/eco/api/session.rb +4 -4
  52. data/lib/eco/api/usecases/base_io/validations.rb +4 -3
  53. data/lib/eco/api/usecases/cli/option.rb +5 -2
  54. data/lib/eco/api/usecases/default/people/amend/clear_abilities_case.rb +2 -2
  55. data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +16 -9
  56. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +20 -20
  57. data/lib/eco/api/usecases/default.rb +5 -5
  58. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +8 -8
  59. data/lib/eco/api/usecases/default_cases/upsert_case.rb +4 -4
  60. data/lib/eco/api/usecases/graphql/helpers/base.rb +1 -1
  61. data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +5 -1
  62. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -1
  63. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +3 -3
  64. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +3 -0
  65. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  66. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +9 -3
  67. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +5 -4
  68. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +5 -2
  69. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +3 -3
  70. data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
  71. data/lib/eco/api/usecases/lib/{file_pattern.rb → files/file_pattern.rb} +5 -1
  72. data/lib/eco/api/usecases/lib/{sftp.rb → files/sftp.rb} +27 -16
  73. data/lib/eco/api/usecases/lib/files.rb +7 -0
  74. data/lib/eco/api/usecases/lib.rb +1 -2
  75. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +5 -5
  76. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +14 -11
  77. data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +14 -23
  78. data/lib/eco/api/usecases/ooze_samples/helpers_migration/typed_fields_pairing.rb +49 -27
  79. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +9 -9
  80. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +1 -1
  81. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +25 -17
  82. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +41 -24
  83. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +16 -15
  84. data/lib/eco/api/usecases/samples/drivers/cli/sftp_cli.rb +15 -15
  85. data/lib/eco/api/usecases/samples/drivers/cli/url_pull_cli.rb +5 -5
  86. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -2
  87. data/lib/eco/api/usecases/use_case.rb +6 -6
  88. data/lib/eco/api/usecases/use_case_chain/chaining.rb +6 -6
  89. data/lib/eco/api/usecases/use_case_chain.rb +4 -4
  90. data/lib/eco/api/usecases/use_case_io.rb +2 -1
  91. data/lib/eco/api/usecases.rb +9 -9
  92. data/lib/eco/cli/config/options_set.rb +4 -4
  93. data/lib/eco/cli/config/use_cases.rb +3 -3
  94. data/lib/eco/cli/scripting/argument.rb +1 -1
  95. data/lib/eco/cli_default/input.rb +9 -9
  96. data/lib/eco/cli_default/options.rb +125 -100
  97. data/lib/eco/cli_default/people.rb +3 -3
  98. data/lib/eco/cli_default/usecases.rb +83 -83
  99. data/lib/eco/cli_default/workflow.rb +7 -7
  100. data/lib/eco/data/files/helpers.rb +3 -3
  101. data/lib/eco/data/fuzzy_match/result.rb +69 -26
  102. data/lib/eco/data/fuzzy_match/results.rb +10 -10
  103. data/lib/eco/data/fuzzy_match/score.rb +13 -8
  104. data/lib/eco/data/fuzzy_match.rb +65 -48
  105. data/lib/eco/data/locations/node_base/treeify.rb +13 -11
  106. data/lib/eco/data/mapper.rb +4 -4
  107. data/lib/eco/language/auxiliar_logger.rb +4 -4
  108. data/lib/eco/language/delegation/const_delegator.rb +64 -0
  109. data/lib/eco/language/delegation/const_lookup_hooks.rb +81 -0
  110. data/lib/eco/language/delegation/delegated_class.rb +84 -0
  111. data/lib/eco/language/delegation.rb +8 -0
  112. data/lib/eco/language/klass/when_inherited.rb +1 -0
  113. data/lib/eco/language/methods/delegate_missing.rb +1 -0
  114. data/lib/eco/language/models/class_helpers.rb +25 -23
  115. data/lib/eco/language/models/collection.rb +12 -2
  116. data/lib/eco/language.rb +1 -0
  117. data/lib/eco/version.rb +1 -1
  118. metadata +12 -6
@@ -1,5 +1,5 @@
1
1
  class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Loaders::UseCase
2
- name "analyse-people"
2
+ name 'analyse-people'
3
3
  type :export
4
4
 
5
5
  require_relative 'cli/analyse_people_cli'
@@ -12,7 +12,7 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
12
12
  elsif case_options[:identify_unnamed]
13
13
  identify_unnamed
14
14
  else
15
- log(:info) { "No analysis operation was specified" }
15
+ log(:info) { 'No analysis operation was specified' }
16
16
  end.tap do |people_involved|
17
17
  next unless people_involved
18
18
 
@@ -27,7 +27,7 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
27
27
  similarity_analytics.unnamed.tap do |unnamed|
28
28
  next unless unnamed.empty?
29
29
 
30
- log(:info) { "There were no people with no name!!" }
30
+ log(:info) { 'There were no people with no name!!' }
31
31
  end
32
32
  end
33
33
 
@@ -35,13 +35,13 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
35
35
  analysed = similarity_screening
36
36
 
37
37
  if case_options[:ignore_matching_words]
38
- log(:info) { "Fine tune results by ignoring matching words..." }
38
+ log(:info) { 'Fine tune results by ignoring matching words...' }
39
39
  analysed = strict_similarity(analysed)
40
40
  end
41
41
 
42
42
  similarity_analytics.newSimilarity(analysed).tap do |related_people|
43
43
  if related_people.empty?
44
- log(:info) { "There were no possible duplicates identified!!" }
44
+ log(:info) { 'There were no possible duplicates identified!!' }
45
45
  else
46
46
  report = similarity_analytics.report(analysed, format: :txt)
47
47
  save!(report)
@@ -157,23 +157,23 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
157
157
  end
158
158
 
159
159
  def output_file
160
- @output_file ||= options.dig(:output, :file) || "analytics.txt"
160
+ @output_file ||= options.dig(:output, :file) || 'analytics.txt'
161
161
  end
162
162
 
163
163
  def save!(data)
164
- ext = File.extname(output_file).downcase.delete(".")
164
+ ext = File.extname(output_file).downcase.delete('.')
165
165
 
166
166
  log(:info) { "Generating file '#{output_file}'" }
167
167
 
168
- File.open(output_file, "w") do |fd|
168
+ File.open(output_file, 'w') do |fd|
169
169
  case ext
170
- when "txt"
170
+ when 'txt'
171
171
  fd << data
172
- when "html"
173
- puts "html is still not supported"
172
+ when 'html'
173
+ puts 'html is still not supported'
174
174
  exit(1)
175
- when "json"
176
- puts "json is still not supported"
175
+ when 'json'
176
+ puts 'json is still not supported'
177
177
  exit(1)
178
178
  end
179
179
  end
@@ -182,11 +182,11 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
182
182
  # A way to use command line to specify part
183
183
  # => i.e. details[first-name] AND details[surname]
184
184
  def proc_value_access(expression)
185
- #return expression.to_sym if expression.start_with?(":")
186
- subexpressions = expression.split(" AND ")
185
+ #return expression.to_sym if expression.start_with?(':')
186
+ subexpressions = expression.split(' AND ')
187
187
  proc do |person|
188
188
  values = subexpressions.map {|exp| attribute_access(person, exp)}
189
- values.compact.join(" ")
189
+ values.compact.join(' ')
190
190
  end
191
191
  end
192
192
 
@@ -216,9 +216,9 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
216
216
 
217
217
  is_method = part.is_a?(Symbol) || obj.respond_to?(part.to_sym)
218
218
  return obj.send(part.to_sym) if is_method
219
- return get_attr(obj, part[1..]) if part.start_with?(":")
219
+ return get_attr(obj, part[1..]) if part.start_with?(':')
220
220
 
221
- if part.start_with?("details[")
221
+ if part.start_with?('details[')
222
222
  via_details = obj.respond_to?(:details) && (details = obj.details)
223
223
  return unless via_details
224
224
 
@@ -228,11 +228,11 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
228
228
  raise "Review your -use-field expression. It should read: person.details[target-alt_id]"
229
229
  end
230
230
 
231
- if part.start_with?("account")
231
+ if part.start_with?('account')
232
232
  return obj.respond_to?(:account) ? obj.account : nil
233
233
  end
234
234
 
235
- return obj if part.start_with?("person")
235
+ return obj if part.start_with?('person')
236
236
 
237
237
  raise "Review your expression. Cannot recognize '#{part}' as part of '#{obj.class}'"
238
238
  end
@@ -2,11 +2,11 @@ module Eco
2
2
  module API
3
3
  class UseCases
4
4
  class Default < Eco::API::UseCases
5
- # autoloads_children_of "Eco::API::Common::Loaders::UseCase"
6
- # autoload_namespace "Eco::API::UseCases::Default"
7
- # autoload_namespace "Eco::API::UseCases::DefaultCases"
8
- # autoload_namespace "Eco::API::UseCases::OozeCases"
9
- # autoload_namespace "Eco::API::UseCases::GraphQL::Cases"
5
+ # autoloads_children_of 'Eco::API::Common::Loaders::UseCase'
6
+ # autoload_namespace 'Eco::API::UseCases::Default'
7
+ # autoload_namespace 'Eco::API::UseCases::DefaultCases'
8
+ # autoload_namespace 'Eco::API::UseCases::OozeCases'
9
+ # autoload_namespace 'Eco::API::UseCases::GraphQL::Cases'
10
10
  end
11
11
  end
12
12
  end
@@ -1,5 +1,5 @@
1
1
  class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::UseCase
2
- name "to-csv"
2
+ name 'to-csv'
3
3
  type :export
4
4
 
5
5
  OUT_FILENAME = 'pm'.freeze
@@ -8,14 +8,14 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
8
8
  options[:end_get] = false
9
9
 
10
10
  unless people && !people.empty?
11
- log(:warn) { "No source people to create the file... aborting!" }
11
+ log(:warn) { 'No source people to create the file... aborting!' }
12
12
  return false
13
13
  end
14
14
 
15
15
  if options.dig(:export, :options, :split_schemas)
16
16
  by_schema.each do |id, people|
17
17
  sch_name = schemas.to_name(id)
18
- prefix = sch_name ? sch_name.gsub(" ", "_").downcase : "no_schema"
18
+ prefix = sch_name ? sch_name.gsub(' ', '_').downcase : 'no_schema'
19
19
  filename = in_folder("#{prefix}_#{File.basename(file)}")
20
20
  create_file!(filename, people)
21
21
  end
@@ -29,7 +29,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
29
29
  def create_file!(filename = file, data = people)
30
30
  session.log(:info) { "going to create file: #{filename}" }
31
31
 
32
- CSV.open(filename, "w") do |csv|
32
+ CSV.open(filename, 'w') do |csv|
33
33
  csv << spot_header(data.first)
34
34
  data.each do |person|
35
35
  csv << to_row(person)
@@ -40,13 +40,13 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
40
40
  def to_row(person)
41
41
  entry = to_entry_type(person)
42
42
  entry.values_at(*keys(entry)).tap do |row|
43
- row << (schemas.to_name(person.details&.schema_id) || "No Schema")
43
+ row << (schemas.to_name(person.details&.schema_id) || 'No Schema')
44
44
  end
45
45
  end
46
46
 
47
47
  def spot_header(person = people.first)
48
48
  header = keys(to_entry_type(person))
49
- header << "Schema"
49
+ header << 'Schema'
50
50
  header = yield(header) if block_given?
51
51
  header = nice_header_names(header, schema: schema(person.details)) if nice_header_names?
52
52
  header
@@ -73,14 +73,14 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
73
73
  end
74
74
 
75
75
  def deps
76
- @deps ||= {"supervisor_id" => {people: people}}
76
+ @deps ||= {'supervisor_id' => {people: people}}
77
77
  end
78
78
 
79
79
  def file
80
80
  @file ||= out_filename.tap do |filename|
81
81
  next if filename
82
82
 
83
- log(:error) { "Destination file not specified" }
83
+ log(:error) { 'Destination file not specified' }
84
84
  return false
85
85
  end
86
86
  end
@@ -1,12 +1,12 @@
1
1
  class Eco::API::UseCases::DefaultCases::UpsertCase < Eco::API::Common::Loaders::UseCase
2
- name "upsert"
2
+ name 'upsert'
3
3
  type :sync
4
4
 
5
5
  def main(entries, people, session, options, usecase)
6
6
  micro = session.micro
7
- creation = session.new_job("main", "create", :create, usecase)
8
- update = session.new_job("main", "update", :update, usecase)
9
- supers = session.new_job("post", "supers", :update, usecase, :core)
7
+ creation = session.new_job('main', 'create', :create, usecase)
8
+ update = session.new_job('main', 'update', :update, usecase)
9
+ supers = session.new_job('post', 'supers', :update, usecase, :core)
10
10
 
11
11
  micro.with_each(entries, people, options, append_created: append_created) do |entry, person|
12
12
  person.new? ? creation.add(person) : update.add(person)
@@ -11,7 +11,7 @@ module Eco::API::UseCases::GraphQL::Helpers
11
11
 
12
12
  # Keep a copy of the requests/responses for future reference
13
13
  def backup(data, type:)
14
- dry_run = simulate? ? "_dry_run" : ""
14
+ dry_run = simulate? ? '_dry_run' : ''
15
15
  dir = config.people.requests_folder
16
16
  file = File.join(dir, "#{type}#{dry_run}.json")
17
17
  session.file_manager.save_json(data, file, :timestamp)
@@ -35,7 +35,11 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
35
35
 
36
36
  latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree)
37
37
  if tree.respond_to?(:treeify) && track_current_tree?
38
- latest_tree ||= Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name)
38
+ latest_tree ||= Eco::API::Organization::TagTree.new(
39
+ tree.treeify,
40
+ id: tree.id,
41
+ name: tree.name
42
+ )
39
43
  end
40
44
 
41
45
  latest_tree.tap do
@@ -37,7 +37,8 @@ class Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
37
37
  end
38
38
 
39
39
  def stage_diffs(stage)
40
- raise "There is NO support for stage '#{stage}'. Please review" unless respond_to?(stage)
40
+ msg = "There is NO support for stage '#{stage}'. Please review"
41
+ raise ArgumentError, msg unless respond_to?(stage)
41
42
 
42
43
  sort_diffs(stage) do
43
44
  send(stage)
@@ -60,13 +60,13 @@ module Eco::API::UseCases::GraphQL::Helpers::Location::Command
60
60
  def command_id
61
61
  return unless result
62
62
 
63
- command_result["id"]
63
+ command_result['id']
64
64
  end
65
65
 
66
66
  def as_json
67
67
  {
68
- "request" => input,
69
- "response" => result.doc
68
+ 'request' => input,
69
+ 'response' => result.doc
70
70
  }
71
71
  end
72
72
  end
@@ -72,13 +72,16 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
72
72
  pages = (total.to_f / size).ceil.to_i
73
73
  page = 1
74
74
  out = []
75
+
75
76
  comms.each_slice(size) do |comms_slice|
76
77
  sliced_input = input_data.slice(:clientMutationId, :id).merge(commands: comms_slice)
78
+
77
79
  yield(sliced_input, page, pages, comms_slice.count, total).tap do |response|
78
80
  out.push([sliced_input, response])
79
81
  page += 1
80
82
  end
81
83
  end
84
+
82
85
  out
83
86
  end
84
87
  end
@@ -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
 
@@ -8,6 +8,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
8
8
  class << self
9
9
  def included(base)
10
10
  super
11
+
11
12
  base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
12
13
  base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL
13
14
  base.send :include, Eco::API::UseCases::GraphQL::Utils::Sftp
@@ -40,7 +41,11 @@ class Eco::API::UseCases::GraphQL::Samples::Location
40
41
  original_tree: current_tree,
41
42
  logger: logger
42
43
  ).tap do |nodes_diff|
43
- archive_input = input(nodes_diff.stage_commands(:archive), force_continue: true)
44
+ archive_input = input(
45
+ nodes_diff.stage_commands(:archive),
46
+ force_continue: true
47
+ )
48
+
44
49
  sliced_batches(
45
50
  archive_input,
46
51
  desc: stage,
@@ -48,6 +53,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
48
53
  ) do |sliced_input, response, page, pages, count, total| # rubocop:disable Metrics/ParameterLists
49
54
  page_results = request_results_class.new(sliced_input, response)
50
55
  (results[stage] ||= []) << page_results
56
+
51
57
  self.error ||= page_errors?(page_results, page, pages, count, total, stage: stage)
52
58
  end
53
59
  end
@@ -89,8 +95,8 @@ class Eco::API::UseCases::GraphQL::Samples::Location
89
95
  return if options.dig(:workflow, :no_email)
90
96
 
91
97
  digest_msgs = logger.cache.logs(level: %i[info error warn])
92
- str_exception = exception ? " - Exception!" : ''
93
- str_exception = " - Aborted!" if exiting?
98
+ str_exception = exception ? ' - Exception!' : ''
99
+ str_exception = ' - Aborted!' if exiting?
94
100
 
95
101
  subject = "#{config.active_enviro} - #{title}#{str_exception}"
96
102
 
@@ -4,14 +4,15 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
4
4
  module Inputable
5
5
  class << self
6
6
  def included(base)
7
- super(base)
7
+ super
8
+
8
9
  base.send :include, Eco::Data::Files
9
10
  end
10
11
  end
11
12
 
12
13
  include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
13
14
 
14
- IN_FILENAME = /requested_tree\.csv/.freeze
15
+ IN_FILENAME = /requested_tree\.csv/
15
16
  IN_FOLDER = 'sftp'.freeze
16
17
 
17
18
  private
@@ -25,7 +26,7 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
25
26
  if file
26
27
  log(:info) { "Using input file '#{file}'" }
27
28
  else
28
- log(:warn) { "Could not find any input file" }
29
+ log(:warn) { 'Could not find any input file' }
29
30
  exit(1)
30
31
  end
31
32
  end
@@ -45,7 +46,7 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
45
46
  end
46
47
 
47
48
  def input_folder
48
- "#{config.active_enviro}/#{self.class::IN_FOLDER}"
49
+ File.join(config.active_enviro, self.class::IN_FOLDER)
49
50
  end
50
51
  end
51
52
  end
@@ -26,18 +26,21 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
26
26
  row_transform&.call(row)
27
27
  transform_classifications(row)
28
28
  end
29
+
29
30
  csv
30
31
  end
31
32
 
32
33
  # The user define block for row transformation
33
34
  def custom_input_row_transform_block
34
- return nil unless respond_to?(:custom_input_row_transform, true)
35
+ return unless respond_to?(:custom_input_row_transform, true)
36
+
35
37
  method(:custom_input_row_transform)
36
38
  end
37
39
 
38
40
  # The user define block for row transformation
39
41
  def custom_input_csv_transform_block
40
- return nil unless respond_to?(:custom_input_csv_transform, true)
42
+ return unless respond_to?(:custom_input_csv_transform, true)
43
+
41
44
  method(:custom_input_csv_transform)
42
45
  end
43
46
  end
@@ -5,11 +5,11 @@ module Eco::API::UseCases::GraphQL::Samples
5
5
  # class Custom::UseCase::TagtreeDiff < Eco::API::UseCases::GraphQL::Samples::Location
6
6
  # name 'tagtree-diff'
7
7
  # type :other
8
-
8
+ #
9
9
  # require_relative 'cli/10_tagtree_diff_cli'
10
-
10
+ #
11
11
  # include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
12
-
12
+ #
13
13
  # IN_FILENAME = /requested_tree\.csv/.freeze
14
14
  # IN_FOLDER = 'sftp'.freeze
15
15
  # HEADER_MAPS = {
@@ -1,6 +1,6 @@
1
1
  module Eco::API::UseCases::GraphQL::Utils
2
2
  module Sftp
3
3
  include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
4
- include Eco::API::UseCases::Lib::Sftp
4
+ include Eco::API::UseCases::Lib::Files::Sftp
5
5
  end
6
6
  end
@@ -1,4 +1,4 @@
1
- module Eco::API::UseCases::Lib
1
+ module Eco::API::UseCases::Lib::Files
2
2
  module FilePattern
3
3
  class WrongConst < ArgumentError; end
4
4
 
@@ -29,6 +29,10 @@ module Eco::API::UseCases::Lib
29
29
  rescue NameError
30
30
  self.class.const_get(fpc)
31
31
  end
32
+ elsif respond_to?(:file_pattern, true)
33
+ file_pattern
34
+ elsif self.class.const_defined?(:FILE_PATTERN)
35
+ self.class::FILE_PATTERN
32
36
  end
33
37
  rescue NameError
34
38
  raise WrongConst, "(#{self.class}) Unknown constant: #{fpc}"
@@ -1,4 +1,4 @@
1
- module Eco::API::UseCases::Lib
1
+ module Eco::API::UseCases::Lib::Files
2
2
  module Sftp
3
3
  class UnspecifiedRemoteFolder < ArgumentError; end
4
4
 
@@ -18,10 +18,15 @@ module Eco::API::UseCases::Lib
18
18
  alias_method :sftp_upload, :upload
19
19
 
20
20
  def sftp_group_id
21
- if self.class.const_defined?(:SFTP_GROUP)
22
- self.class.const_get(:SFTP_GROUP)
23
- elsif (group_id = options.dig(:sftp, :group))
21
+ return super if defined?(super) && !super.nil?
22
+ return group_id if respond_to?(:group_id, true)
23
+
24
+ if (group_id = options.dig(:sftp, :group))
24
25
  group_id
26
+ elsif self.class.const_defined?(:SFTP_GROUP)
27
+ self.class.const_get(:SFTP_GROUP)
28
+ elsif self.class.const_defined?(:GROUP_ID)
29
+ self.class.const_get(:GROUP_ID)
25
30
  end
26
31
  end
27
32
 
@@ -78,7 +83,7 @@ module Eco::API::UseCases::Lib
78
83
  sftp_archive_file!(filename)
79
84
  end
80
85
 
81
- def ensure_remote_empty(subfolder: remote_subfolder, pattern: nil)
86
+ def ensure_remote_empty(subfolder: remote_subfolder, pattern: nil, timeout: 3)
82
87
  files = with_remote_files(subfolder: subfolder, pattern: pattern)
83
88
  return if files.empty?
84
89
 
@@ -92,7 +97,7 @@ module Eco::API::UseCases::Lib
92
97
  'Do you want to proceed to delete? (Y/n):',
93
98
  explanation: msg,
94
99
  default: 'Y',
95
- timeout: 3
100
+ timeout: timeout
96
101
  ) do |response|
97
102
  next unless response.upcase.start_with?('Y')
98
103
 
@@ -106,6 +111,18 @@ module Eco::API::UseCases::Lib
106
111
  end
107
112
  end
108
113
 
114
+ def local_folder
115
+ return super if defined?(super) && !super.nil?
116
+
117
+ if (local_dir = options.dig(:sftp, :local_folder))
118
+ local_dir
119
+ elsif self.class.const_defined?(:LOCAL_FOLDER)
120
+ self.class::LOCAL_FOLDER
121
+ else
122
+ '.'
123
+ end
124
+ end
125
+
109
126
  def to_remote_path(file, subfolder: remote_subfolder)
110
127
  [remote_folder(subfolder), file].join('/')
111
128
  end
@@ -113,6 +130,8 @@ module Eco::API::UseCases::Lib
113
130
  # `remote_target_folder` overrides `sftp_config.remote_folder` as well as `remote_subfolder`
114
131
  # `remote_folder` overrides `sftp_config.remote_folder` but NOT `remote_subfolder`
115
132
  def remote_folder(subfolder = remote_subfolder)
133
+ return super if defined?(super) && !super.nil?
134
+
116
135
  rm_tf = options.dig(:sftp, :remote_target_folder)
117
136
  return rm_tf if rm_tf
118
137
 
@@ -121,6 +140,8 @@ module Eco::API::UseCases::Lib
121
140
  end
122
141
 
123
142
  def remote_subfolder(required: true)
143
+ return super if defined?(super) && !super.nil?
144
+
124
145
  remote_subdir = options.dig(:sftp, :remote_subfolder)
125
146
  remote_subdir ||= self.class::REMOTE_FOLDER if self.class.const_defined?(:REMOTE_FOLDER)
126
147
  remote_subdir ||= self.class::REMOTE_SUBFOLDER if self.class.const_defined?(:REMOTE_SUBFOLDER)
@@ -132,16 +153,6 @@ module Eco::API::UseCases::Lib
132
153
  raise UnspecifiedRemoteFolder, msg
133
154
  end
134
155
 
135
- def local_folder
136
- if (local_dir = options.dig(:sftp, :local_folder))
137
- local_dir
138
- elsif self.class.const_defined?(:LOCAL_FOLDER)
139
- self.class::LOCAL_FOLDER
140
- else
141
- '.'
142
- end
143
- end
144
-
145
156
  # @param subfolder [String] the subfolder.
146
157
  def with_remote_files(subfolder: remote_subfolder, pattern: nil)
147
158
  sftp.files(remote_folder(subfolder), pattern: pattern).each do |remote_file|
@@ -0,0 +1,7 @@
1
+ module Eco::API::UseCases::Lib
2
+ module Files
3
+ end
4
+ end
5
+
6
+ require_relative 'files/sftp'
7
+ require_relative 'files/file_pattern'
@@ -8,5 +8,4 @@ module Eco
8
8
  end
9
9
 
10
10
  require_relative 'lib/error_handling'
11
- require_relative 'lib/sftp'
12
- require_relative 'lib/file_pattern'
11
+ require_relative 'lib/files'
@@ -1,13 +1,13 @@
1
1
  # Use case to export a register into a CSV
2
2
  class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::OozeSamples::RegisterExportCase
3
- name "export-register"
3
+ name 'export-register'
4
4
  type :other
5
5
  batch_size 5
6
6
 
7
7
  def main(session, options, usecase)
8
- super(session, options, usecase) do
8
+ super do
9
9
  # Save the File
10
- CSV.open(filename, "w") do |csv|
10
+ CSV.open(filename, 'w') do |csv|
11
11
  csv << exportable_register.header(refresh: true)
12
12
  exportable_register.each(as_values: true) do |values|
13
13
  csv << values
@@ -79,7 +79,7 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
79
79
  end
80
80
 
81
81
  def options_delimiter
82
- options.dig(:export, :options, :delimiter) || "|"
82
+ options.dig(:export, :options, :delimiter) || '|'
83
83
  end
84
84
 
85
85
  def include_deindexed?
@@ -94,7 +94,7 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
94
94
  @filename ||= (options[:file] || options.dig(:export, :file, :name)).tap do |filename|
95
95
  next if filename
96
96
 
97
- log(:error) { "Destination file not specified" }
97
+ log(:error) { 'Destination file not specified' }
98
98
  return false
99
99
  end
100
100
  end
@@ -5,16 +5,16 @@ module Eco
5
5
  module Helpers
6
6
  # Class to ease the export process
7
7
  class ExportableOoze
8
- MERGE_DELIMITER = "#:#".freeze
8
+ MERGE_DELIMITER = '#:#'.freeze
9
9
  META_FIELDS = {
10
- "id" => "Internal ID",
11
- "uid" => "Unique ID",
12
- "name" => "Name of Page",
13
- "state" => "State of Page",
14
- "time_zone" => "Time Zone",
15
- "created_at" => "Page Created",
16
- "updated_at" => "Last updated",
17
- "tags" => "Location Tags"
10
+ 'id' => 'Internal ID',
11
+ 'uid' => 'Unique ID',
12
+ 'name' => 'Name of Page',
13
+ 'state' => 'State of Page',
14
+ 'time_zone' => 'Time Zone',
15
+ 'created_at' => 'Page Created',
16
+ 'updated_at' => 'Last updated',
17
+ 'tags' => 'Location Tags'
18
18
  }.freeze
19
19
  DEFAULT_OPTIONS = {
20
20
  delimiter: "\n",
@@ -31,9 +31,10 @@ module Eco
31
31
  def label(field, default: nil)
32
32
  value = nil
33
33
  value ||= field.label.to_s.strip if field.respond_to?(:label)
34
- value = nil unless value && !value.empty?
34
+ value = nil unless value && !value.empty?
35
35
  return value if value || !default
36
- default || "Unnamed field:"
36
+
37
+ default || 'Unnamed field:'
37
38
  end
38
39
 
39
40
  def key_ref_label(field, default: nil)
@@ -157,6 +158,7 @@ module Eco
157
158
  return false if opts[:only_indexed] && !self.class.indexed?(field)
158
159
  return false if opts[:only_labeled] && !self.class.label?(field)
159
160
  return false if opts[:only_with_ref] && !self.class.with_ref?(field)
161
+
160
162
  true
161
163
  end
162
164
 
@@ -167,6 +169,7 @@ module Eco
167
169
  def to_value(field, delimiter: self.delimiter)
168
170
  return nil unless field.respond_to?(:to_s)
169
171
  return field.to_s unless offers_delimiter?(field.method(:to_s))
172
+
170
173
  field.to_s(delimiter: delimiter)
171
174
  end
172
175