eco-helpers 1.5.7 → 1.5.12

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: 7620c9cd737d1ba284868030b84b2589b0cd55c71708fee487c79dbce3fa3313
4
- data.tar.gz: 444174de9c8634744060d411dcbad7229ef6c2acf24065f001ff29ecd41c6d4c
3
+ metadata.gz: cb7b7377b64d086bb76f11f99c2f63f19eae2e25c67dc52fdeb034d58af888f4
4
+ data.tar.gz: d1fecbe4232a57e21a9f100fcb5ef7e0058787cdb19d5e84cb79dfc9d0082889
5
5
  SHA512:
6
- metadata.gz: ae26e27d3b51f2b11cc50f6a6c6acc6229172b6a0416ca6feb633727b7fb45c9f19307d8d355ea14f77a67a041cf6886b54299f555b45990ff2c16ff6857f130
7
- data.tar.gz: a11ca5b39ca0067c912b2ae59b5bfff1f59caa8ee23565b91f3dc8d694c966cc593a9efb5b7ca1c9c53cae4855f6fa4e59c3a792c6068c5179637641f22a5300
6
+ metadata.gz: 1c77b34e3ce111d4203eb54bd765f04d00044e42cdd53a05443668e3a35589193f95b877b24fe10acbdb0214aab1aaaa5031be6f6f6012983242e4e03ebcfe7a
7
+ data.tar.gz: 2cff100787f222de6300ec9d991b6dba8b36726b64a90ca7618ff35330efe1dd4b0431d197cdf952dc657701357b5ff3f9fe5799f2b749f512baf9f6dd145c83
data/.yardopts CHANGED
@@ -5,5 +5,6 @@
5
5
  --no-private
6
6
  --output-dir ./doc
7
7
  'lib/**/*.rb'
8
+ CHANGELOG.md
8
9
  -
9
10
  LICENSE
@@ -1,6 +1,52 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.5.12] - 2021-01-xx
5
+
6
+ ### Added
7
+ - `Eco::API::Common::People::DefaultParsers::CSVParser` when cell content is `Null`, capture `nil` value.
8
+
9
+ ### Changed
10
+ - upgraded `ecoportal-api` dependency
11
+
12
+ ### Fixed
13
+
14
+
15
+ ## [1.5.11] - 2021-01-25
16
+
17
+ ### Added
18
+ - `Eco::API::Organization::TagTree#subtag?` to check if the tag is in any subtree.
19
+
20
+ ### Changed
21
+
22
+ ### Fixed
23
+ - `Eco::API::MicroCases#set_supervisor` shouldn't set it if the entry does not have it.
24
+
25
+ ## [1.5.10] - 2021-01-19
26
+
27
+ ### Added
28
+ ### Changed
29
+ ### Fixed
30
+ - `Eco::API::Session::Batch::Errors#print` show the row number of the input data.
31
+
32
+ ## [1.5.9] - 2021-01-08
33
+
34
+ ### Added
35
+ - `Eco::API::Organization::TagTree#subtags` to get all the tags but those of the highest level.
36
+
37
+ ### Changed
38
+ ### Fixed
39
+
40
+
41
+ ## [1.5.8] - 2021-01-05
42
+
43
+ ### Added
44
+ ### Changed
45
+ ### Fixed
46
+ - `Eco::API::Session::Batch::Jobs#job` shouldn't be calling the post-launch callback function on creation.
47
+ - `Eco::API::Session#new_job` should include a `&block` parameter.
48
+ - `Eco::API::UseCases::DefaultCases::RefreshCase`: fixed typo
49
+
4
50
  ## [1.5.7] - 2020-12-17
5
51
 
6
52
  ### Added
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.summary = %q{eco-helpers to manage people api cases}
14
14
  s.homepage = "https://www.ecoportal.com"
15
15
  s.licenses = %w[MIT]
16
+ s.required_ruby_version = '>= 2.4.4'
16
17
 
17
18
  s.files = `git ls-files -z`.split("\x0").reject do |f|
18
19
  f.match(%r{^(test|spec|features)/})
