eco-helpers 2.1.5 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaeec07a9cf6c0b584a546d6626f661d73f608332a72ef938bcfe7513adc6f2c
4
- data.tar.gz: 285234b6c42a281c900ae3c05dc5a71f9e6a55d4aa52a884457a6956a02c456e
3
+ metadata.gz: 57558123bd83d606799604772ef717673f58bd089efc90458116a3126b1742f4
4
+ data.tar.gz: 99ec5e1bf52f4cd3ce3bbab5da60c64bfb42aa7742dfbe85897b40bfd6c76471
5
5
  SHA512:
6
- metadata.gz: bc26467b2cb2b102a03aff3e5c189c60d3d63290c107e69c609e5536e70631e50e1a2c21c5859260e048c132584288fc728fd185681df4540a3c67e822f581dc
7
- data.tar.gz: 0a5a23a848dac8114d1945efac8f58508066de077cac286e4b6bd473965356ce2aa0b961b1b2e542183afb58f04b1ceeb441f14452e0477976b565c9ff414a51
6
+ metadata.gz: 4d5bbe4a67ec3b9f18025877ecc3ce8735a8e816be686a17deee58be2e9f1d1c35b54b73a004440210905b113230224c8ce9f2b225746e7bf7c276b274f67b5e
7
+ data.tar.gz: 3d492d4ead671bc288621135e197ee3ce42ed40a10b73546ca7b8f3c3b9d137c2048105beda464d2d7b0d443dde510f3c86edac0bdb68f5262ae434f063864f8
data/CHANGELOG.md CHANGED
@@ -1,13 +1,29 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.1.6] - 2022-10-xx
4
+ ## [2.1.8] - 2022-11-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
- ## [2.1.5] - 2022-10-xx
10
+ ## [2.1.7] - 2022-11-17
11
+
12
+ ### Added
13
+ - `Eco::API::UseCases::OozeSamples::RegisterMigrationCase` method `excluded_field_hooks`
14
+ - This enables the ability to prevent fields from being paired/copied/written on
15
+
16
+ ### Changed
17
+ - **refactored** `#with_src_dst_field_pair` helper
18
+ - from `Eco::API::UseCases::OozeSamples::HelpersMigration::Copying`
19
+
20
+ ## [2.1.6] - 2022-11-17
21
+
22
+ ### Fixed
23
+ - `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#to_i` (missing param on method)
24
+ - `Eco::API::UseCases::OozeSamples::HelpersMigration::TypedFieldsPairing#multi_delete` typo
25
+
26
+ ## [2.1.5] - 2022-11-17
11
27
 
12
28
  ### Added
13
29
  - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase` added creation count
@@ -16,7 +32,7 @@ All notable changes to this project will be documented in this file.
16
32
  - `with_rescue` that prompts user to continue
17
33
  - this is for usage in child classes
18
34
  - new use case and helpers thereof `Eco::API::UseCases::OozeSamples::RegisterMigrationCase`
19
-
35
+
20
36
  ### Changed
21
37
  - upgraded `ecoportal-api-v2` **gem**
22
38
  - **refactored** `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#same_string?`
@@ -126,7 +126,7 @@ module Eco
126
126
  end
127
127
  end
128
128
 
129
- def to_i
129
+ def to_i(value)
130
130
  Float(value).to_i
131
131
  end
132
132
 
@@ -9,8 +9,8 @@ class Eco::API::UseCases::OozeSamples
9
9
  session.logger
10
10
  end
11
11
 
12
- def copy_generic_paired_fields(src, dst, exclude_ximport: false)
13
- HelpersMigration::TypedFieldsPairing.new(src, dst, exclude_ximport: false).tap do |pairing|
12
+ def copy_generic_paired_fields(src, dst, src_excluded: [], dst_excluded: [], exclude_ximport: false)
13
+ HelpersMigration::TypedFieldsPairing.new(src, dst, src_excluded: src_excluded, dst_excluded: dst_excluded, exclude_ximport: false).tap do |pairing|
14
14
  pairing.each_pair do |src_fld, dst_fld|
15
15
  copy_field_content(src_fld, dst_fld)
16
16
  yield(src_fld, dst_fld, pairing) if block_given?
@@ -18,11 +18,11 @@ class Eco::API::UseCases::OozeSamples
18
18
  end
19
19
  end
20
20
 
21
- def copy_hooked_fields(src, dst, hook:, type:, fields_tracker: nil)
21
+ def copy_hooked_fields(src, dst, hook:, type:, fields_tracker: nil, src_excluded: [], dst_excluded: [])
22
22
  case hook
23
23
  when String
