eco-helpers 2.1.6 → 2.1.8

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: a60227ce2638442d0a7b4cb8a292506ef2b4f13b59535c53e7397afb0ac48eb0
4
- data.tar.gz: 794d2c7e3c85e1a9e97c22677efd483e94fb47687ff6dd2c238613099022a7e1
3
+ metadata.gz: 34fabf1bbcb318ac7860992bc5a24a5b27e7941e6976cda455d1e65e274fa16c
4
+ data.tar.gz: e44bc288d08d82ce98921f63c978d84e8813883a729e17a718978aab293d9c44
5
5
  SHA512:
6
- metadata.gz: 4186a76a325a920057c6a71a0dd1f774a9342a4f1e280c392e639ceb008f845a104b7615fa8e03d11f9dab73fd995e15f25551c3b989577fa2595a64505550b9
7
- data.tar.gz: 2ab664150646c1f9af560aca8c2a1dff9ddd651f867e28bddd5d560ec89c4ae9bbc8884fadd07346ab7ec6544288adcc2ce9be866adadbb63db04f0e521ee3e9
6
+ metadata.gz: a94bc6ca7d5c012dc03491e6e96456d4ae620c4ecfc52023716525caadb4e6683e49de8fe8d56479dc883b4710bef1c2a3b9f51fd4a7d6e7da52e0cf1d15cb50
7
+ data.tar.gz: 7ca163e67e3675bf3d0a84b4f11cb57cf25c164b169d418164da94963cfdbdcb5d6cc8b8ae78fb5311e955119190b93d254c715e24a05de73f90974e6ed154dd
data/CHANGELOG.md CHANGED
@@ -1,18 +1,39 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.1.7] - 2022-11-xx
4
+ ## [2.1.9] - 2022-11-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.1.8] - 2022-11-18
11
+
12
+ ### Added
13
+ - `Eco::API::UseCases::OozeSamples::RegisterMigrationCase`
14
+ - When in `dry-run` mode, it adds one line before creation feedback, so it is clear the feedback is about creation (i.e. none of the source entries got mistakenly updated)
15
+ - **enhanced** `Eco::API::UseCases::OozeSamples::OozeBaseCase#with_fields`
16
+ - It allows to optionally pass as first parameter a section or a stage (default: ooze)
17
+
18
+ ### Changed
19
+ - upgraded gem dependency `ecoportal-api-v2`
20
+
21
+ ## [2.1.7] - 2022-11-17
22
+
23
+ ### Added
24
+ - `Eco::API::UseCases::OozeSamples::RegisterMigrationCase` method `excluded_field_hooks`
25
+ - This enables the ability to prevent fields from being paired/copied/written on
26
+
27
+ ### Changed
28
+ - **refactored** `#with_src_dst_field_pair` helper
29
+ - from `Eco::API::UseCases::OozeSamples::HelpersMigration::Copying`
30
+
10
31
  ## [2.1.6] - 2022-11-17
11
32
 
12
33
  ### Fixed
13
34
  - `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#to_i` (missing param on method)
14
- - `Eco::API::UseCases::OozeSamples::module HelpersMigration::TypedFieldsPairing#multi_delete` typo
15
-
35
+ - `Eco::API::UseCases::OozeSamples::HelpersMigration::TypedFieldsPairing#multi_delete` typo
36
+
16
37
  ## [2.1.5] - 2022-11-17
17
38
 
18
39
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.8.5', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.9.5', '< 0.10'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.9.6', '< 0.10'
35
35
  spec.add_dependency 'ecoportal-api-graphql', '>= 0.1.10', '< 0.2'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
@@ -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)}
@@ -70,8 +70,14 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
70
70
 
71
71
  def with_fields(entry = target, type: nil, label: nil)
72
72
  flds = entry.components
73
- flds = flds.get_by_type(type) if type
74
- flds = flds.select do |fld|
73
+ if type
74
+ if flds.respond_to?(:get_by_type)
75
+ flds = flds.get_by_type(type)
76
+ else
77
+ flds = flds.select {|fld| fld.type == type}
78
+ end
79
+ end
80
+ flds.select do |fld|
75
81
  value = (label == :unnamed) ? nil : label
76
82
  !label || same_string?(fld.label, value)
77
83
  end.each do |field|
@@ -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
@@ -140,6 +160,7 @@ class Eco::API::UseCases::OozeSamples::RegisterMigrationCase < Eco::API::UseCase
140
160
  if !options[:dry_run]
141
161
  create_ooze(draft, template_id: from).page_id
142
162
  else
163
+ logger.info("Creation sample follows...")
143
164
  dry_run_feedback(draft)
144
165
  false
145
166
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.1.6"
2
+ VERSION = "2.1.8"
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.6
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 0.9.5
139
+ version: 0.9.6
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.10'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 0.9.5
149
+ version: 0.9.6
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.10'