eco-helpers 2.0.35 → 2.0.39

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: b4d6a312dda42afc3e6ba2becccf69d42121024d9b81e2c37276719089521971
4
- data.tar.gz: a3536e8fba79c1600135b4c4fd523a9c3a5262d605c39c751a3dc278d096b96e
3
+ metadata.gz: 84c964d986dd27f75c533dfcca194ca69354eeda318fe751f40db3f1276c4d69
4
+ data.tar.gz: 958a277abf32af125c768b17e5b6bf0791c6136658ebb1e0183f973b4b4b4839
5
5
  SHA512:
6
- metadata.gz: 8fcb26823bc3b6e3d35522c13d410094ea056269c14dea3b47bcaf16991ff36cde9537507a6a21c952aa15f590fb1f5b1fc594e55d08f04782a8e2802c695d0c
7
- data.tar.gz: fb2768c6e345da3dec034e7793876ecf25ae1cff76a059d98a38d9328c57884efb2a2f0b449eb28aea686ba074e477875fd8ba30201773170935f1c766fd45ae
6
+ metadata.gz: c704901e864a071f11b62a8e2ec4916f3cfb63fc6ebd87a92391339dfb559afe1e1f062c0234e2ffaa9a754a99eec978969447cdb19bbe49aa629aac040d7d80
7
+ data.tar.gz: 98348a3777cb58849a007b3e4487db3f270190c595c6dc8384e2b28a838f203332fe746a2429adb69cc32b3af62fb6048376e3606587a9ea9df548708321251a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,48 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [2.0.39] - 2021-09-07
5
+
6
+ ### Added
7
+ ### Changed
8
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
9
+ - Moved helpers from `Eco::API::UseCases::OozeSamples::OozeUpdateCase`
10
+
11
+ ### Fixed
12
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
13
+ - fix launch condition to be `Y`
14
+ - fix `search` method call
15
+ - Changed the `workflow` to prevent re-cache of people when `people` was not used
16
+
17
+ ## [2.0.38] - 2021-09-07
18
+
19
+ ### Added
20
+ - `Eco::CSV::Table` some more helpers to manage input `csv`s
21
+ - `#transform_headers` that allows to pass a block to decide the new name
22
+ - `#merge_same_header_names` that allows to deal with value of columns with same header name
23
+ - `#duplicated_header_names` that identifies repeated header names
24
+
25
+ ### Changed
26
+ - Changed the `workflow` to prevent re-cache of people when `people` was not used
27
+
28
+ ## [2.0.37] - 2021-09-03
29
+
30
+ ### Added
31
+ ### Changed
32
+
33
+ ### Fixed
34
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
35
+ - `#update_ooze` only count dry run for changed pages (to have better feedack)
36
+ - stop downloading the people manager
37
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
38
+ - prevent queuing non page objects
39
+
40
+ ## [2.0.36] - 2021-08-31
41
+
42
+ ### Fixed
43
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
44
+ - `#update_ooze` only count dry run for changed pages (to have better feedack)
45
+
4
46
  ## [2.0.35] - 2021-08-30
5
47
 
6
48
  ### 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.3', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.12', '< 0.9'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.14', '< 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
@@ -84,7 +127,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
84
127
  end
85
128
  end
86
129
  backup_patch!(ooze)
87
- exit(0) if dry_count > DRY_COUNT
130
+ exit(0) if dirty?(ooze) && dry_count > DRY_COUNT
88
131
  end
89
132
  end
90
133
 
@@ -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.35"
2
+ VERSION = "2.0.39"
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.35
4
+ version: 2.0.39
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.14
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.14
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'