@@ -28,7 +29,7 @@ Gem::Specification.new do |s|
28
29
  s.add_development_dependency "yard", ">= 0.9.18", "< 0.10"
29
30
  s.add_development_dependency "redcarpet", ">= 3.5.0", "< 3.6"
30
31
 
31
- s.add_dependency 'ecoportal-api', '>= 0.7.3', '< 0.8'
32
+ s.add_dependency 'ecoportal-api', '>= 0.7.4', '< 0.8'
32
33
  s.add_dependency 'ecoportal-api-oozes', '>= 0.7.2', '< 0.8'
33
34
  s.add_dependency 'aws-sdk-s3', '>= 1.64.0', '< 2'
34
35
  s.add_dependency 'aws-sdk-ses', '>= 1.29.0', '< 2'
@@ -5,8 +5,7 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
5
5
  Eco::CSV.parse(data, headers: true, skip_blanks: true).each_with_object([]) do |row, arr_hash|
6
6
  row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
7
7
  next if attr.to_s.strip.empty?
8
- value = row[attr]
9
- hash[attr.strip] = value.to_s.empty?? nil : value
8
+ hash[attr.strip] = parse_string(row[attr])
10
9
  end
11
10
  arr_hash.push(row_hash)
12
11
  end
@@ -23,4 +22,18 @@ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Lo
23
22
  CSV::Table.new(arr_rows).to_csv
24
23
  end
25
24
 
25
+ private
26
+
27
+ def parse_string(value)
28
+ return nil if value.to_s.empty?
29
+ return nil if null?(value)
30
+ value
31
+ end
32
+
33
+ def null?(value)
34
+ return true if !value
35
+ str = value.strip.upcase
36
+ ["NULL"].any? {|token| str == token}
37
+ end
38
+
26
39
  end
@@ -75,7 +75,7 @@ module Eco
75
75
  !parsing?
76
76
  end
77
77
 
78
- # @note `Eco::API::Common::People::EntryFactory#entries` adds this `idx`
78
+ # @note `Eco::API::Common::People::EntryFactory#entries` adds this `idx` (i.e. row number)
79
79
  # @return [Integer] the entry number in the input file
80
80
  def idx
81
81
  final_entry["idx"]
@@ -11,9 +11,11 @@ module Eco
11
11
  def set_core_with_supervisor(entry, person, people, supers_job, options)
12
12
  unless options.dig(:exclude, :core) && !person.new?
13
13
  micro.set_core(entry, person, options)
14
- micro.set_supervisor(entry.supervisor_id, person, people, options) do |unkown_id|
15
- # delay setting supervisor if does not exit
16
- supers_job.add(person) {|person| person.supervisor_id = unkown_id}
14
+ if entry.supervisor_id?
15
+ micro.set_supervisor(entry.supervisor_id, person, people, options) do |unkown_id|
16
+ # delay setting supervisor if does not exit
17
+ supers_job.add(person) {|person| person.supervisor_id = unkown_id}
18
+ end
17
19
  end
18
20
  end
19
21
  end
@@ -46,6 +46,10 @@ module Eco
46
46
  @has_tags.empty?
47
47
  end
48
48
 
49
+ # Gets all the tags of the current node tree.
50
+ # @note
51
+ # - this will include the upper level tag(s) as well
52
+ # - to get all but the upper level tag(s) use `subtags` method instead
49
53
  # @param depth [Integer] if empty, returns the list of tag nodes of that level. Otherwise the list of tag nodes of the entire subtree.
50
54
  # @return [Array<String>]
51
55
  def tags(depth: nil)
@@ -58,6 +62,19 @@ module Eco
58
62
  end
59
63
  end
60
64
 
65
+ # Gets all but the upper level tags of the current node tree.
66
+ # @return [Array<String>]
67
+ def subtags
68
+ tags - tags(depth: depth)
69
+ end
70
+
71
+ # Verifies if a tag exists in the subtree(s).
72
+ # @param key [String] tag to verify.
73
+ # @return [Boolean]
74
+ def subtag?(key)
75
+ subtags.include?(key&.upcase)
76
+ end
77
+
61
78
  # Verifies if a tag exists in the tree.
62
79
  # @param key [String] tag to verify.
