eco-helpers 2.6.3 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +95 -0
  4. data/CHANGELOG.md +135 -2
  5. data/Rakefile +13 -7
  6. data/eco-helpers.gemspec +3 -3
  7. data/lib/eco/api/common/loaders/base.rb +2 -2
  8. data/lib/eco/api/common/loaders/case_base.rb +1 -1
  9. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +5 -5
  10. data/lib/eco/api/common/loaders/error_handler.rb +8 -5
  11. data/lib/eco/api/common/loaders/parser.rb +44 -22
  12. data/lib/eco/api/common/loaders/policy.rb +6 -4
  13. data/lib/eco/api/common/loaders/use_case.rb +13 -7
  14. data/lib/eco/api/common/people/base_parser.rb +0 -2
  15. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +0 -1
  16. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +1 -1
  17. data/lib/eco/api/common/people/default_parsers/date_parser.rb +64 -12
  18. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +0 -1
  19. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +13 -5
  20. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +0 -1
  21. data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +18 -5
  22. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +8 -8
  23. data/lib/eco/api/common/people/default_parsers/select_parser.rb +50 -26
  24. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -6
  25. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +9 -12
  26. data/lib/eco/api/common/people/default_parsers.rb +1 -12
  27. data/lib/eco/api/common/people/entries.rb +13 -13
  28. data/lib/eco/api/common/people/entry_factory.rb +76 -45
  29. data/lib/eco/api/common/people/person_attribute_parser.rb +8 -12
  30. data/lib/eco/api/common/people/person_entry.rb +86 -75
  31. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +60 -44
  32. data/lib/eco/api/common/people/person_factory.rb +30 -22
  33. data/lib/eco/api/common/people/person_modifier.rb +11 -13
  34. data/lib/eco/api/common/people/person_parser.rb +101 -39
  35. data/lib/eco/api/common/people/supervisor_helpers.rb +25 -26
  36. data/lib/eco/api/common/session/base_session.rb +9 -9
  37. data/lib/eco/api/common/session/environment.rb +7 -5
  38. data/lib/eco/api/common/session/sftp.rb +59 -32
  39. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +10 -6
  40. data/lib/eco/api/common/version_patches/exception.rb +11 -13
  41. data/lib/eco/api/error.rb +32 -20
  42. data/lib/eco/api/microcases/set_supervisor.rb +0 -3
  43. data/lib/eco/api/organization/node_classifications.rb +82 -0
  44. data/lib/eco/api/organization/policy_groups.rb +4 -6
  45. data/lib/eco/api/organization/tag_tree.rb +169 -93
  46. data/lib/eco/api/organization.rb +1 -0
  47. data/lib/eco/api/session/batch/job.rb +1 -1
  48. data/lib/eco/api/session/config/tagtree.rb +41 -23
  49. data/lib/eco/api/session/config/workflow.rb +113 -88
  50. data/lib/eco/api/session/config.rb +6 -0
  51. data/lib/eco/api/session.rb +51 -29
  52. data/lib/eco/api/usecases/base_io.rb +28 -25
  53. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
  54. data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
  55. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
  56. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
  57. data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
  58. data/lib/eco/api/usecases/default/locations.rb +1 -0
  59. data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
  60. data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
  61. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
  62. data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
  63. data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
  64. data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
  65. data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
  66. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
  67. data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
  68. data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
  69. data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
  70. data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
  71. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
  72. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -2
  73. data/lib/eco/api/usecases/graphql/base.rb +5 -3
  74. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
  75. data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
  76. data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
  77. data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
  78. data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
  79. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
  80. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
  81. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
  82. data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
  83. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
  84. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
  85. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
  86. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
  87. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
  88. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
  89. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
  90. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
  91. data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
  92. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
  93. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
  94. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
  95. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
  96. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
  97. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
  98. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
  99. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
  100. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
  101. data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
  102. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
  103. data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
  104. data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
  105. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
  106. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
  107. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
  108. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
  109. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
  110. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
  111. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
  112. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
  113. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
  114. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
  115. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
  116. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
  117. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
  118. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
  119. data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
  120. data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
  121. data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
  122. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
  123. data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
  124. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
  125. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
  126. data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
  127. data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
  128. data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
  129. data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
  130. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
  131. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
  132. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +34 -34
  133. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
  134. data/lib/eco/api/usecases.rb +0 -1
  135. data/lib/eco/cli/config/use_cases.rb +31 -29
  136. data/lib/eco/cli_default/input_filters.rb +0 -5
  137. data/lib/eco/cli_default/people_filters.rb +4 -4
  138. data/lib/eco/cli_default/workflow.rb +13 -14
  139. data/lib/eco/csv/table.rb +34 -25
  140. data/lib/eco/data/hashes/array_diff.rb +24 -35
  141. data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
  142. data/lib/eco/data/hashes/diff_result.rb +65 -57
  143. data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
  144. data/lib/eco/data/hashes.rb +1 -1
  145. data/lib/eco/data/locations/convert.rb +1 -1
  146. data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
  147. data/lib/eco/data/locations/node_base/parsing.rb +4 -2
  148. data/lib/eco/data/locations/node_base/treeify.rb +149 -132
  149. data/lib/eco/data/locations/node_base.rb +15 -4
  150. data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
  151. data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
  152. data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
  153. data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
  154. data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
  155. data/lib/eco/data/locations/node_diff.rb +45 -17
  156. data/lib/eco/data/locations/node_level/parsing.rb +15 -21
  157. data/lib/eco/data/locations/node_level.rb +66 -22
  158. data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
  159. data/lib/eco/data/locations/node_plain.rb +60 -7
  160. data/lib/eco/data/strings/camel_case.rb +35 -0
  161. data/lib/eco/data/strings/snake_case.rb +18 -0
  162. data/lib/eco/data/strings.rb +8 -0
  163. data/lib/eco/data.rb +1 -0
  164. data/lib/eco/language/methods/call_detector.rb +11 -0
  165. data/lib/eco/language/methods/dsl_able.rb +7 -1
  166. data/lib/eco/language/methods.rb +2 -1
  167. data/lib/eco/language/models/collection.rb +23 -25
  168. data/lib/eco/language/models/parser_serializer.rb +24 -5
  169. data/lib/eco/version.rb +1 -1
  170. data/lib/eco-helpers.rb +0 -1
  171. metadata +54 -9
  172. data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -29,7 +29,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
