eco-helpers 2.6.4 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +95 -0
  4. data/CHANGELOG.md +128 -2
  5. data/Rakefile +13 -7
  6. data/eco-helpers.gemspec +2 -2
  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/exception.rb +11 -13
  40. data/lib/eco/api/error.rb +32 -20
  41. data/lib/eco/api/organization/node_classifications.rb +82 -0
  42. data/lib/eco/api/organization/policy_groups.rb +4 -6
  43. data/lib/eco/api/organization/tag_tree.rb +169 -93
  44. data/lib/eco/api/organization.rb +1 -0
  45. data/lib/eco/api/session/batch/job.rb +1 -1
  46. data/lib/eco/api/session/config/tagtree.rb +41 -23
  47. data/lib/eco/api/session/config/workflow.rb +113 -88
  48. data/lib/eco/api/session/config.rb +6 -0
  49. data/lib/eco/api/session.rb +51 -29
  50. data/lib/eco/api/usecases/base_io.rb +28 -25
  51. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
  52. data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
  53. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
  54. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
  55. data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
  56. data/lib/eco/api/usecases/default/locations.rb +1 -0
  57. data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
  58. data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
  59. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
  60. data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
  61. data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
  62. data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
  63. data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
  64. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
  65. data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
  66. data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
  67. data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
  68. data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
  69. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
  70. data/lib/eco/api/usecases/graphql/base.rb +5 -3
  71. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
  72. data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
  73. data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
  74. data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
  75. data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
  76. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
  77. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
  78. data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
  79. data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
  80. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
  81. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
  82. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
  83. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
  84. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
  85. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
  86. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
  87. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
  88. data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
  89. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
  90. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
  91. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
  92. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
  93. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
  94. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
  95. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
  96. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
  97. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
  98. data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
  99. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
  100. data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
  101. data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
  102. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
  103. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
  104. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
  105. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
  106. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
  107. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
  108. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
  109. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
  110. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
  111. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
  112. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
  113. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
  114. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
  115. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
  116. data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
  117. data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
  118. data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
  119. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
  120. data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
  121. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
  122. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
  123. data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
  124. data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
  125. data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
  126. data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
  127. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
  128. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
  129. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +33 -34
  130. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
  131. data/lib/eco/api/usecases.rb +0 -1
  132. data/lib/eco/cli/config/use_cases.rb +31 -29
  133. data/lib/eco/cli_default/workflow.rb +13 -14
  134. data/lib/eco/csv/table.rb +34 -25
  135. data/lib/eco/data/hashes/array_diff.rb +24 -35
  136. data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
  137. data/lib/eco/data/hashes/diff_result.rb +65 -57
  138. data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
  139. data/lib/eco/data/hashes.rb +1 -1
  140. data/lib/eco/data/locations/convert.rb +1 -1
  141. data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
  142. data/lib/eco/data/locations/node_base/parsing.rb +4 -2
  143. data/lib/eco/data/locations/node_base/treeify.rb +149 -132
  144. data/lib/eco/data/locations/node_base.rb +15 -4
  145. data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
  146. data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
  147. data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
  148. data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
  149. data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
  150. data/lib/eco/data/locations/node_diff.rb +45 -17
  151. data/lib/eco/data/locations/node_level/parsing.rb +15 -21
  152. data/lib/eco/data/locations/node_level.rb +66 -22
  153. data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
  154. data/lib/eco/data/locations/node_plain.rb +60 -7
  155. data/lib/eco/data/strings/camel_case.rb +35 -0
  156. data/lib/eco/data/strings/snake_case.rb +18 -0
  157. data/lib/eco/data/strings.rb +8 -0
  158. data/lib/eco/data.rb +1 -0
  159. data/lib/eco/language/methods/call_detector.rb +11 -0
  160. data/lib/eco/language/methods/dsl_able.rb +7 -1
  161. data/lib/eco/language/methods.rb +2 -1
  162. data/lib/eco/language/models/collection.rb +23 -25
  163. data/lib/eco/language/models/parser_serializer.rb +24 -5
  164. data/lib/eco/version.rb +1 -1
  165. data/lib/eco-helpers.rb +0 -1
  166. metadata +52 -7
  167. data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -1,22 +1,23 @@