63
80
  # @return [Boolean]
@@ -217,6 +217,7 @@ module Eco
217
217
  @job_groups ||= Batch::JobsGroups.new(enviro)
218
218
  end
219
219
 
220
+ # It retrives the group of `Batch::Jobs` named `name`. It creates it if it doesn't exist.
220
221
  # @return [Eco::API::Session::Batch::Jobs]
221
222
  def job_group(name, order: :last)
222
223
  case
@@ -228,9 +229,10 @@ module Eco
228
229
  end
229
230
 
230
231
  # Shortcut to create a job of certain type within a group
232
+ # @param [see @Eco::API::Session::Batch::Jobs#new]
231
233
  # @return [Eco::API::Session::Batch::Job]
232
- def new_job(group, name, type, usecase, sets = [:core, :details, :account])
233
- job_group(group).new(name, usecase: usecase, type: type, sets: sets)
234
+ def new_job(group, name, type, usecase, sets = [:core, :details, :account], &block)
235
+ job_group(group).new(name, usecase: usecase, type: type, sets: sets, &block)
234
236
  end
235
237
 
236
238
  # @see Eco::API::Session::Batch::JobsGroups#launch
@@ -123,7 +123,7 @@ module Eco
123
123
  entry = queue.to_a[i]
124
124
  response = status[i]
125
125
  msg = "Error #{response.status}: #{response.body}\n"
126
- msg += "-- Failed to batch #{method} (entry #{i+1}). Person: #{person_ref(entry)}"
126
+ msg += "-- Failed to batch #{method}. Person: #{person_ref(entry)}"
127
127
  end
128
128
  msg
129
129
  end
@@ -164,7 +164,8 @@ module Eco
164
164
  private
165
165
 
166
166
  def person_ref(entry)
167
- "(id: '#{get_attr(entry, :id)}') '#{get_attr(entry, :name)}' ('#{get_attr(entry, :external_id)}': '#{get_attr(entry, :email)}')"
167
+ row_str = (row = get_row(entry)) ? "(row: #{row}) " : nil
168
+ "#{row_str}(id: '#{get_attr(entry, :id)}') '#{get_attr(entry, :name)}' ('#{get_attr(entry, :external_id)}': '#{get_attr(entry, :email)}')"
168
169
  end
169
170
 
170
171
  def get_attr(entry, attr)
@@ -175,6 +176,15 @@ module Eco
175
176
  end
176
177
  end
177
178
 
179
+ def get_row(value)
180
+ case value
181
+ when Eco::API::Common::People::PersonEntry
182
+ value.idx
183
+ when Ecoportal::API::V1::Person
184
+ get_row(value.entry)
185
+ end
186
+ end
187
+
178
188
  end
179
189
  end
180
190
  end
@@ -96,7 +96,7 @@ module Eco
96
96
  # @param entry [Ecoportal::API::V1::Person, Enumberable<Person>] the person(s) we want to update, carrying the changes to be done.
97
97
  # @param unique [Boolean] specifies if repeated entries should be avoided in the queue.
98
98
  # @yield [person] callback before launching the batch job request against the server.
99
- # @yieldparam param [Person] current person object that that should be treated by the callback before launching the batch.
99
+ # @yieldparam person [Person] current person object that that should be treated by the callback before launching the batch.
100
100
  # @return [Eco::API::Session::Batch::Job] this `Batch::Job`.
101
101
  def add(entry, unique: true, &block)
102
102
  case entry
@@ -42,13 +42,23 @@ module Eco
42
42
  @jobs.key?(name)
43
43
  end
44
44
 
45
+ # It retrieves an existing job named `name` or creates it if it doesn't exist.
46
+ # @note
47
+ # - the block should only be passed when creating the job
48
+ # @param [see @Eco::API::Session::Batch::Jobs#new]
49
+ # @return [Eco::API::Session::Batch::Job]
45
50
  def job(name, type: nil, sets: nil, usecase: nil, &block)
51
+ fatal "Can't give a job post-launch callback &block to an already existing job" if exists?(name)
46
52
  new(name, type: type, sets: sets, usecase: usecase, &block) unless exists?(name)