29
29
 
30
30
  super(session, options, usecase) do
31
31
  if mode == :legacy
32
- with_each_entry do |ooze|
32
+ with_each_entry do
33
33
  process_ooze(&block)
34
34
  end
35
35
  elsif mode == :delegate
@@ -41,21 +41,20 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
41
41
  log_kpis
42
42
  end
43
43
 
44
- def process_ooze(ooze = target)
44
+ def process_ooze(_ooze = target)
45
45
  raise "You need to define this method"
46
46
  end
47
47
 
48
48
  private
49
49
 
50
50
  def before_loading_new_target(ooze_id)
51
- if pending = queue_shift(ooze_id)
52
- update_ooze(pending).tap do |result|
53
- if result.is_a?(Ecoportal::API::Common::Response)
54
- if result.success?
55
- @updated_oozes += 1
56
- else
57
- @failed_update_oozes +=1
58
- end
51
+ return unless (pending = queue_shift(ooze_id))
52
+ update_ooze(pending).tap do |result|
53
+ if result.is_a?(Ecoportal::API::Common::Response)
54
+ if result.success?
55
+ @updated_oozes += 1
56
+ else
57
+ @failed_update_oozes +=1
59
58
  end
60
59
  end
61
60
  end
@@ -78,15 +77,13 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
78
77
  ooze_result_ids[page_result.id] = true
79
78
  end
80
79
 