24
- with_src_dest_field_pair(src, dst, label: to_regex(hook), type: type) do |src_fld, dst_fld|
25
- copy_field_content(src_fld, dst_fld, type).tap do |result|
24
+ with_src_dst_field_pair(src, dst, label: to_regex(hook), type: type, src_excluded: src_excluded, dst_excluded: dst_excluded) do |src_fld, dst_fld|
25
+ copy_field_content(src_fld, dst_fld).tap do |result|
26
26
  fields_tracker.resolve(src_fld, dst_fld) if fields_tracker
27
27
  yield(src_fld, dst_fld, fields_tracker) if block_given?
28
28
  end
@@ -30,8 +30,8 @@ class Eco::API::UseCases::OozeSamples
30
30
  when Hash
31
31
  hook.each do |hook_src, hook_dst|
32
32
  src_lab, dst_lab = to_regex(hook_src), to_regex(hook_dst)
33
- with_src_dest_field_pair(src, dst, label: src_lab, label_dst: dst_lab, type: type) do |src_fld, dst_fld|
34
- copy_field_content(src_fld, dst_fld, type).tap do |result|
33
+ with_src_dst_field_pair(src, dst, label: src_lab, label_dst: dst_lab, type: type, src_excluded: src_excluded, dst_excluded: dst_excluded) do |src_fld, dst_fld|
34
+ copy_field_content(src_fld, dst_fld).tap do |result|
35
35
  fields_tracker.resolve(src_fld, dst_fld) if fields_tracker
36
36
  yield(src_fld, dst_fld, fields_tracker) if block_given?
37
37
  end
@@ -44,33 +44,59 @@ class Eco::API::UseCases::OozeSamples
44
44
  /^#{str}$/i
45
45
  end
46
46
 
47
- def with_src_dest_field_pair(src, dst, label: nil, label_dst: label, type: nil)
47
+ # @note
48
+ # - When used with `type: nil` it may pair fields of different type. There isn't refinement for this yet.
49
+ def with_src_dst_field_pair(src, dst, label: nil, label_dst: label, type: nil, src_excluded: [], dst_excluded: [])
48
50
  unless respond_to?(:with_fields, true)
49
51
  raise "These helpers are to be included in class cases inheriting from Eco::API::UseCases::OozeSamples::RegisterUpdateCase"
50
52
  end
51
53
  src_flds = with_fields(src, label: label, type: type)
52
54
  dst_flds = with_fields(dst, label: label_dst, type: type)
55
+ src_fld, dst_fld = src_flds.first, dst_flds.first
56
+
57
+ # Not found
58
+ if dst_flds.empty? || src_flds.empty?
59
+ msg = "There isn't a '#{type}'"
60
+ dst_msg = dst_flds.empty?? "destination field named '#{label_dst}'" : nil
61
+ src_msg = src_flds.empty?? "source field named '#{label}'" : nil
62
+ msg << " #{[dst_msg, src_msg].join(" or ")} (source: '#{src.id}')"
63
+ logger.warn(msg)
64
+ return nil, nil
65
+ end
66
+
67
+ # Fields exclusion
68
+ dst_flds -= dst_excluded unless dst_excluded.empty?
69
+ src_flds -= src_excluded unless src_excluded.empty?
70
+ src_fld, dst_fld = src_flds.first, dst_flds.first
71
+ return src_fld, dst_fld if dst_flds.empty? || src_flds.empty?
53
72
 
54
73
  if dst_flds.count > 1
55
74
  logger.warn("There are #{dst_flds.count} destination '#{type}' fields named '#{label_dst}' (source: '#{src.id}'). Using first...")
56
- elsif dst_flds.empty?
57
- logger.warn("There isn't a destination '#{type}' field named '#{label_dst}' (source: '#{src.id}')")
58
- return nil, nil
59
75
  end
60
76
 
61
77
  if src_flds.count > 1
62
- logger.warn("There are #{src_flds.count} source '#{type}' fields named '#{label}' (source: '#{src.id}'). Using first...")
63
- elsif src_flds.empty?
64
- logger.warn("There isn't a source '#{type}' field named '#{label}' (source: '#{src.id}')")
65
- return nil, dst
78
+ msg = "There are #{src_flds.count} source '#{type}' fields named '#{label}' (source: '#{src.id}'). "
79
+ src_content = src_flds.reject(&:empty?)
80
+ if src_content.empty?
81
+ msg << "None with content. Using first..."
82
+ else
83
+ src_fld = src_content.first
84
+ if src_content.count == 1
85
+ msg << "Using the only one with content (idx: #{src_flds.index(src_fld)})..."
86
+ else
87
+ msg << "#{src_content.count} have content. Using first..."
88
+ end
89
+ end
90
+ logger.warn(msg)
66
91
  end
