eco-helpers 2.0.36 → 2.0.40

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: '069fe6b03a523420dd24aa933eeffb05c20153ace763deb228de9e978a2f0ef6'
4
- data.tar.gz: 974d0af1009597161438cc9de087d42a73a503b6c0c8d50ab97c3030672e7180
3
+ metadata.gz: 48ff2a20387ce7665b56aebc5b9c4746088c4bdcbe1eb47cf97dd8464e8cea07
4
+ data.tar.gz: 2a63611643f60bd63f84e273a6fab267685b46dead2e01060e71f37a05398e22
5
5
  SHA512:
6
- metadata.gz: 8c089ac0050ab88d68eda450060785d9a59870cfa87b3c0c958612cb85f8251d826c824aa9da93b1cffa99afa4e7877ebd42dec1ad0d161764fea7de29495fb7
7
- data.tar.gz: f42d0a303f79775a71da9d13aa1639c8e0de85131590b84301fa1523e0293f87a943d9eaf65c22b97b73d71d667e889ae8bc0137861ac3811fed1a8a439de66f
6
+ metadata.gz: e421231ced6f863fd0f849f229ebba0ca242b666304613dce7d2084a891ac304de9e9002fb7a97212948a002cfe959351ce25752707daa74f63163b684f8332a
7
+ data.tar.gz: b4273a6a9e9de5fddc0bcd117ec0a467bcd57d3b904286f3130c36e6226b930e9b38bf6839867a09d79b0c284af17087b4bf0ea38b0edc69e024c64884097941
data/CHANGELOG.md CHANGED
@@ -1,10 +1,51 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.36] - 2021-08-xx
4
+ ## [2.0.40] - 2021-09-xx
5
5
 
6
6
  ### Added
7
+ - Unique access point for `validation` via core case `Eco::API::UseCases::OozeSamples::OozeBaseCase#update_ooze`
8
+
7
9
  ### Changed
10
+ ### Fixed
11
+
12
+ ## [2.0.39] - 2021-09-28
13
+
14
+ ### Changed
15
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
16
+ - Moved helpers from `Eco::API::UseCases::OozeSamples::OozeUpdateCase`
17
+
18
+ ### Fixed
19
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
20
+ - fix launch condition to be `Y`
21
+ - fix `search` method call
22
+ - Changed the `workflow` to prevent re-cache of people when `people` was not used
23
+
24
+ ## [2.0.38] - 2021-09-07
25
+
26
+ ### Added
27
+ - `Eco::CSV::Table` some more helpers to manage input `csv`s
28
+ - `#transform_headers` that allows to pass a block to decide the new name
29
+ - `#merge_same_header_names` that allows to deal with value of columns with same header name
30
+ - `#duplicated_header_names` that identifies repeated header names
31
+
32
+ ### Changed
33
+ - Changed the `workflow` to prevent re-cache of people when `people` was not used
34
+
35
+ ## [2.0.37] - 2021-09-03
36
+
37
+ ### Added
38
+ ### Changed
39
+
40
+ ### Fixed
41
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
42
+ - `#update_ooze` only count dry run for changed pages (to have better feedack)
43
+ - stop downloading the people manager
44
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
45
+ - prevent queuing non page objects
46
+
47
+ ## [2.0.36] - 2021-08-31
48
+
8
49
  ### Fixed
9
50
  - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
10
51
  - `#update_ooze` only count dry run for changed pages (to have better feedack)
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.3', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.12', '< 0.9'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.19', '< 0.9'
35
35
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
36
36
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
37
37
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
@@ -12,6 +12,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
12
12
  DRY_COUNT = 5
13
13
 
14
14
  def main(session, options, usecase)
15
+ options[:end_get] = false
15
16
  raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
16
17
  @session = session; @options = options; @usecase = usecase
17
18
  @target = nil
@@ -25,6 +26,48 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
25
26
  update_ooze(ooze)
26
27
  end
27
28
 