47
- self[name].tap do |job|
48
- block.call(job) if block
49
- end
53
+ self[name]
50
54
  end
51
55
 
56
+ # Creates a new `Batch::Job` included as part of this `Batch::Jobs`.
57
+ # @param [see Eco::API::Session::Job#new]
58
+ # @yield [job, status] callback after launching the batch job request against the server.
59
+ # @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server.
60
+ # @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch.
61
+ # @return [Eco::API::Session::Batch::Job]
52
62
  def new(name, type:, sets:, usecase: nil, &block)
53
63
  fatal "Can't create job named '#{name}' because it already exists." if exists?(name)
54
64
 
@@ -57,6 +67,11 @@ module Eco
57
67
  end
58
68
  end
59
69
 
70
+ # @param job [Eco::API::Session::Batch::Job] the `Batch::Job` to add.
71
+ # @yield [job, status] callback after launching the batch job request against the server.
72
+ # @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server.
73
+ # @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch.
74
+ # @return [Eco::API::Session::Batch::Job]
60
75
  def add(job)
61
76
  fatal "Expected Eco::API::Session::Batch::Job object. Given #{job.class}" unless job.is_a?(Eco::API::Session::Batch::Job)
62
77
  @jobs[job.name] = job
@@ -67,6 +82,10 @@ module Eco
67
82
  any? {|job| job.pending?}
68
83
  end
69
84
 
85
+ # Launches every `Batch::Job` in the group.
86
+ # @note
87
+ # - if there was post-launch callback for a `Batch::Job`, it calls it.
88
+ # @return [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>]
70
89
  def launch(simulate: false)
71
90
  each do |job|
72
91
  if job.pending?
@@ -58,6 +58,11 @@ module Eco
58
58
  @groups.key?(name)
59
59
  end
60
60
 
61
+ # Creates a new group of `Batch::Jobs` named `name`.
62
+ # @yield [group, group_status] callback after launching the batch job request against the server.
63
+ # @yieldparam group [Eco::API::Session::Batch::Jobs] the group of jobs we have launched against the server.
64
+ # @yieldparam group_status [Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>] the status of the launched batch jobs.
65
+ # @return [Eco::API::Session::Batch::Jobs] the group of jobs.
61
66
  def new(name, order: :last)
62
67
  fatal "Can't create job group named '#{name}' because it already exists." if exists?(name)
63
68
 
@@ -78,6 +83,10 @@ module Eco
78
83
  any? {|group| group.pending?}
79
84
  end
80
85
 
86
+ # Launches every `Batch::Jobs` group in the current `Batch::JobGroups`
87
+ # @note
88
+ # - if there was post-launch callback for a `Batch::Jobs` groups, it calls it.
89
+ # @return [Hash<Eco::API::Session::Batch::Jobs,Hash<Eco::API::Session::Batch::Job, Eco::API::Session::Batch::Status>>]
81
90
  def launch(simulate: false)
82
91
  @order.each_with_index do |group, idx|
83
92
  if group.pending?
@@ -4,7 +4,7 @@ class Eco::API::UseCases::DefaultCases::RefreshCase < Eco::API::Common::Loaders:
4
4
 
5
5
  def main(people, session, options, usecase)
6
6
  update = session.new_job("main", "update", :update, usecase)
7
- people.each {|person| job.add(person)}
7
+ people.each {|person| update.add(person)}
8
8
  end
9
9
 
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.5.7"
2
+ VERSION = "1.5.12"
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: 1.5.7
4
+ version: 1.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -116,7 +116,7 @@ dependencies:
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 0.7.3
119
+ version: 0.7.4
120
120
  - - "<"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0.8'
@@ -126,7 +126,7 @@ dependencies:
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- version: 0.7.3
129
+ version: 0.7.4
130
130
  - - "<"
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0.8'
@@ -474,7 +474,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
474
474
  requirements:
475
475
  - - ">="
476
476
  - !ruby/object:Gem::Version
477
- version: '0'
477
+ version: 2.4.4
478
478
  required_rubygems_version: !ruby/object:Gem::Requirement
479
479
  requirements:
480
480
  - - ">="