67
92
 
68
- [src_flds.first, dst_flds.first].tap do |(src_fld, dst_fld)|
93
+ [src_fld, dst_fld].tap do |(src_fld, dst_fld)|
69
94
  yield(src_fld, dst_fld) if block_given?
70
95
  end
71
96
  end
72
97
 
73
- def copy_field_content(src, dst, type = src.type)
98
+ def copy_field_content(src, dst)
99
+ type = src.type
74
100
  case type
75
101
  when "select"
76
102
  src.values.each {|val| dst.select(val)}
@@ -192,7 +192,7 @@ class Eco::API::UseCases::OozeSamples
192
192
  @dst_multi.delete(dst_fld) if pairs.empty?
193
193
  end
194
194
  end
195
- src_dst_multi.delete(type) if type_pairs.empty?
195
+ src_dst_multi.delete(fld.type) if type_pairs.empty?
196
196
  end
197
197
  end
198
198
 
@@ -7,12 +7,17 @@
7
7
  # 1. field label name (String or RegExp body/source),
8
8
  # 2. or an object with key-value being source-destination label names (also supports RegExp body/source)
9
9
  # - Example: {"select": ["severity of .*:", {"type of event:" => "type of incident:"}]}
10
+ # - "all" as type will target all type of fields.
11
+ # - Caution with this! Copying between fields of different types is not yet supported.
10
12
  # - You may either
11
13
  # 1. define the `process_ooze` method calling super with a block: super.do ||
12
14
  # 2. of define the function `custom_processing(draft, source, fields_tracker: nil)`
13
15
  # - You can define a callback function, `paired_fields_post_callback(src_fld, dst_fld, pairing_tracking = nil)`
14
16
  # - It will be called after copying by using any of the pairing methods, and allows to introduce modifications
15
17
  # such as selection option mappings
18
+ # - You may define a method called `excluded_field_hooks` with same syntax as the json pairing file
19
+ # - This will exclude as source and destination targets any fields matching those patterns.
20
+ # - This is specially useful to discard rich text field guidelines (i.e. `{"rich_text" => [".*guideline:"]}`)
16
21
  # This case expects `options[:source][:register_id]`
17
22
  class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCases::OozeSamples::RegisterUpdateCase
18
23
  name "register-migration-case"
@@ -101,8 +106,22 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
101
106
 
102
107
  def copy_pairings(src, dst)
103
108
  after_copy = callback(:paired_fields_post)
104
- copy_generic_paired_fields(src, dst, exclude_ximport: self.class::EXCLUDE_XIMPORT, &after_copy).tap do |pairing_tracking|
105
- copy_mapped_fields(src, dst, fields_tracker: pairing_tracking, &after_copy)
109
+ params = {
110
+ src_excluded: excluded_fields(src),
111
+ dst_excluded: excluded_fields(dst)
112
+ }
113
+ copy_generic_paired_fields(src, dst, **params.merge(exclude_ximport: self.class::EXCLUDE_XIMPORT), &after_copy).tap do |pairing_tracking|
114
+ copy_mapped_fields(src, dst, **params.merge(fields_tracker: pairing_tracking), &after_copy)
115
+ end
116
+ end
117
+
118
+ def excluded_fields(entry)
119
+ return [] unless respond_to?(:excluded_field_hooks, true)
120
+ excluded_field_hooks.each_with_object([]) do |(type, hooks), excluded|
121
+ hooks.each do |hook|
122
+ type = (type == "all")? nil : type
123
+ excluded.push(*with_fields(entry, label: to_regex(hook), type: type))
124
+ end
106
125
  end
107
126
  end
108
127
 
@@ -112,11 +131,12 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
112
131
  raise msg
113
132
  end
114
133
 
115
- def copy_mapped_fields(src, dst, fields_tracker: nil, &after_copy)
134
+ def copy_mapped_fields(src, dst, **kargs, &after_copy)
116
135
  return [] unless field_maps?
117
136
  field_maps.each do |type, field_hooks|
137
+ type = (type == "all")? nil : type
118
138
  field_hooks.each do |hook_name|
119
- copy_hooked_fields(src, dst, hook: hook_name, type: type, fields_tracker: fields_tracker, &after_copy)
139
+ copy_hooked_fields(src, dst, hook: hook_name, type: type, **kargs, &after_copy)
120
140
  end
121
141
  end
122
142
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.1.5"
2
+ VERSION = "2.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura