eco-helpers 2.0.24 → 2.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -6
  3. data/lib/eco/api/common.rb +0 -1
  4. data/lib/eco/api/common/loaders.rb +2 -0
  5. data/lib/eco/api/common/loaders/base.rb +58 -0
  6. data/lib/eco/api/common/loaders/case_base.rb +33 -0
  7. data/lib/eco/api/common/loaders/error_handler.rb +2 -2
  8. data/lib/eco/api/common/loaders/parser.rb +30 -5
  9. data/lib/eco/api/common/loaders/policy.rb +1 -1
  10. data/lib/eco/api/common/loaders/use_case.rb +1 -1
  11. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +129 -1
  12. data/lib/eco/api/common/people/entries.rb +83 -14
  13. data/lib/eco/api/common/people/entry_factory.rb +11 -10
  14. data/lib/eco/api/common/people/person_attribute_parser.rb +8 -0
  15. data/lib/eco/api/common/people/person_entry.rb +7 -6
  16. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +55 -16
  17. data/lib/eco/api/common/people/person_factory.rb +4 -2
  18. data/lib/eco/api/common/people/person_parser.rb +7 -1
  19. data/lib/eco/api/common/people/supervisor_helpers.rb +1 -1
  20. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +0 -8
  21. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +0 -8
  22. data/lib/eco/api/microcases/set_core_with_supervisor.rb +4 -2
  23. data/lib/eco/api/microcases/set_supervisor.rb +29 -8
  24. data/lib/eco/api/microcases/with_each.rb +7 -3
  25. data/lib/eco/api/microcases/with_each_starter.rb +3 -2
  26. data/lib/eco/api/organization/people.rb +7 -1
  27. data/lib/eco/api/session.rb +7 -2
  28. data/lib/eco/api/session/batch.rb +1 -1
  29. data/lib/eco/api/session/batch/job.rb +9 -1
  30. data/lib/eco/api/usecases/default_cases/create_case.rb +10 -1
  31. data/lib/eco/api/usecases/default_cases/create_details_case.rb +10 -1
  32. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +10 -1
  33. data/lib/eco/api/usecases/default_cases/hris_case.rb +25 -1
  34. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +1 -37
  35. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +42 -0
  36. data/lib/eco/api/usecases/default_cases/upsert_case.rb +10 -1
  37. data/lib/eco/cli/config/default/input.rb +2 -2
  38. data/lib/eco/cli/config/default/options.rb +29 -8
  39. data/lib/eco/cli/config/default/usecases.rb +16 -0
  40. data/lib/eco/cli/config/default/workflow.rb +7 -4
  41. data/lib/eco/cli/config/filters.rb +6 -2
  42. data/lib/eco/cli/config/filters/input_filters.rb +3 -2
  43. data/lib/eco/cli/config/filters/people_filters.rb +3 -2
  44. data/lib/eco/cli/config/help.rb +1 -1
  45. data/lib/eco/cli/config/options_set.rb +6 -4
  46. data/lib/eco/cli/config/use_cases.rb +6 -3
  47. data/lib/eco/csv.rb +2 -0
  48. data/lib/eco/language/models/collection.rb +5 -2
  49. data/lib/eco/version.rb +1 -1
  50. metadata +3 -2
  51. data/lib/eco/api/common/base_loader.rb +0 -72
@@ -190,9 +190,18 @@ ASSETS.cli.config do |cnf|
190
190
  cases.add("-set-default-tag", :transform, desc, case_name: "set-default-tag")
191
191
 
192
192
  desc = "Creates people with with details and account"
193
+ as1 = "During the run, if new people is created, they are included in the People object of the current session."
194
+ as1 << " This makes them available to find them (i.e. via 'external-id') before they exist"
193
195
  cases.add("-create-from", :sync, desc, case_name: "create")
196
+ .add_option("-append-starters", as1) do |options|
197
+ options.deep_merge!(people: {append_created: true})
198
+ end
199
+
194
200
  desc = "Creates people with only details"
195
201
  cases.add("-create-details-from", :sync, desc, case_name: "create-details")
202
+ .add_option("-append-starters", as1) do |options|
203
+ options.deep_merge!(people: {append_created: true})
204
+ end
196
205
 
197
206
  desc = "It just adds everybody to an update job without doing any change. If the org has policies, it will refresh"
198
207
  cases.add("-refresh", :transform, desc, case_name: "refresh")
@@ -213,7 +222,14 @@ ASSETS.cli.config do |cnf|
213
222
 