81
- if pending = queue_shift(page_result.id)
82
- if dirty?(pending)
83
- msg = "Inconsistent search results. "
84
- msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
85
- logger.warn msg
86
- update_ooze(pending)
87
- end
80
+ if (pending = queue_shift(page_result.id)) && dirty?(pending)
81
+ msg = "Inconsistent search results. "
82
+ msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
83
+ logger.warn msg
84
+ update_ooze(pending)
88
85
  end
89
- if ooz = ooze(page_result.id)
86
+ if (ooz = ooze(page_result.id))
90
87
  @retrieved_oozes += 1
91
88
  yield(ooz)
92
89
  else
@@ -99,11 +96,11 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
99
96
  end
100
97
 
101
98
  def enqueue(object)
102
- return unless object && object.respond_to?(:id)
99
+ return unless object.respond_to?(:id)
103
100
  unless object.is_a?(Ecoportal::API::V2::Page) or object.is_a?(Ecoportal::API::V2::Pages::PageStage)
104
101
  raise "Queuing is just for entries. Expecting Page or PageStage. Given: #{object.class}"
105
102
  end
106
- if elem = queue_get(object.id)
103
+ if (elem = queue_get(object.id))
107
104
  msg = "Something is wrong. Native case 'RegisterUpdateCase' is "
108
105
  if (elem != object) && dirty?(elem)
109
106
  msg << "trying to queue different objects with same page id:\n"
@@ -154,7 +151,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
154
151
  dry_run_feedback(draft)
155
152
  false
156
153
  else
157
- apiv2.pages.create(draft, from: template_id).tap do |result|
154
+ apiv2.pages.create(draft, from: template_id).tap do
158
155
  @created_oozes += 1
159
156
  end
160
157
  end
@@ -182,28 +179,31 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
182
179
  end
183
180
 
184
181
  def backup_patch!(ooze = target)
185
- unless patch = (patch_doc(ooze) || {})["page"]
186
- logger.info "No changes to update for #{object_reference(ooze)}."
187
- return
188
- end
182
+ return if (patch_doc(ooze) || {})["page"]
183
+ logger.info "No changes to update for #{object_reference(ooze)}."
189
184
  end
190
185
 
191
186
  def results_preview
192
187
  apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
193
188
  @total_search_oozes = search_results.total
194
189
  str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
195
- default_answer = if session.config.run_mode_remote? then "Y" else "N" end
196
- session.prompt_user("Do you want to proceed (y/N):", explanation: str_results, default: default_answer, timeout: 10) do |res|
197
- unless res.upcase.start_with?("Y")
198
- puts "..."
199
- logger.info "Aborting script..."
200
- exit(0)
201
- end
190
+ default_answer = session.config.run_mode_remote?? "Y" : "N"
191
+ session.prompt_user(
192
+ "Do you want to proceed (y/N):",
193
+ explanation: str_results,
194
+ default: default_answer,
195
+ timeout: 10
196
+ ) do |res|
197
+ next if res.upcase.start_with?("Y")
198
+ puts "..."
199
+ logger.info "Aborting script..."
200
+ exit(0)
202
201
  end
203
202
  end
204
203
  end
205
204
 
206
205
  def init_kpis
206
+ @total_search_oozes = 0
207
207
  @retrieved_oozes = 0
208
208
  @non_retrieved_oozes = 0
209
209
  @dupped_search_oozes = 0
@@ -242,12 +242,12 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
242
242
  end
243
243
 
244
244
  def conf_filters
245
- return filters if self.respond_to?(:filters)
245
+ return filters if respond_to?(:filters)
246
246
  []
247
247
  end
248
248
 
249
249
  def conf_search
250
- return search if self.respond_to?(:search)
250
+ return search if respond_to?(:search)
251
251
  end
252
252
 
253
253
  def register_id
@@ -10,15 +10,13 @@ class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCase
10
10
  def with_each_entry
11
11
  batched_target_ids do |ids|
12
12
  ids.each do |id|