1
+ # rubocop:disable Lint/SymbolConversion, Style/QuotedSymbols
1
2
  module Eco
2
3
  module API
3
4
  class UseCases
4
5
  class OozeSamples
5
6
  module Helpers
6
7
  module Filters
7
- FILTER_TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
8
+ FILTER_TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ'.freeze
8
9
 
9
10
  def tags_filter(tags, any: true, negate: false)
10
11
  tags = [tags].flatten.compact
11
12
  return nil if tags.empty?
12
13
  key, name = field_key_name(:tags)
13
14
  {
14
- "tags": tags,
15
- "mode": any ? "any" : "all",
15
+ "tags": tags,
16
+ "mode": any ? "any" : "all",
16
17
  "negate": negate,
17
- "key": key,
18
- "name": name,
19
- "type": "tag_filter"
18
+ "key": key,
19
+ "name": name,
20
+ "type": "tag_filter"
20
21
  }
21
22
  end
22
23
 
@@ -24,12 +25,12 @@ module Eco
24
25
  return nil unless from || to
25
26
  key, name = field_key_name(key)
26
27
  {
27
- "relstart": "today",
28
+ "relstart": "today",
28
29
  "time_zone": "Pacific/Auckland",
29
- "relative": false,
30
- "key": key,
31
- "name": name,
32
- "type": "date_filter"
30
+ "relative": false,
31
+ "key": key,
32
+ "name": name,
33
+ "type": "date_filter"
33
34
  }.tap do |out|
34
35
  out.merge!("lbound": to_date_filter(from)) if from
35
36
  out.merge!("ubound": to_date_filter(to)) if to
@@ -40,15 +41,41 @@ module Eco
40
41
  daystart(date).utc.strftime(FILTER_TIME_FORMAT)
41
42
  end
42
43
 
43
- def set_time(date, h, m, s); Time.new(date.year, date.month, date.day, h, m, s); end
44
- def weeks(num); num * days(7); end
45
- def days(num); num * 60 * 60 * 24; end
46
- def today; Date.today.to_time; end
47
- def sunday(date); date + days(7 - weekday(date)); end
48
- def midnight(date); set_time(date, 23, 59, 59); end
49
- def daystart(date); set_time(date, 0, 0, 0); end
50
- def previous_sunday(date); midnight(sunday(date - weeks(1))); end
51
- def this_monday(date); set_time(previous_sunday(as_at_date) + days(1), 0, 0, 0); end
44
+ def set_time(date, h, m, s) # rubocop:disable Naming/MethodParameterName
45
+ Time.new(date.year, date.month, date.day, h, m, s)
46
+ end
47
+
48
+ def weeks(num)
49
+ num * days(7)
50
+ end
51
+
52
+ def days(num)
53
+ num * 60 * 60 * 24
54
+ end
55
+
56
+ def today
57
+ Date.today.to_time
58
+ end
59
+
60
+ def sunday(date)
61
+ date + days(7 - weekday(date))
62
+ end
63
+
64
+ def midnight(date)
65
+ set_time(date, 23, 59, 59)
66
+ end
67
+
68
+ def daystart(date)
69
+ set_time(date, 0, 0, 0)
70
+ end
71
+
72
+ def previous_sunday(date)
73
+ midnight(sunday(date - weeks(1)))
74
+ end
75
+
76
+ def this_monday(date)
77
+ set_time(previous_sunday(date) + days(1), 0, 0, 0)
78
+ end
52
79
 
53
80
  def field_key_name(value)
54
81
  case value
@@ -61,7 +88,7 @@ module Eco
61
88
  when :tags
62
89
  ["tags", "Location Tags"]
63
90
  else
64
- [nil , nil]
91
+ [nil, nil]
65
92
  end
66
93
  end
67
94
  end
@@ -70,3 +97,5 @@ module Eco
70
97
  end
71
98
  end
72
99
  end
100
+
101
+ # rubocop:enable Lint/SymbolConversion, Style/QuotedSymbols
@@ -1,9 +1,11 @@
1
+ # rubocop:disable Lint/DuplicateBranch
1
2
  module Eco
2
3
  module API
3
4
  class UseCases
4
5
  class OozeSamples
5
6
  module Helpers
6
7
  module OozeHandlers