214
223
  desc = "Tries to find the input entries and update them. It creates them if not found"
215
224
  cases.add("-upsert-from", :sync, desc, case_name: "upsert")
225
+ .add_option("-append-starters", as1) do |options|
226
+ options.deep_merge!(people: {append_created: true})
227
+ end
228
+
216
229
  desc = "It does like -upsert-from and additionally removes account and supervisor of those in people that are not in the entries (leavers)"
217
230
  cases.add("-hris-from", :sync, desc, case_name: "hris")
231
+ .add_option("-append-starters", as1) do |options|
232
+ options.deep_merge!(people: {append_created: true})
233
+ end
218
234
  end
219
235
  end
@@ -100,10 +100,13 @@ ASSETS.cli.config do |config|
100
100
  else
101
101
  get_people = io.options.dig(:people, :get)
102
102
  partial_update = get_people && get_people.dig(:type) == :partial
103
- if !io.options[:dry_run] && partial_update
104
- # get target people afresh
105
- people = io.session.micro.people_refresh(people: io.people, include_created: true)
106
- io = io.base.new(people: people)
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]
106
+ # get target people afresh
107
+ people = io.session.micro.people_refresh(people: io.people, include_created: true)
108
+ io = io.base.new(people: people)
109
+ end
107
110
  else
108
111
  wf_post.skip!
109
112
  msg = "Although there are post_launch cases, they will NOT be RUN"
@@ -12,10 +12,14 @@ module Eco
12
12
  end
13
13
 
14
14
  # @return [String] summary of the filters.
15
- def help(msg = "The following are the available filters:")
15
+ def help(msg = nil, refine: nil)
16
+ refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
17
+ msg ||= "The following are the available filters#{refinement}:"
16
18
  [msg].yield_self do |lines|
17
19
  max_len = keys_max_len(@filters.keys)
18
- @filters.keys.sort.each do |key|
20
+ @filters.keys.sort.select do |key|
21
+ !refine.is_a?(String) || key.include?(refine)
22
+ end.each do |key|
19
23
  lines << help_line(key, @description[key], max_len)
20
24
  end
21
25
  lines
@@ -4,8 +4,9 @@ module Eco
4
4
  class Filters
5
5
  class InputFilters < Eco::CLI::Config::Filters
6
6
 
7
- def help
8
- super("The following are the available filters on the input entries:")
7
+ def help(refine: nil)
8
+ refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
9
+ super("The following are the available filters on the input entries#{refinement}:", refine: refine)
9
10
  end
10
11
 
11
12
  def process(io:)
@@ -4,8 +4,9 @@ module Eco
4
4
  class Filters
5
5
  class PeopleFilters < Eco::CLI::Config::Filters
6
6
 
7
- def help
8
- super("The following are the available filters on people:")
7
+ def help(refine: nil)
8
+ refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
9
+ super("The following are the available filters on people#{refinement}:", refine: refine)
9
10
  end
10
11
 
11
12
  def process(io:)
@@ -3,7 +3,7 @@ module Eco
3
3
  class Config
4
4
  module Help
5
5
 
6
- def help
6
+ def help(*args)
7
7
  raise "this needs to be reimplemented in the child class and return a string"
8
8
  end
9
9
 
@@ -14,17 +14,19 @@ module Eco
14
14
  end
15
15
 
16
16
  # @return [String] summary of the options.
17
- def help
17
+ def help(refine: nil)
18
18
  indent = 2
19
19
  spaces = any_non_general_space_active? ? active_namespaces : namespaces
20
-
21
- ["The following are the available options:"].yield_self do |lines|
20
+ refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
21
+ ["The following are the available options#{refinement}:"].yield_self do |lines|
22
22
  max_len = keys_max_len(options_args(spaces)) + indent
23
23
  spaces.each do |namespace|
24
24
  is_general = (namespace == :general)
25
25
  str_indent = is_general ? "" : " " * indent
26
26
  lines << help_line(namespace, "", max_len) unless is_general
27
- options_set(namespace).each do |arg, option|
27
+ options_set(namespace).select do |arg, option|
28
+ !refine.is_a?(String) || option.name.include?(refine)
29
+ end.each do |arg, option|
28
30
  lines << help_line(" " * indent + "#{option.name}", option.description, max_len)
29
31
  end
30
32
  end
@@ -29,10 +29,13 @@ module Eco
29
29
  end
30
30
 
31
31
  # @return [String] summary of the use cases.