13
- if pending = queue_shift(id)
14
- if dirty?(pending)
15
- msg = "Same entry 'id' appears more than once. "
16
- msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
17
- console.warn msg
18
- update_ooze(pending)
19
- end
13
+ if (pending = queue_shift(id)) && dirty?(pending)
14
+ msg = "Same entry 'id' appears more than once. "
15
+ msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
16
+ console.warn msg
17
+ update_ooze(pending)
20
18
  end
21
- if ooz = ooze(id)
19
+ if (ooz = ooze(id))
22
20
  @retrieved_oozes += 1
23
21
  yield(ooz)
24
22
  else
@@ -49,7 +47,7 @@ class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCase
49
47
  @total_search_oozes = target_ids.count
50
48
  @dupped_search_oozes = dups.count
51
49
 
52
- dups_str = dups.count > 0 ? "There are #{dups.count} duplicated ids" : "No duplicates detected"
50
+ dups_str = dups.count.positive? ? "There are #{dups.count} duplicated ids" : "No duplicates detected"
53
51
  msg = "Total target entries: #{target_ids.count} (#{dups_str})"
54
52
 
55
53
  session.prompt_user("Do you want to proceed (y/N):", explanation: msg, default: "N", timeout: 10) do |res|
@@ -62,7 +60,7 @@ class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCase
62
60
  end
63
61
 
64
62
  def target_ids
65
- @target_ids ||= input_csv.columns.first[1..-1]
63
+ @target_ids ||= input_csv.columns.first[1..]
66
64
  end
67
65
 
68
66
  def input_csv
@@ -2,7 +2,6 @@ module Eco
2
2
  module API
3
3
  # Autoloading children is done on init and each time usecases it's queried
4
4
  class UseCases
5
-
6
5
  class UnknownCase < StandardError
7
6
  def initialize(msg = nil, case_name: nil, type: nil)
8
7
  msg ||= "Unknown case"
@@ -5,7 +5,7 @@ module Eco
5
5
  include Eco::CLI::Config::Help
6
6
  attr_reader :core_config
7
7
 
8
- class CaseConfig < Struct.new(:cases_config, :option, :type, :description, :casename, :callback)
8
+ CaseConfig = Struct.new(:cases_config, :option, :type, :description, :casename, :callback) do
9
9
  def add_option(arg, desc = nil, &block)
10
10
  core_config.options_set.add(arg, desc, namespace: option, &block)
11
11
  self
@@ -18,8 +18,7 @@ module Eco
18
18
  end
19
19
  end
20
20
 
21
- class ActiveCase < Struct.new(:index, :option, :callback)
22
- end
21
+ ActiveCase = Struct.new(:index, :option, :callback)
23
22
 
24
23
  def initialize(core_config:)
25
24
  @core_config = core_config
@@ -29,7 +28,7 @@ module Eco
29
28
  # @return [String] summary of the use cases.
30
29
  def help(refine: nil)
31
30
  refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
32
- ["The following are the available use cases#{refinement}:"].yield_self do |lines|
31
+ ["The following are the available use cases#{refinement}:"].then do |lines|
33
32
  max_len = keys_max_len(@linked_cases.keys)
34
33
  @linked_cases.keys.sort.select do |key|
35
34
  !refine.is_a?(String) || key.include?(refine)
@@ -60,7 +59,7 @@ module Eco
60
59
  def cli_apply(io:)
61
60
  io.session.usecases.each do |usecase|
62
61
  next unless usecase.respond_to?(:classed_definition)
63
- next unless original_case = usecase.classed_definition
62
+ next unless (original_case = usecase.classed_definition)
64
63
  original_case.cli_apply!
65
64
  end
66
65
  end
@@ -72,14 +71,15 @@ module Eco
72
71
  # @return [Hash] where keys are cases and values a `Hash` with `option` String and `callback`
73
72
  def active(io:)
74
73
  validate_io!(io)
75
- return @active_cases unless !@active_cases
74
+ return @active_cases if @active_cases
75
+
76
76
  @active_cases = @linked_cases.each_with_object({}) do |(option_case, data), active_cases|