29
+ protected
30
+
31
+ def add_field(name, type, section, after: nil, before: nil, side: :left)
32
+ unless section.is_a?(Ecoportal::API::V2::Page::Section)
33
+ raise "You need to specify a section for a new field. Given: #{section.class}"
34
+ end
35
+ target.components.add(label: name, type: type) do |field|
36
+ section.add_component(field, after: after, before: before, side: side)
37
+ end.tap do |field|
38
+ yield(field) if block_given?
39
+ end
40
+ end
41
+
42
+ def with_fields(type: nil, label: nil)
43
+ flds = target.components
44
+ flds = flds.get_by_type(type) if type
45
+ flds = flds.select do |fld|
46
+ value = (label == :unnamed) ? nil : label
47
+ !label || same_string?(fld.label, value)
48
+ end.each do |field|
49
+ yield(field) if block_given?
50
+ end
51
+ end
52
+
53
+ def with_sections(type: nil, heading: nil)
54
+ secs = target.sections
55
+ secs = secs.get_by_type(type) if type
56
+ secs = secs.select do |sec|
57
+ value = (heading == :unnamed) ? nil : heading
58
+ !heading || same_string?(sec.heading, value)
59
+ end.each do |sec|
60
+ yield(sec) if block_given?
61
+ end
62
+ end
63
+
64
+ def with_stage(name:)
65
+ if stage = target.stages.get_by_name(name)
66
+ yield(stage) if block_given?
67
+ end
68
+ stage
69
+ end
70
+
28
71
  private
29
72
 
30
73
  # Hook method to use before the target is switched
@@ -69,6 +112,11 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
69
112
  def update_ooze(ooze = target)
70
113
  if !options[:simulate]
71
114
  return unless dirty?(ooze)
115
+
116
+ ooze.validate.tap do |validation|
117
+ raise validation if validation.is_a?(String)
118
+ end
119
+
72
120
  apiv2.pages.update(ooze).tap do |response|
73
121
  if response.success?
74
122
  ooze.consolidate!
@@ -4,44 +4,6 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::UseCases::Ooze
4
4
 
5
5
  private
6
6
 
7
- def with_fields(type: nil, label: nil)
8
- flds = target.components
9
- flds = flds.get_by_type(type) if type
10
- flds = flds.select do |fld|
11
- value = (label == :unnamed) ? nil : label
12
- !label || same_string?(fld.label, value)
13
- end.each do |field|
14
- yield(field) if block_given?
15
- end
16
- end
17
-
18
- def with_sections(type: nil, heading: nil)
19
- secs = target.sections
20
- secs = secs.get_by_type(type) if type
21
- secs = secs.select do |sec|
22
- value = (heading == :unnamed) ? nil : heading
23
- !heading || same_string?(sec.heading, value)
24
- end.each do |sec|
25
- yield(sec) if block_given?
26
- end
27
- end
28
-
29
- def with_stage(name:)
30
- if stage = target.stages.get_by_name(name)
31
- yield(stage) if block_given?
32
- end
33
- stage
34
- end
35
-
36
- def add_field(name, type, section, after: nil, side: :left)
37
- raise "You need to specify a section for a new field. Given: #{section.class}" unless section.is_a?(Ecoportal::API::V2::Page::Section)
38
- target.components.add(label: name, type: type) do |field|
39
- section.add_component(field, after: after, side: side)
40
- end.tap do |field|
41
- yield(field) if block_given?
42
- end
43
- end
44
-
45
7
  def to_field(value)
46
8
  fld = nil
47
9
  fld ||= value if value.is_a?(Ecoportal::API::V2::Page::Component)
@@ -50,5 +12,4 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::UseCases::Ooze
50
12
  #fld ||= value.reference if value.is_a?(Ecoportal::API::V2::Page::Force::Binding)
51
13
  end
52
14
 
53
-
54
15
  end
@@ -40,7 +40,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
40
40
  def new_target(object, warn_pending_changes: false)
41
41
  enqueue(object)
42
42
  super(object, warn_pending_changes: warn_pending_changes) do |pending|
43
- #queue(pending)
43
+ #enqueue(pending)
44
44
  end
45
45
  end
46
46
 
@@ -65,6 +65,9 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
65
65
 
66
66
  def enqueue(object)
67
67
  return unless object && object.respond_to?(:id)
68
+ unless object.is_a?(Ecoportal::API::V2::Page) or object.is_a?(Ecoportal::API::V2::Pages::PageStage)
69
+ raise "Queuing is just for entries. Expecting Page or PageStage. Given: #{object.class}"
70
+ end
68
71
  if elem = queue_get(object.id)
69
72
  msg = "Something is wrong. Native case 'RegisterUpdateCase' is "
70
73
  if (elem != object) && dirty?(elem)
@@ -126,7 +129,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
126
129
  apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
127
130
  str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
128
131
  session.prompt_user("Do you want to proceed (y/N):", explanation: str_results, default: "N", timeout: 10) do |res|