32
- def help
33
- ["The following are the available use cases:"].yield_self do |lines|
32
+ def help(refine: nil)
33
+ refinement = refine.is_a?(String)? " (containing: '#{refine}')" : ""
34
+ ["The following are the available use cases#{refinement}:"].yield_self do |lines|
34
35
  max_len = keys_max_len(@linked_cases.keys)
35
- @linked_cases.keys.sort.each do |option_case|
36
+ @linked_cases.keys.sort.select do |key|
37
+ !refine.is_a?(String) || key.include?(refine)
38
+ end.each do |option_case|
36
39
  lines << help_line(option_case, @linked_cases[option_case].description, max_len)
37
40
  end
38
41
  lines
data/lib/eco/csv.rb CHANGED
@@ -5,6 +5,7 @@ module Eco
5
5
 
6
6
  class << self
7
7
 
8
+ # @return [Eco::CSV::Table]
8
9
  def parse(data, **kargs, &block)
9
10
  kargs = {headers: true, skip_blanks: true}.merge(kargs)
10
11
  out = super(data, **kargs, &block).reject do |row|
@@ -14,6 +15,7 @@ module Eco
14
15
  Eco::CSV::Table.new(out)
15
16
  end
16
17
 
18
+ # @return [Eco::CSV::Table]
17
19
  def read(file, **kargs)
18
20
  kargs = {headers: true, skip_blanks: true}.merge(kargs)
19
21
 
@@ -134,8 +134,11 @@ module Eco
134
134
  to_a.group_by(&block) if block
135
135
  end
136
136
 
137
- def to_h(attr)
138
- return {} if !attr
137
+ # By a specific `attr` or a block
138
+ # @note either one or the other should be present
139
+ def to_h(attr, &block)
140
+ return to_a.group_by(&block) if block
141
+ raise "And attr or a block are required. Given attr: #{attr}" unless attr
139
142
  to_a.group_by { |object| object.method(attr).call }
140
143
  end
141
144
  # @!endgroup
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.24"
2
+ VERSION = "2.0.29"
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.24
4
+ version: 2.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -369,12 +369,13 @@ files:
369
369
  - lib/eco-helpers.rb
370
370
  - lib/eco/api.rb
371
371
  - lib/eco/api/common.rb
372
- - lib/eco/api/common/base_loader.rb
373
372
  - lib/eco/api/common/class_auto_loader.rb
374
373
  - lib/eco/api/common/class_helpers.rb
375
374
  - lib/eco/api/common/class_hierarchy.rb
376
375
  - lib/eco/api/common/class_meta_basics.rb
377
376
  - lib/eco/api/common/loaders.rb
377
+ - lib/eco/api/common/loaders/base.rb
378
+ - lib/eco/api/common/loaders/case_base.rb
378
379
  - lib/eco/api/common/loaders/error_handler.rb
379
380
  - lib/eco/api/common/loaders/parser.rb
380
381
  - lib/eco/api/common/loaders/policy.rb
@@ -1,72 +0,0 @@
1
- module Eco
2
- module API
3
- module Common
4
- class BaseLoader
5
- extend Eco::API::Common::ClassHelpers
6
-
7
- class << self
8
- attr_writer :name, :type
9
-
10
- # The name that this case, policy or error handler will have.
11
- def name(value = nil)
12
- name_only_once! if value
13
- set_created_at!
14
- return @name ||= self.to_s unless value
15
- @name = value
16
- end
17
-
18
- # Sort order
19
- def <=>(other)
20
- created_at <=> other.created_at
21
- end
22
-
23
- # If still not set, it sets the `created_at` class timestamp.
24
- def set_created_at!
25
- @created_at = Time.now unless @created_at
26
- end
27
-
28
- # Class creation timestamp, to be able to load them in the order they were declared.
29
- def created_at
30
- @created_at ||= Time.now
31
- end
32
-
33
- # Prevent the same class to be re-opened/re-named
34
- def name_only_once!
35
- raise "You have already declared #{self} or you are trying to give it a name twice" if @name
36
- end
37
-
38
- end
39
-
40
- # This method will be called when the BaseLoader is created
41
- # @note
42
- # - this method should implement the loading logics for the given `Children` class.
43
- def initialize
44
- raise "You should implement this method"
45
- end
46
-
47
- def name
48
- self.class.name
49
- end
50
-
51
- private
52
-
53
- def session
54
- ASSETS.session
55
- end
56
-
57
- def config
58
- session.config
59
- end
60
-
61
- def logger
62
- session.logger
63
- end
64
-
65
- def micro
66
- session.micro
67
- end
68
-
69
- end
70
- end
71
- end
72
- end