77
- next nil unless SCR.get_arg(option_case)
78
- if usecase = get_usecase(io: io, data: data)
79
- index = SCR.get_arg_index(option_case)
80
- active_cases[usecase] = ActiveCase.new(index, option_case, data.callback)
81
- end
82
- end.sort_by {|c, d| d.index}.to_h
77
+ next unless SCR.get_arg(option_case)
78
+ next unless (usecase = get_usecase(io: io, data: data))
79
+
80
+ index = SCR.get_arg_index(option_case)
81
+ active_cases[usecase] = ActiveCase.new(index, option_case, data.callback)
82
+ end.sort_by {|_c, d| d.index}.to_h
83
83
  end
84
84
 
85
85
  def process(io:)
@@ -111,28 +111,30 @@ module Eco
111
111
  end
112
112
 
113
113
  def get_usecase(io:, data:)
114
- usecase = if case_name = data.casename
115
- io.session.usecases.case(case_name, type: data.type)
116
- end
117
- usecase ||= if callback = data.callback
118
- # identify/retrieve usecase via callback
119
- params = io.params(keyed: true).merge(type: data.type)
120
- io = io.new(**params, validate: false)
121
- callback.call(*io.params).tap do |usecase|
122
- unless usecase.is_a?(Eco::API::UseCases::UseCase)
123
- msg = "When adding a usecase, without specifying 'case_name:', "
124
- msg += "the block that integrates usecase for cli option '#{data.option}'"
125
- msg += " must return an Eco::API::UseCases::UseCase object. It returns #{usecase.class}"
126
- raise msg
114
+ usecase =
115
+ if (case_name = data.casename)
116
+ io.session.usecases.case(case_name, type: data.type)
117
+ end
118
+
119
+ usecase ||
120
+ if (callback = data.callback)
121
+ # identify/retrieve usecase via callback
122
+ params = io.params(keyed: true).merge(type: data.type)
123
+ io = io.new(**params, validate: false)
124
+ callback.call(*io.params).tap do |use|
125
+ unless use.is_a?(Eco::API::UseCases::UseCase)
126
+ msg = "When adding a usecase, without specifying 'case_name:', "
127
+ msg += "the block that integrates usecase for cli option '#{data.option}'"
128
+ msg += " must return an Eco::API::UseCases::UseCase object. It returns #{use.class}"
129
+ raise msg
130
+ end
127
131
  end
128
132
  end
129
- end
130
133
  end
131
134
 
132
135
  def validate_io!(io)
133
- unless io && io.is_a?(Eco::API::UseCases::BaseIO)
134
- raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
135
- end
136
+ return if io.is_a?(Eco::API::UseCases::BaseIO)
137
+ raise ArgumentError, "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
136
138
  end
137
139
  end
138
140
  end
@@ -40,11 +40,6 @@ ASSETS.cli.config do |cnf|
40
40
  end
41
41
  end
42
42
 
43
- #filters.add("-input-supervisors") do |people, session, options|
44
- # options.deep_merge!(input: {filter: {subordinates: true}})
45
- # people.newFrom people.to_a.select {|person| person.subordinates > 0}
46
- #end
47
-
48
43
  filters.add("-input-supervisor-id", "only those with certain supervisor id or external_id") do |input, session, options|
49
44
  id = SCR.get_arg("-input-supervisor-id", with_param: true)
50
45
  options.deep_merge!(input: {filter: {supervisor_id: id}})
@@ -21,10 +21,10 @@ ASSETS.cli.config do |cnf|
21
21
  people.external_id_present(false)
22
22
  end
23
23
 
24
- filters.add("-supervisors", "only those that have subordinates") do |people, session, options|
25
- options.deep_merge!(people: {filter: {subordinates: true}})
26
- people.newFrom people.to_a.select {|person| person.subordinates > 0}
27
- end
24
+ # filters.add("-supervisors", "only those that have subordinates") do |people, session, options|
25
+ # options.deep_merge!(people: {filter: {subordinates: true}})
26
+ # people.newFrom people.to_a.select {|person| person.subordinates > 0}
27
+ # end
28
28
 