129
- if res.upcase.start_with?("N")
132
+ unless res.upcase.start_with?("Y")
130
133
  puts "..."
131
134
  logger.info "Aborting script..."
132
135
  exit(0)
@@ -139,7 +142,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
139
142
  @search_options ||= {}.tap do |opts|
140
143
  opts.merge!(sort: "created_at")
141
144
  opts.merge!(dir: "asc")
142
- opts.merge!(query: conf_filters) if conf_search
145
+ opts.merge!(query: conf_search) if conf_search
143
146
  opts.merge!(filters: conf_filters)
144
147
  end
145
148
  end
@@ -101,19 +101,28 @@ ASSETS.cli.config do |config|
101
101
  get_people = io.options.dig(:people, :get)
102
102
  partial_update = get_people && get_people.dig(:type) == :partial
103
103
  run_it = !io.options[:dry_run] || io.options.dig(:post_launch, :run)
104
- if run_it && partial_update
105
- unless io.options[:dry_run]
104
+ refresh_data = !io.options[:dry_run] && partial_update
105
+ if run_it
106
+ if refresh_data
106
107
  # get target people afresh
107
108
  people = io.session.micro.people_refresh(people: io.people, include_created: true)
108
109
  io = io.base.new(people: people)
110
+ else
111
+ msg = "Although there are post_launch cases, data will not be refreshed before their run"
112
+ if io.options[:dry_run]
113
+ msg += ", because we are in dry-run (simulate)."
114
+ elsif !partial_update
115
+ msg += ", because it is not a partial update (-get-partial option not present)."
116
+ end
117
+ io.session.logger.warn(msg)
109
118
  end
110
119
  else
111
120
  wf_post.skip!
112
121
  msg = "Although there are post_launch cases, they will NOT be RUN"
113
- if io.options[:dry_run]
114
- msg+= ", because we are in dry-run (simulate)."
115
- elsif !partial_update
122
+ if !partial_update
116
123
  msg+= ", because it is not a partial update (-get-partial)"
124
+ elsif io.options[:dry_run]
125
+ msg+= ", because we are in dry-run (simulate)."
117
126
  end
118
127
  io.session.logger.info(msg)
119
128
  end
@@ -146,8 +155,11 @@ ASSETS.cli.config do |config|
146
155
  get_people = io.options.dig(:people, :get)
147
156
  partial_update = get_people && get_people.dig(:type) == :partial
148
157
  unless !io.options[:end_get] || io.options[:dry_run] || partial_update
149
- people = io.session.micro.people_cache
150
- io = io.new(people: people)
158
+ # Prevent getting people when there were no use cases that used them
159
+ unless io.people
160
+ people = io.session.micro.people_cache
161
+ io = io.new(people: people)
162
+ end
151
163
  end
152
164
  io
153
165
  end
data/lib/eco/csv/table.rb CHANGED
@@ -15,6 +15,46 @@ module Eco
15
15
  end
16
16
  end
17
17
 
18
+ # @return [Eco::CSV::Table]
19
+ def transform_headers
20
+ header = self.headers
21
+ cols = self.columns
22
+ cols.each do |col|
23
+ col[0] = yield(col.first)
24
+ end
25
+ columns_to_table(cols)
26
+ end
27
+
28
+ # @return [Eco::CSV::Table]
29
+ def merge_same_header_names
30
+ dups = self.duplicated_header_names
31
+ out_rows = self.map do |row|
32
+ row.to_a.each_with_object({}) do |(name, value), out|
33
+ if dups.include?(name) && out.key?(name)
34
+ if block_given?
35
+ yield(value, out[name], name)
36
+ else
37
+ # resolve
38
+ value || out[name]
39
+ end
40
+ elsif out.key?(name)
41
+ out[name]
42
+ else
43
+ value
44
+ end.tap do |final_value|
45
+ out[name] = final_value
46
+ end
47
+ end
48
+ end
49
+ self.class.new(out_rows)
50
+ end
51
+
52
+ # @return [Array<String>] list of duplicated header names
53
+ def duplicated_header_names
54
+ header = self.headers
55
+ header.select {|e| header.count(e) > 1}.uniq
56
+ end
57
+
18
58
  # @return [Eco::CSV::Table]
19
59
  def transform_values
20
60
  transformed_rows = rows.map do |row|
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.36"
2
+ VERSION = "2.0.40"
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.0.36
4
+ version: 2.0.40
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.8.12
139
+ version: 0.8.19
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.9'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 0.8.12
149
+ version: 0.8.19
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'