8
+ # Helper to merge values of fields of same type and label name
7
9
  def merge_values(origin, append, klass: nil, delimiter: "\n")
8
10
  return origin if !append || append.to_s.strip.empty?
9
11
  return append if !origin || origin.to_s.strip.empty?
@@ -41,12 +43,17 @@ module Eco
41
43
  end
42
44
  end
43
45
 
44
- def merge_arrays(ref, plus)
46
+ # Merges arrays `ref` and `plus` by keeping the order of `ref`
47
+ # but inserting additional elements of `plus` in the correct position
48
+ # (i.e. when those elements are between two elements that exist in `ref`)
49
+ # @note this can be used to combine two different header sequences
50
+ # by using `ref` as a reference.
51
+ def merge_arrays(ref, plus) # rubocop:disable Metrics/AbcSize
45
52
  return ref if ref == plus
46
- href_idx = array_indexes(ref)
47
- hplus_idx = array_indexes(plus)
48
53
 
49
- shared = ref & plus
54
+ href_idx = array_indexes(ref)
55
+ hplus_idx = array_indexes(plus)
56
+ shared = ref & plus
50
57
  hshared_ref_idx = href_idx.slice(*shared)
51
58
 
52
59
  # hidx_plus_shared = hplus_idx.slice(*shared).each_with_object({}) do |(e, idx), reversed|
@@ -55,22 +62,23 @@ module Eco
55
62
  # shared_plus_idxs = hidx_plus_shared.keys.reverse
56
63
  shared_plus_idxs = hplus_idx.values_at(*shared).sort.reverse
57
64
 
58
- only_plus = plus - ref
65
+ only_plus = plus - ref
59
66
  honly_plus_idx = hplus_idx.slice(*only_plus)
60
67
 
61
- hplus_ref_idx = honly_plus_idx.each_with_object({}) do |(e, idx), hplus_ref_idx|
68
+ hplus_ref_idx = honly_plus_idx.each_with_object({}) do |(e, idx), href_idx_plus|
62
69
  ps_idx = shared_plus_idxs.bsearch {|i| idx >= i}
63
70
  rs_idx = ps_idx ? hshared_ref_idx[plus[ps_idx]] : -1
64
- hplus_ref_idx[e] = rs_idx
65
- end.group_by do |e, idx|
71
+ href_idx_plus[e] = rs_idx
72
+ end.group_by do |_e, idx|
66
73
  idx
67
- end.to_a.sort_by do |(idx, pairs)|
74
+ end.to_a.sort_by do |(idx, _pairs)|
68
75
  idx
69
76
  end.reverse.to_h.transform_values do |pairs|
70
77
  pairs.map(&:first)
71
78
  end
72
- hplus_ref_idx.each_with_object(ref.dup) do |(idx, elements), ref|
73
- ref.insert(idx+1, *elements)
79
+
80
+ hplus_ref_idx.each_with_object(ref.dup) do |(idx, elements), rf|
81
+ rf.insert(idx + 1, *elements)
74
82
  end
75
83
  end
76
84
 
@@ -83,3 +91,5 @@ module Eco
83
91
  end
84
92
  end
85
93
  end
94
+
95
+ # rubocop:enable Lint/DuplicateBranch
@@ -46,9 +46,11 @@ module Eco
46
46
 
47
47
  def validate_base_type!(base)
48
48
  return super if defined?(super)
49
+
49
50
  msg = "#{self} can only be included in Eco::API::Common::Loaders::Base"
50
51
  msg << "\nCan't be included in #{base}"
51
52
  raise LoadError, msg unless base <= Eco::API::Common::Loaders::Base
53
+
52
54
  true
53
55
  end
54
56
  end
@@ -11,7 +11,7 @@ module Eco
11
11
 
12
12
  # Matches anything between two consecutive (), inclusive
13
13
  def bracked_regex
14
- @bracked_regex ||= /(?<bracked>\([^\)]+?\))/
14
+ @bracked_regex ||= /(?<bracked>\([^\)]+?\))/ # rubocop:disable Style/RedundantRegexpEscape
15
15
  end
16
16
 
17
17
  # It always downcase, trim and remove double spaces.
@@ -24,10 +24,11 @@ module Eco
24
24
  def simplify_string(str, ignore: false)
25
25
  str = str.to_s.strip.downcase.gsub(/\s+/, ' ')
