eco-helpers 1.5.6 → 1.5.11

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: bbc18ef6018f837f7a9b85f51553667710197aa3d47be99a41ecf7167c86d5d5
4
- data.tar.gz: 9b451c907cc1b9386d107fffdcde38cba56a1983b24783bd321e48acc33d43b3
3
+ metadata.gz: 9b9af4f974524b36ddd0fad5316d37281f0a9a2e7dd2f03d2f5febbaef957313
4
+ data.tar.gz: '003906cbfc9389e184b238001997ad1f444355cfbccd9d609f9197445ad3a369'
5
5
  SHA512:
6
- metadata.gz: 3832e2d59233c3ffc1b61e72a84e6823e8f65091362c2a1867e5a62ca136557379c77e7d4bf555b370e8cb7bb6f6898d081780dfb0248976b9421bcfd0396800
7
- data.tar.gz: 132d7db16cf17073736c7bbc57982cf6a85645162ea87a52e58a0f97561ea58c416e40f2b4f7db81da35bc2cc384210c0e753b470c2a1c056b5a87546efd9d99
6
+ metadata.gz: 5f3b5aa580a10398ebcbf99203f2e6fd4951a20d45d2edd8fd9fff2c0e894ed18f8a54d0537fef4e281465fd7ef7326454df3647bf80051348e6c56d3215866e
7
+ data.tar.gz: b53b697f1b07ad41bac8550150d3ab7d9cfe6eb842507e5cc77d8bd3a2dc4a8568621f1f2ba849d44440a42c646c7f844336f43de0db058b798c5cdebd643764
@@ -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
+ ## [1.5.11] - 2021-01-xx
5
+
6
+ ### Added
7
+ - `Eco::API::Organization::TagTree#subtag?` to check if the tag is in any subtree.
8
+
9
+ ### Changed
10
+
11
+ ### Fixed
12
+ - `Eco::API::MicroCases#set_supervisor` shouldn't set it if the entry does not have it.
13
+
14
+ ## [1.5.10] - 2021-01-19
15
+
16
+ ### Added
17
+ ### Changed
18
+ ### Fixed
19
+ - `Eco::API::Session::Batch::Errors#print` show the row number of the input data.
20
+
21
+ ## [1.5.9] - 2021-01-08
22
+
23
+ ### Added
24
+ - `Eco::API::Organization::TagTree#subtags` to get all the tags but those of the highest level.
25
+
26
+ ### Changed
27
+ ### Fixed
28
+
29
+
30
+ ## [1.5.8] - 2021-01-05
31
+
32
+ ### Added
33
+ ### Changed
34
+ ### Fixed
35
+ - `Eco::API::Session::Batch::Jobs#job` shouldn't be calling the post-launch callback function on creation.
36
+ - `Eco::API::Session#new_job` should include a `&block` parameter.
37
+ - `Eco::API::UseCases::DefaultCases::RefreshCase`: fixed typo
38
+
39
+ ## [1.5.7] - 2020-12-17
40
+
41
+ ### Added
42
+ ### Changed
43
+ ### Fixed
44
+ - `Eco::API::Sesssion#parse_attribute` was not using phase argument
45
+
4
46
  ## [1.5.6] - 2020-12-04
5
47
 
6
48
  ### 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)/})
@@ -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]
@@ -126,7 +126,7 @@ module Eco
126
126
  unless parsers = entry_factory.person_parser
127
127
  raise "There are no parsers defined"
128
128
  end
129
- parsers.parse(attr, source)
129
+ parsers.parse(attr, source, phase)
130
130
  end
131
131
 
132
132
  # @see Eco::API::Common::People::EntryFactory#export
@@ -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.6"
2
+ VERSION = "1.5.11"
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.6
4
+ version: 1.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -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
  - - ">="