29
29
  filters.add("-supervisor-id", "only those with certain supervisor") do |people, session, options|
30
30
  id = SCR.get_arg("-supervisor-id", with_param: true)
@@ -1,6 +1,5 @@
1
- ASSETS.cli do |cli|
2
- ASSETS.config.workflow do |wf|
3
-
1
+ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
2
+ ASSETS.config.workflow do |wf| # rubocop:disable Metrics/BlockLength
4
3
  rescued = false
5
4
  # default rescue
6
5
  wf.rescue do |err, io|
@@ -20,7 +19,7 @@ ASSETS.cli do |cli|
20
19
  wf.for(:load) do |wf_load|
21
20
  wf_load.for(:input) do |wf_in|
22
21
  wf_in.on(:get) do |_wf_ig, io|
23
- cases_with_input = cli.config.usecases.active(io: io).select do |usecase, data|
22
+ cases_with_input = cli.config.usecases.active(io: io).select do |usecase, _data|
24
23
  io.class.input_required?(usecase.type)
25
24
  end
26
25
 
@@ -38,13 +37,13 @@ ASSETS.cli do |cli|
38
37
 
39
38
  wf_in.on(:filter) do |_wf_if, io|
40
39
  next unless input && !input.empty?
41
- io.new(input: cli.config.input_filters.process(io: io))
40
+ io.new(input: cli.config.input_filters.process(io: io))
42
41
  end
43
42
  end
44
43
 
45
44
  wf_load.for(:people) do |wf_peo|
46
45
  wf_peo.on(:get) do |_wf_pg, io|
47
- cases_with_people = cli.config.usecases.active(io: io).select do |usecase, data|
46
+ cases_with_people = cli.config.usecases.active(io: io).select do |usecase, _data|
48
47
  io.class.people_required?(usecase.type)
49
48
  end
50
49
  next if cases_with_people.empty? && !options.dig(:people, :get)
@@ -61,7 +60,7 @@ ASSETS.cli do |cli|
61
60
  wf.before(:usecases) do |_wf_ca, io|
62
61
  # save partial entries -> should be native to session.workflow
63
62
  get_people = options.dig(:people, :get)
64
- partial_update = get_people && get_people.dig(:type) == :partial
63
+ partial_update = get_people && get_people[:type] == :partial
65
64
  if !options[:dry_run] && partial_update
66
65
  partial_file = session.config.people.partial_cache
67
66
  session.file_manager.save_json(io.people, partial_file, :timestamp)
@@ -86,7 +85,7 @@ ASSETS.cli do |cli|
86
85
  wf.before(:post_launch) do |wf_post, io|
87
86
  next wf_post.skip! if session.post_launch.empty?
88
87
 
89
- run_it = !options[:dry_run] || options.dig(:post_launch, :run)
88
+ run_it = !options[:dry_run] || options.dig(:post_launch, :run)
90
89
  unless run_it
91
90
  wf_post.skip!