26
26
  return str unless ignore
27
+
27
28
  sub = non_letters_regex
28
29
  case ignore
29
- when Regexp; sub = ignore
30
- when String; sub = /[#{ignore}]+/
30
+ when Regexp then sub = ignore
31
+ when String then sub = /[#{ignore}]+/
31
32
  when Array
32
33
  return ignore.reduce(str) do |out, sub|
33
34
  simplify_string(out, ignore: sub)
@@ -38,67 +39,74 @@ module Eco
38
39
 
39
40
  # Offers multiple simplification methods to compare two strings
40
41
  # @note only one of the values can be a Regexp
41
- # @param value1 [String, Regexp, Nil]
42
- # @param value2 [String, Regexp, Nil]
42
+ # @param value_1 [String, Regexp, Nil]
43
+ # @param value_2 [String, Regexp, Nil]
43
44
  # @param exact [Boolean]
44
45
  # * when `true`: requiring the values to be exactly the same
45
46
  # * otherwise (`false`): compares in downcase, with no extra spaces
46
47
  # @param mild [Boolean] only a-z comparison
47
48
  # @param ignore [see @simplify_string]
48
- def same_string?(value1, value2, exact: false, mild: false, ignore: false)
49
- return true if value1.to_s.strip.empty? && value2.to_s.strip.empty?
50
- return false if value1.to_s.strip.empty? || value2.to_s.strip.empty?
51
- val1, val2 = value1, value2
49
+ def same_string?(value_1, value_2, exact: false, mild: false, ignore: false) # rubocop:disable Metrics/AbcSize
50
+ return true if value_1.to_s.strip.empty? && value_2.to_s.strip.empty?
51
+ return false if value_1.to_s.strip.empty? || value_2.to_s.strip.empty?
52
+
53
+ val_1, val_2 = value_1, value_2 # rubocop:disable Style/ParallelAssignment
54
+
52
55
  unless exact
53
- if val1.is_a?(String)
54
- val1 = simplify_string(val1, ignore: ignore) if ignore
55
- val1 = simplify_string(val1, ignore: non_letters_regex) if mild
56
+ if val_1.is_a?(String)
57
+ val_1 = simplify_string(val_1, ignore: ignore) if ignore
58
+ val_1 = simplify_string(val_1, ignore: non_letters_regex) if mild
56
59
  end
57
- if val2.is_a?(String)
58
- val2 = simplify_string(val2, ignore: ignore) if ignore
59
- val2 = simplify_string(val2, ignore: non_letters_regex) if mild
60
+ if val_2.is_a?(String)
61
+ val_2 = simplify_string(val_2, ignore: ignore) if ignore
62
+ val_2 = simplify_string(val_2, ignore: non_letters_regex) if mild
60
63
  end
61
64
  end
62
- case
63
- when val1.is_a?(String) && val2.is_a?(String)
64
- val1 == val2
65
- when val1.is_a?(Regexp) && val2.is_a?(String)
66
- val2 =~ val1
67
- when val1.is_a?(String) && val2.is_a?(Regexp)
68
- val1 =~ val2
65
+
66
+ if val_1.is_a?(String) && val_2.is_a?(String)
67
+ val_1 == val_2
68
+ elsif val_1.is_a?(Regexp) && val_2.is_a?(String)
69
+ val_2 =~ val_1
70
+ elsif val_1.is_a?(String) && val_2.is_a?(Regexp)
71
+ val_1 =~ val_2
69
72
  else
70
- #val1 == val2
71
- raise "Expected at least one String, and either a String or Regex. Given: (1: #{val1.class}) and (2: #{val2.class})"
73
+ #val_1 == val_2
74
+ msg = "Expected at least one String, and either a String or Regex. "
75
+ msg << "Given: (1: #{val_1.class}) and (2: #{val_2.class})"
76
+ raise ArgumentError, msg
72
77
  end
73
78
  end
74
79
 
75
80
  def titleize(str)
76
81
  return nil unless str
77
82
  return str if str.strip.empty?
83
+
78
84
  str.split(/\s+/).map do |part|
79
85
  part[0] = part[0].upcase
80
- part[1..-1] = part[1..-1].downcase
86
+ part[1..-1] = part[1..].downcase
81
87
  part
82
88
  end.join(" ")
83
89
  end
84
90
 
85
91
  def normalize_string(str)
86
92
  return nil unless str
87
- str.gsub(/[^[:print:]]/, '')
88
- .gsub(/[[:space:]]+/, ' ')
89
- .gsub(/[[:space:]]$/, '')
90
- .gsub(/[-\u2011\u2012\u2013]/, '-').yield_self do |str|
91
- str = yield(str) if block_given?
92
- str
93
- end
93
+
94
+ str.gsub(/[^[:print:]]/, '').
95
+ gsub(/[[:space:]]+/, ' ').
96
+ gsub(/[[:space:]]$/, '').
97
+ gsub(/[-\u2011\u2012\u2013]/, '-').then do |aux|
98
+ aux = yield(aux) if block_given?
99
+ aux
100
+ end
94
101
  end
95
102
 
96
103
  def clean_question(str)
97
104
  return nil unless str
98
- normalize_string(str) do |str|
99
- str.gsub(/\r\n/, ' ').yield_self do |str|
100
- str = yield(str) if block_given?
101
- str
105
+
106
+ normalize_string(str) do |x|
107
+ x.gsub(/\r\n/, ' ').then do |aux|
108
+ aux = yield(aux) if block_given?
109
+ aux
102
110
  end
103
111
  end
104
112
  end
@@ -116,7 +124,7 @@ module Eco
116
124
  when Ecoportal::API::V2::Page::Section
117
125
  ref << "Section '#{obj.heading || "(unnamed)"}'"
118
126
  when Ecoportal::API::V2::Page::Component
119
- ref << "Component '#{obj.label || "(unnamed of type '#{obj.type}')"}' in #{object_reference(obj.section)}"
127
+ ref << "Component '#{obj.label || "(unnamed of type '#{obj.type}')"}' in #{object_reference(obj.section)}" # rubocop:disable Layout/LineLength
120
128
  when Ecoportal::API::V2::Page::Force
121
129
  ref << "Force '#{obj.name}'"
122
130
  when Ecoportal::API::V2::Page::Force::Binding
@@ -131,12 +139,10 @@ module Eco
131
139
  end
132
140
 
133
141
  # https://stackoverflow.com/a/5661695/4352306
134
- def is_number?(value)
135
- begin
136
- true if Float(value)
137
- rescue ArgumentError => e
138
- false
139
- end
142
+ def is_number?(value) # rubocop:disable Naming/PredicateName
143
+ true if Float(value)
144
+ rescue ArgumentError
145
+ false
140
146
  end
141
147
  end
142
148
  end
@@ -8,13 +8,13 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
8
8
 
9
9
  attr_reader :target
10
10
 
11
- SAVE_PATCH = "ooze_patch_update.json"
11
+ SAVE_PATCH = "ooze_patch_update.json".freeze
12
12
  DRY_COUNT = 5
13
13
 
14
- def main(session, options, usecase)
14
+ def main(_session, options, _usecase)
15
15
  options[:end_get] = false
16
16
  raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
17
- @target = nil
17
+ @target = nil
18
18
  yield
19
19
  end
20
20
 
@@ -77,7 +77,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
77
77
  end
78
78
  end
79
79
  flds.select do |fld|
80
- value = (label == :unnamed) ? nil : label
80
+ value = label == :unnamed ? nil : label
81
81
  !label || same_string?(fld.label, value)
82
82
  end.each do |field|
83
83
  yield(field) if block_given?
@@ -87,8 +87,8 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
87
87
  def with_sections(entry = target, type: nil, heading: nil)
88
88
  secs = entry.sections
89
89
  secs = secs.get_by_type(type) if type
90
- secs = secs.select do |sec|
91
- value = (heading == :unnamed) ? nil : heading
90
+ secs.select do |sec|
91
+ value = heading == :unnamed ? nil : heading
92
92
  !heading || same_string?(sec.heading, value)
93
93
  end.each do |sec|
94
94
  yield(sec) if block_given?
@@ -96,9 +96,8 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
96
96
  end
97
97
 
98
98
  def with_stage(name:)
99
- if stage = target.stages.get_by_name(name)
100
- yield(stage) if block_given?
101
- end
99
+ return unless (stage = target.stages.get_by_name(name))
100
+ yield(stage) if block_given?
102
101
  stage
103
102
  end
104
103
 
@@ -106,6 +105,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
106
105
 
107
106
  # Hook method to use before the target is switched
108
107
  def before_loading_new_target(ooze_id)
108
+ ooze_id
109
109
  end
110
110
 
111
111
  def ooze(ooze_id = nil, stage_id: nil)
@@ -122,13 +122,13 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
122
122
  end
123
123
 
124
124
  def stage(id_name = nil, ooze: target)
125
- if ooze_id = ooze && ooze.id
125
+ if (ooze_id = ooze&.id)
126
126
  exit_error "#{object_reference(ooze)} does not have stages!" unless ooze.stages?
127
127
  else
128
128
  exit_error "There's no target ooze to retrieve stages from"
129
129
  end
130
130
 
131
- if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
131
+ if (stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name))
132
132
  return ooze if ooze.respond_to?(:current_stage_id) && (ooze.current_stage_id == stg.id)
133
133
  before_loading_new_target(ooze_id)
134
134
  return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
@@ -184,7 +184,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
184
184
  end
185
185
 
186
186
  def backup_patch!(ooze = target)
187
- unless patch = (patch_doc(ooze) || {})["page"]
187
+ unless (patch = (patch_doc(ooze) || {})["page"])
188
188
  logger.info "No changes to update for #{object_reference(ooze)}."
189
189
  return
190
190
  end
@@ -200,11 +200,9 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
200
200
  end
201
201
 
202
202
  def display_patch(entry = target)
203
- unless options.dig(:feedback, :only_stats)
204
- if patch = (patch_doc(entry) || {})["page"]
205
- pp patch
206
- end
207
- end
203
+ return if options.dig(:feedback, :only_stats)
204
+ return unless (patch = (patch_doc(entry) || {})["page"])
205
+ pp patch
208
206
  end
209
207
 
210
208
  def patch_doc(ooze = target)
@@ -229,8 +227,8 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
229
227
  false
230
228
  end
231
229
 
232
- def apiv2
233
- @apiv2 ||= session.api(version: :oozes)
230
+ def apiv2 # rubocop:disable Naming/VariableNumber
231
+ @apiv2 ||= session.api(version: :oozes) # rubocop:disable Naming/VariableNumber
234
232
  end
235
233
 
236
234
  def exit_error(msg)
@@ -21,10 +21,9 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
21
21
  attr_reader :session, :options, :usecase
22
22
  attr_reader :target
23
23
 
24
- def main(session, options, usecase)
24
+ def main(_session, options, _usecase)
25
25
  options[:end_get] = false
26
- @session = session; @options = options; @usecase = usecase
27
- @target = nil
26
+ @target = nil
28
27
  raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
29
28
 
30
29
  with_each_entry do |ooze|
@@ -48,9 +47,8 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
48
47
  def with_each_entry
49
48
  batched_search_results do |page_results|
50
49
  page_results.each do |page_result|
51
- if ooz = build_full_ooze(page_result.id)
52
- yield(ooz)
53
- end
50
+ next unless (ooz = build_full_ooze(page_result.id))
51
+ yield(ooz)
54
52
  end
55
53
  end
56
54
  end
@@ -59,36 +57,39 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
59
57
  # @note If it's a page instance with stages, there's where it will be handy
60
58
  # @param ooze_id [String]
61
59
  # @return [Ecoportal::API::V2::Page]
62
- def build_full_ooze(ooze_id)
63
- if page = ooze(ooze_id)
64
- return page unless page.is_a?(Ecoportal::API::V2::Pages::PageStage)
65
- pending_stage_ids = page.stages.ordered.map(&:id) - [page.current_stage_id]
66
- state = page.state
67
- secs_doc = page.sections.doc
68
- flds_doc = page.components.doc
69
- hsecs = secs_doc.each_with_object({}) {|sec, h| h[sec["id"]] = sec}
70
- hflds = flds_doc.each_with_object({}) {|fld, h| h[fld["id"]] = fld}
71
- pending_stage_ids.each do |id|
72
- if other_stage = stage(id, ooze: page)
73
- state = "inprogress" unless other_stage.state == "complete"
74
- other_stage.sections.doc.each do |sec_doc|
75
- unless hsecs.key?(id = sec_doc["id"])
76
- hsecs[id] = sec_doc
77
- secs_doc << sec_doc
78
- end
79
- end
80
- other_stage.components.doc.each do |comp_doc|
81
- unless hflds.key?(id = comp_doc["id"])
82
- hflds[id] = comp_doc
83
- flds_doc << comp_doc
84
- end
85
- end
60
+ def build_full_ooze(ooze_id) # rubocop:disable Metrics/AbcSize
61
+ return unless (page = ooze(ooze_id))
62
+ return page unless page.is_a?(Ecoportal::API::V2::Pages::PageStage)
63
+
64
+ pending_stage_ids = page.stages.ordered.map(&:id) - [page.current_stage_id]
65
+ state = page.state
66
+ secs_doc = page.sections.doc
67
+ flds_doc = page.components.doc
68
+ hsecs = secs_doc.each_with_object({}) {|sec, h| h[sec["id"]] = sec}
69
+ hflds = flds_doc.each_with_object({}) {|fld, h| h[fld["id"]] = fld}
70
+
71
+ pending_stage_ids.each do |id|
72
+ next unless (other_stage = stage(id, ooze: page))
73
+
74
+ state = "inprogress" unless other_stage.state == "complete"
75
+ other_stage.sections.doc.each do |sec_doc|
76
+ unless hsecs.key?(id = sec_doc["id"])
77
+ hsecs[id] = sec_doc
78
+ secs_doc << sec_doc
86
79
  end
87
80
  end
88
- Ecoportal::API::V2::Pages::PageStage.new(page.doc).tap do |ozz|
89
- ozz.state = state
81
+
82
+ other_stage.components.doc.each do |comp_doc|
83
+ unless hflds.key?(id = comp_doc["id"])
84
+ hflds[id] = comp_doc
85
+ flds_doc << comp_doc
86
+ end
90
87
  end
91
88
  end
89
+
90
+ Ecoportal::API::V2::Pages::PageStage.new(page.doc).tap do |ozz|
91
+ ozz.state = state
92
+ end
92
93
  end
93
94
 
94
95
  def batched_search_results
@@ -118,7 +119,7 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
118
119
  end
119
120
 
120
121
  def stage(id_name = nil, ooze: target)
121
- if ooze_id = ooze && ooze.id
122
+ if (ooze_id = ooze&.id)
122
123
  exit_error "#{object_reference(ooze)} does not have stages!" unless ooze.stages?
123
124
  else
124
125
  exit_error "There's no target ooze to get retrieve stages from"
@@ -145,12 +146,16 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
145
146
  def results_preview
146
147
  apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
147
148
  str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
148
- session.prompt_user("Do you want to proceed (y/N):", explanation: str_results, default: default_proceed, timeout: 10) do |res|
149
- unless res.upcase.start_with?("Y")
150
- puts "..."
151
- logger.info "Aborting script..."
152
- exit(0)
153
- end
149
+ session.prompt_user(
150
+ "Do you want to proceed (y/N):",
151
+ explanation: str_results,
152
+ default: default_proceed,
153
+ timeout: 10
154
+ ) do |res|
155
+ next if res.upcase.start_with?("Y")
156
+ puts "..."
157
+ logger.info "Aborting script..."
158
+ exit(0)
154
159
  end
155
160
  end
156
161
  end
@@ -165,20 +170,20 @@ class Eco::API::UseCases::OozeSamples::RegisterExportCase < Eco::API::Common::Lo
165
170
  end
166
171
 
167
172
  def conf_filters
168
- return filters if self.respond_to?(:filters)
173
+ return filters if respond_to?(:filters)
169
174
  []
170
175
  end
171
176
 
172
177
  def conf_search
173
- return search if self.respond_to?(:search)
178
+ return search if respond_to?(:search)
174
179
  end
175
180
 
176
181
  def register_id
177
182
  options.dig(:source, :register_id)
178
183
  end
179
184
 
180
- def apiv2
181
- @apiv2 ||= session.api(version: :oozes)
185
+ def apiv2 # rubocop:disable Naming/VariableNumber
186
+ @apiv2 ||= session.api(version: :oozes) # rubocop:disable Naming/VariableNumber
182
187
  end
183
188
 
184
189
  def exit_error(msg)