eco-helpers 2.0.22 → 2.0.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +95 -5
  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 +42 -9
  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 +44 -7
  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
@@ -65,8 +65,8 @@ ASSETS.cli.config do |cnf|
65
65
  input = [file].flatten.reduce(Eco::API::Organization::People.new([])) do |people, file|
66
66
  people.merge(JSON.parse(File.read(file)))
67
67
  end
68
- else
69
- input = session.csv_entries(file)
68
+ else # :csv
69
+ input = session.csv_entries(file, check_headers: true)
70
70
  end
71
71
  end
72
72
  input
@@ -1,19 +1,35 @@
1
1
  ASSETS.cli.config do |cnf|
2
2
  cnf.options_set do |options_set, options|
3
3
  options_set.add("--help", "Offers a HELP") do |options, sesssion|
4
- conf = ASSETS.cli.config
5
- puts conf.people_filters.help if hpf = SCR.get_arg("-filters")
6
- puts conf.input_filters.help if hif = SCR.get_arg("-input-filters")
7
- puts conf.options_set.help if ho = SCR.get_arg("-options")
8
- puts conf.usecases.help if huc = SCR.get_arg("-usecases")
4
+ conf = ASSETS.cli.config
5
+ active = Proc.new do |opt|
6
+ if there = SCR.get_arg(opt)
7
+ refine = SCR.get_arg(opt, with_param: true)
8
+ end
9
+ refine || there
10
+ end
11
+
12
+ if hpf = active.call("-filters")
13
+ puts conf.people_filters.help(refine: hpf)
14
+ end
15
+ if hif = active.call("-input-filters")
16
+ puts conf.input_filters.help(refine: hif)
17
+ end
18
+ if ho = active.call("-options")
19
+ puts conf.options_set.help(refine: ho)
20
+ end
21
+ if huc = active.call("-usecases")
22
+ puts conf.usecases.help(refine: huc)
23
+ end
9
24
  puts [
10
25
  "Please specify one of the below:",
11
26
  " -filters to display available filters on people",
12
27
  " -input-filters to display available filters on input data",
13
28
  " -options to dislpay available options",
14
29
  " -usecases to display available usecases",
15
- "",
16
- "You may specify the usecase to know its specific options by: -usecase_name --help -options"
30
+ "TIPS:",
31
+ " * You may specify the usecase to know its specific options by: -usecase_name --help -options",
32
+ " * You may specify a refinement to show specific information only: --help -usecases tags"
17
33
  ].join("\n") unless hpf || hif || ho || huc
18
34
  exit
19
35
  end
@@ -66,6 +82,11 @@ ASSETS.cli.config do |cnf|
66
82
  })
67
83
  end
68
84
 
85
+ desc = "Saves the requests's body even though running in dry-run (-simulate)"
86
+ options_set.add("-save-requests", desc) do |options, session|
87
+ options.deep_merge!(requests: {backup: true})
88
+ end
89
+
69
90
  desc = "Used to specify the cache file of people to be used. "
70
91
  desc += "It is useful to use as people reference those stored in cached file diffrent to the last one."
71
92
  options_set.add("-people-from-backup", desc) do |options, session|
@@ -82,6 +103,22 @@ ASSETS.cli.config do |cnf|
82
103
  session.config.dry_run!
83
104
  end
84
105
 
106
+ desc = "Runs runs post_launch cases even if in dry-run"
107
+ options_set.add("-run-postlaunch", desc) do |options, session|
108
+ options.deep_merge!(post_launch: {run: true})
109
+ end
110
+
111
+ desc = "(careful with this option) This will include everybody as part of the update (including those that are api excluded). "
112
+ desc += "Only launch with this option when only api excluded people are included in your update."
113
+ options_set.add("-include-excluded", desc) do |options|
114
+ options.deep_merge!(include: {excluded: true})
115
+ end
116
+
117
+ desc = "Includes in API updates ONLY people that evaluate true as people excluded from periodic upates."
118
+ options_set.add("-include-only-excluded", desc) do |options|
119
+ options.deep_merge!(include: {excluded: {only: true}})
120
+ end
121
+
85
122
  desc = "Ignores threshold limitations on requests for this session (skip batch belt)"
86
123
  options_set.add("-skip-batch-policy", desc) do |options|
87
124
  options.deep_merge!(skip: {batch_policy: true})
@@ -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.22"
2
+ VERSION = "2.0.27"
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.22
4
+ version: 2.0.27
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