92
91
  log(:info) {
@@ -98,7 +97,7 @@ ASSETS.cli do |cli|
98
97
  end
99
98
 
100
99
  get_people = options.dig(:people, :get)
101
- partial_update = get_people && get_people.dig(:type) == :partial
100
+ partial_update = get_people && get_people[:type] == :partial
102
101
  refresh_data = !options[:dry_run] && partial_update
103
102
 
104
103
  unless refresh_data
@@ -131,13 +130,13 @@ ASSETS.cli do |cli|
131
130
  end
132
131
  end
133
132
 
134
- wf_post.on(:launch_jobs) do |_wf_pl, io|
133
+ wf_post.on(:launch_jobs) do |_wf_pl, _io|
135
134
  session.jobs_launch(simulate: options[:dry_run])
136
135
  end
137
136
  end
138
137
 
139
138
  wf.on(:report) do |_wf_rep, io|
140
- if file = options.dig(:report, :people, :csv)
139
+ if (file = options.dig(:report, :people, :csv))
141
140
  options.deep_merge!(export: {
142
141
  options: {internal_names: true, nice_header: true, split_schemas: true},
143
142
  file: {name: file, format: :csv}
@@ -149,11 +148,11 @@ ASSETS.cli do |cli|
149
148
 
150
149
  wf.on(:end) do |_wf_end, io|
151
150
  get_people = options.dig(:people, :get)
152
- partial_update = get_people && get_people.dig(:type) == :partial
151
+ partial_update = get_people && get_people[:type] == :partial
153
152
 
154
153
  unless !options[:end_get] || options[:dry_run] || partial_update
155
- people_update_cases = cli.config.usecases.active(io: io).any? do |usecase, data|
156
- [:transform, :sync].any? { |type| usecase.type == type }
154
+ people_update_cases = cli.config.usecases.active(io: io).any? do |usecase, _data|
155
+ %i[transform sync].any? { |type| usecase.type == type }
157
156
  end
158
157
 
159
158
  if !people_update_cases
data/lib/eco/csv/table.rb CHANGED
@@ -5,7 +5,7 @@ module Eco
5
5
  # - when `Array<Array>` => all `rows` as arrays where first array is the **header**
6
6
  def initialize(input)
7
7
  super(to_rows_array(input))
8
- self.delete_if do |row|
8
+ delete_if do |row|
9
9
  values = row.fields
10
10
  values.all?(&:nil?) || values.map(&:to_s).all?(&:empty?)
11
11
  end
@@ -15,7 +15,7 @@ module Eco
15
15
  # @note assumes there are no repeated header names
16
16
  # @return [Eco::CSV::Table]
17
17
  def nil_blank_cells!
18
- self.each do |row|
18
+ each do |row|
19
19
  row.dup.each do |header, value|
20
20
  value = value.to_s.strip
21
21
  row[header] = value.empty?? nil : value
@@ -40,8 +40,7 @@ module Eco
40
40
  # It allows to rename the header names
41
41
  # @return [Eco::CSV::Table]
42
42
  def transform_headers
43
- header = self.headers
44
- cols = self.columns
43
+ cols = columns
45
44
  cols.each do |col|
46
45
  col[0] = yield(col.first)
47
46
  end
@@ -52,8 +51,8 @@ module Eco
52
51
  # @note it also offers a way to resolve merge conflicts
53
52
  # @return [Eco::CSV::Table]
54
53
  def merge_same_header_names
55
- dups = self.duplicated_header_names
56
- out_rows = self.map do |row|
54
+ dups = duplicated_header_names
55
+ out_rows = map do |row|
57
56
  row.to_a.each_with_object({}) do |(name, value), out|
58
57
  if dups.include?(name) && out.key?(name)
59
58
  if block_given?
@@ -76,7 +75,7 @@ module Eco
76
75
 
77
76
  # @return [Array<String>] list of duplicated header names
78
77
  def duplicated_header_names
79
- header = self.headers
78
+ header = headers
80
79
  header.select {|e| header.count(e) > 1}.uniq
81
80
  end
82
81
 
@@ -113,7 +112,7 @@ module Eco
113
112
  when String
114
113
  csv_cols = columns
115
114
  csv_cols = index.each_with_object([]) do |name, cols|
116
- col = csv_cols.find {|col| col.first == name}
115
+ col = csv_cols.find {|cl| cl.first == name}
117
116
  cols << col if col
118
117
  end
119
118
  columns_to_table(csv_cols)
@@ -157,14 +156,14 @@ module Eco
157
156
  # @return [Array<::CSV::Row>]
158
157
  def rows
159
158
  [].tap do |out|
160
- self.each {|row| out << row}
159
+ each {|row| out << row}
161
160
  end
162
161
  end
163
162
 
164
163
  # It removes all rows where all columns' values are the same
165
164
  def delete_duplicates!
166
165
  unique_rows = []
167
- self.by_row!.delete_if do |row|
166
+ by_row!.delete_if do |row|
168
167
  unique_rows.any? {|done| equal_rows?(row, done)}.tap do |found|
169
168
  unique_rows << row unless found
170
169
  end
@@ -174,9 +173,9 @@ module Eco
174
173
  # @param row1 [CSV:Row] row to be compared
175
174
  # @param row2 [CSV:Row] row to be compared
176
175
  # @param [Boolean] `true` if all values of `row1` are as of `row2`
177
- def equal_rows?(row1, row2)
178
- row1.fields.zip(row2.fields).all? do |(v1, v2)|
179
- v1 == v2
176
+ def equal_rows?(row_1, row_2)
177
+ row_1.fields.zip(row_2.fields).all? do |(v_1, v_2)|
178
+ v_1 == v_2
180
179
  end
181
180
  end
182
181
 
@@ -198,9 +197,9 @@ module Eco
198
197
  # @note it will override columns with same header name
199
198
  # @return [Hash] keys are headers, values are arrays
200
199
  def columns_hash
201
- columns.map do |col|
202
- [col.first, col[1..-1]]
203
- end.to_h
200
+ columns.to_h do |col|
201
+ [col.first, col[1..]]
202
+ end
204
203
  end
205
204
 
206
205
  # Returns an array of row hashes
@@ -218,29 +217,29 @@ module Eco
218
217
 
219
218
  def columns_to_table(columns_array)
220
219
  rows_data = columns_array.transpose
221
- return self.class.new(rows_data) if rows_data.length > 0
222
- raise ArgumentError.new("Expecting 'columns_array' to at least have header. Given: #{columns_array}")
220
+ return self.class.new(rows_data) if rows_data.length.positive?
221
+ raise ArgumentError, "Expecting 'columns_array' to at least have header. Given: #{columns_array}"
223
222
  end
224
223
 
225
- def to_rows_array(data)
224
+ def to_rows_array(data) # rubocop:disable Metrics/AbcSize
226
225
  case data
227
226
  when ::CSV::Table
228
227
  to_rows_array(data.to_a)
229
228
  when Hash
230
229
  # hash of columns header as key and column array as value
231
- rows_arrays = [a.keys].concat(a.values.first.zip(*a.values[1..-1]))
230
+ # rows_arrays = [a.keys].concat(a.values.first.zip(*a.values[1..]))
232
231
  to_rows_array(data.keys)
233
232
  when Enumerable
234
233
  data = data.dup.compact
235
- return data unless data.count > 0
234
+ return data unless data.count.positive?
236
235
  sample = data.first
237
236
 
238
237
  case sample
239
238
  when ::CSV::Row
240
239
  data
241
240
  when Array
242
- headers = data.shift
243
- data.push(Array.new(headers.length)) if data.count == 0
241
+ headers = data.shift
242
+ data.push(Array.new(headers.length)) if data.count.zero?
244
243
  data.map do |arr_row|
245
244
  ::CSV::Row.new(headers, arr_row)
246
245
  end.compact
@@ -248,15 +247,25 @@ module Eco
248
247
  headers = sample.keys
249
248
  headers_str = headers.map(&:to_s)
250
249
  data.map do |hash|
251
- ::CSV::Row.new(headers_str, hash.values_at(*headers))
250
+ values = hash.values_at(*headers).map do |value|
251
+ if_array_to_pipe_string(value)
252
+ end
253
+ ::CSV::Row.new(headers_str, values)
252
254
  end.compact
253
255
  else
254
- raise "Expected data that can be transformed into Array<::CSV::Row>. Given 'Enumerable' of '#{sample.class}'"
256
+ msg = "Expected data that can be transformed into Array<::CSV::Row>. "
257
+ msg << "Given 'Enumerable' of '#{sample.class}'"
258
+ raise msg
255
259
  end
256
260
  else
257
261
  raise "Input type not supported. Given: #{data.class}"
258
262
  end
259
263
  end
264
+
265
+ def if_array_to_pipe_string(value)
266
+ return value unless value.is_a?(Array)
267
+ value.join('|')
268
+ end
260
269
  end
261
270
  end
262
271
  end