eco-helpers 3.0.21 → 3.0.23

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 (154) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/.gitignore +10 -0
  3. data/CHANGELOG.md +44 -2
  4. data/eco-helpers.gemspec +5 -3
  5. data/lib/eco/api/common/class_helpers.rb +2 -1
  6. data/lib/eco/api/common/class_hierarchy.rb +6 -9
  7. data/lib/eco/api/common/loaders/case_base.rb +12 -4
  8. data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
  9. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
  10. data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
  11. data/lib/eco/api/common/loaders/error_handler.rb +3 -2
  12. data/lib/eco/api/common/loaders/policy.rb +3 -2
  13. data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
  14. data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
  15. data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
  16. data/lib/eco/api/common/loaders/use_case.rb +16 -43
  17. data/lib/eco/api/error/handler.rb +6 -4
  18. data/lib/eco/api/error/handlers.rb +12 -5
  19. data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
  20. data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
  21. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
  22. data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
  23. data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
  24. data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
  25. data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
  26. data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
  27. data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
  28. data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
  29. data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
  30. data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
  31. data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
  32. data/lib/eco/api/microcases/people/fetch.rb +23 -0
  33. data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
  34. data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
  35. data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
  36. data/lib/eco/api/microcases/people/integrity.rb +17 -0
  37. data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
  38. data/lib/eco/api/microcases/people/macro.rb +13 -0
  39. data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
  40. data/lib/eco/api/microcases/people/manage/load.rb +90 -0
  41. data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
  42. data/lib/eco/api/microcases/people/manage/search.rb +118 -0
  43. data/lib/eco/api/microcases/people/manage.rb +19 -0
  44. data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
  45. data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
  46. data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
  47. data/lib/eco/api/microcases/people/preserve.rb +17 -0
  48. data/lib/eco/api/microcases/people.rb +21 -0
  49. data/lib/eco/api/microcases/person_update.rb +1 -1
  50. data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
  51. data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
  52. data/lib/eco/api/microcases.rb +3 -23
  53. data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
  54. data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
  55. data/lib/eco/api/organization/people.rb +40 -66
  56. data/lib/eco/api/organization.rb +0 -1
  57. data/lib/eco/api/policies/policy.rb +7 -5
  58. data/lib/eco/api/policies.rb +9 -4
  59. data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
  60. data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
  61. data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
  62. data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
  63. data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
  64. data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
  65. data/lib/eco/api/session/batch/feedback.rb +45 -119
  66. data/lib/eco/api/session/batch/job/sets.rb +23 -0
  67. data/lib/eco/api/session/batch/job/type.rb +22 -0
  68. data/lib/eco/api/session/batch/job.rb +8 -18
  69. data/lib/eco/api/session/batch/jobs.rb +6 -2
  70. data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
  71. data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
  72. data/lib/eco/api/session/batch/launcher.rb +2 -2
  73. data/lib/eco/api/session/batch/policies.rb +4 -4
  74. data/lib/eco/api/session/batch/searcher.rb +2 -1
  75. data/lib/eco/api/session/batch.rb +0 -1
  76. data/lib/eco/api/session/config/workflow.rb +19 -9
  77. data/lib/eco/api/usecases/base_case/model.rb +54 -0
  78. data/lib/eco/api/usecases/base_case/type.rb +52 -0
  79. data/lib/eco/api/usecases/base_case.rb +5 -29
  80. data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
  81. data/lib/eco/api/usecases/base_io/validations.rb +114 -0
  82. data/lib/eco/api/usecases/base_io.rb +65 -115
  83. data/lib/eco/api/usecases/cli/dsl.rb +3 -1
  84. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
  85. data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
  86. data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
  87. data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
  88. data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
  89. data/lib/eco/api/usecases/default_cases/samples/sftp.rb +3 -0
  90. data/lib/eco/api/usecases/default_cases/samples.rb +1 -1
  91. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
  92. data/lib/eco/api/usecases/graphql/base.rb +3 -2
  93. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
  94. data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
  95. data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
  96. data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
  97. data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
  98. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
  99. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
  100. data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
  101. data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
  102. data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
  103. data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
  104. data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
  105. data/lib/eco/api/usecases/graphql/samples.rb +1 -0
  106. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
  107. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
  108. data/lib/eco/api/usecases/{default_cases/samples → samples/drivers}/cli/sftp_cli.rb +1 -1
  109. data/lib/eco/api/usecases/samples/drivers/cli/url_pull_cli.rb +15 -0
  110. data/lib/eco/api/usecases/{default_cases/samples/sftp_case.rb → samples/drivers/sftp_sample.rb} +8 -8
  111. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +110 -0
  112. data/lib/eco/api/usecases/samples/drivers.rb +13 -0
  113. data/lib/eco/api/usecases/samples.rb +11 -0
  114. data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
  115. data/lib/eco/api/usecases/use_case.rb +32 -23
  116. data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
  117. data/lib/eco/api/usecases/use_case_chain.rb +17 -62
  118. data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
  119. data/lib/eco/api/usecases/use_case_io.rb +17 -22
  120. data/lib/eco/api/usecases.rb +15 -6
  121. data/lib/eco/assets.rb +1 -1
  122. data/lib/eco/cli/config/filters/people_filters.rb +6 -5
  123. data/lib/eco/cli/config/input.rb +6 -2
  124. data/lib/eco/cli/config/use_cases.rb +4 -2
  125. data/lib/eco/cli_default/people_filters.rb +1 -0
  126. data/lib/eco/cli_default/workflow.rb +149 -138
  127. data/lib/eco/data/mapper.rb +51 -19
  128. data/lib/eco/language/methods/dsl_able.rb +10 -0
  129. data/lib/eco/version.rb +1 -1
  130. metadata +87 -35
  131. data/lib/eco/api/microcases/account_excluded.rb +0 -26
  132. data/lib/eco/api/microcases/core_excluded.rb +0 -20
  133. data/lib/eco/api/microcases/fix_default_group.rb +0 -33
  134. data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
  135. data/lib/eco/api/microcases/people_cache.rb +0 -30
  136. data/lib/eco/api/microcases/people_load.rb +0 -84
  137. data/lib/eco/api/microcases/people_refresh.rb +0 -53
  138. data/lib/eco/api/microcases/people_search.rb +0 -112
  139. data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
  140. data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
  141. data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
  142. data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
  143. data/lib/eco/api/microcases/set_account.rb +0 -18
  144. data/lib/eco/api/microcases/set_core.rb +0 -17
  145. data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
  146. data/lib/eco/api/microcases/set_supervisor.rb +0 -63
  147. data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
  148. data/lib/eco/api/microcases/with_each.rb +0 -103
  149. data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
  150. data/lib/eco/api/microcases/with_each_present.rb +0 -36
  151. data/lib/eco/api/microcases/with_each_starter.rb +0 -37
  152. data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
  153. data/lib/eco/api/microcases/with_supervisor.rb +0 -35
  154. data/lib/eco/api/session/batch/request_stats.rb +0 -266
@@ -1,182 +1,193 @@
1
- ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
2
- ASSETS.config.workflow do |wf| # rubocop:disable Metrics/BlockLength
3
- rescued = false
4
-
5
- # default rescue
6
- wf.rescue do |err, io|
7
- next io if rescued
8
-
9
- rescued = true
10
- log(:debug) { err.patch_full_message }
1
+ class Eco::CliDefault::Workflow < Eco::API::Common::Loaders::Workflow
2
+ # @todo The ones below:
3
+ # 1. Identify the target model earlier (required_data?),
4
+ # provided that we can granulate the workflow.
5
+ # 2. Try to modularize the options check/dig.
6
+ # 3. Review the cli.config.people and see if it can be
7
+ # renamed to cli.config.data and load it based on the
8
+ # target model.
9
+ # 4. Decouple into multiple classes that can be loaded
10
+ # based on the target model. Or either define different
11
+ # workflows that assembly those classes?
12
+ # 5. Right on the load:data stage, set the io model
13
+ # based on (1).
14
+
15
+ class << self
16
+ attr_accessor :rescued
17
+ end
11
18
 
12
- wf.run(:close, io: io)
13
- rescue StandardError => e
14
- puts "Some problem in workflow.rescue: #{e}"
15
- end
19
+ # default rescue
20
+ exception do |err, io|
21
+ next io if rescued
16
22
 
17
- wf.on(:options) do |_wf_opt, io|
18
- cli.config.usecases.cli_apply(io: io)
19
- io.new(options: cli.config.options_set.process(io: io))
20
- end
23
+ self.rescued = true
24
+ log(:debug) { err.patch_full_message }
21
25
 
22
- wf.for(:load) do |wf_load|
23
- wf_load.for(:input) do |wf_in|
24
- wf_in.on(:get) do |_wf_ig, io|
25
- cases_with_input = cli.config.usecases.active(io: io).select do |usecase, _data|
26
- io.class.input_required?(usecase.type)
27
- end
28
-
29
- input_is_required = !cases_with_input.empty? || options.dig(:input, :entries_from)
30
- missing_input = !input || input.empty?
31
- next unless missing_input && input_is_required
32
-
33
- if options.dig(:input, :entries_from)
34
- io.new(input: cli.config.input.get(io: io))
35
- else
36
- opt_case = cases_with_input.values.first.option
37
- io.new(input: cli.config.input.get(io: io, option: opt_case))
38
- end
39
- end
26
+ workflow.run(:close, io: io)
27
+ rescue StandardError => e
28
+ puts "Some problem in workflow.rescue: #{e}"
29
+ end
40
30
 
41
- wf_in.on(:filter) do |_wf_if, io|
42
- next unless input && !input.empty?
31
+ on(:options) do
32
+ cli_usecases.cli_apply(io: io)
33
+ io.new(options: cli.config.options_set.process(io: io))
34
+ end
43
35
 
44
- io.new(input: cli.config.input_filters.process(io: io))
36
+ with(:load) do |wf_load|
37
+ wf_load.with(:input) do |wf_in|
38
+ wf_in.on(:get) do
39
+ input_is_required = some_input_case?(io) || options.dig(:input, :entries_from)
40
+ missing_input = !input || input.empty?
41
+ next unless missing_input && input_is_required
42
+
43
+ if options.dig(:input, :entries_from)
44
+ io.new(input: cli.config.input.get(io: io))
45
+ else
46
+ opt_case = cli_input_cases(io).values.first.option
47
+ io.new(input: cli.config.input.get(io: io, option: opt_case))
45
48
  end
46
49
  end
47
50
 
48
- wf_load.for(:people) do |wf_peo|
49
- wf_peo.on(:get) do |_wf_pg, io|
50
- cases_with_people = cli.config.usecases.active(io: io).select do |usecase, _data|
51
- io.class.people_required?(usecase.type)
52
- end
51
+ wf_in.on(:filter) do
52
+ next unless input && !input.empty?
53
53
 
54
- next if cases_with_people.empty? && !options.dig(:people, :get)
54
+ io.new(input: cli.config.input_filters.process(io: io))
55
+ end
56
+ end
55
57
 
56
- io.new(people: cli.config.people(io: io))
57
- end
58
+ wf_load.before(:data) do
59
+ # @todo model should be set to the target model
60
+ # based on the main use case that requires data!
61
+ io.new(model: :people)
62
+ end
58
63
 
59
- wf_peo.on(:filter) do |_wf_pf, io|
60
- next unless people && !people.empty?
64
+ wf_load.with(:data) do |wf_peo|
65
+ wf_peo.on(:get) do
66
+ next unless some_data_case?(io) || options.dig(:people, :get)
61
67
 
62
- io.new(people: cli.config.people_filters.process(io: io))
63
- end
68
+ io.new(data: cli.config.people(io: io))
64
69
  end
65
- end
66
70
 
67
- wf.before(:usecases) do |_wf_ca, io|
68
- # save partial entries -> should be native to session.workflow
69
- get_people = options.dig(:people, :get)
70
- partial_update = get_people && get_people[:type] == :partial
71
+ wf_peo.on(:filter) do
72
+ next unless data && !data.empty?
71
73
 
72
- if !options[:dry_run] && partial_update
73
- partial_file = session.config.people.partial_cache
74
- session.file_manager.save_json(io.people, partial_file, :timestamp)
74
+ io.new(data: cli.config.people_filters.process(io: io))
75
75
  end
76
76
  end
77
+ end
77
78
 
78
- wf.on(:usecases) do |_wf_ca, io|
79
- next if cli.config.usecases.process(io: io)
79
+ before(:usecases) do
80
+ # save partial entries -> should be native to session.workflow
81
+ get_people = options.dig(:people, :get)
82
+ partial_update = get_people && get_people[:type] == :partial
80
83
 
81
- log(:info) { "No update operation specified... quitting" }
82
- exit 0
84
+ if !options[:dry_run] && partial_update
85
+ partial_file = session.config.people.partial_cache
86
+ session.file_manager.save_json(io.data, partial_file, :timestamp)
83
87
  end
88
+ end
84
89
 
85
- wf.before(:launch_jobs) do |_wf_jobs, _io|
86
- available_args = cli.config.available_option_args
87
- SCR.stop_on_unknown!(all_available: available_args)
88
- end
90
+ on(:usecases) do
91
+ next if cli_usecases.process(io: io)
89
92
 
90
- wf.on(:launch_jobs) do
91
- session.jobs_launch(simulate: options[:dry_run])
92
- end
93
+ log(:info) { "No update operation specified... quitting" }
94
+ exit 0
95
+ end
93
96
 
94
- wf.before(:post_launch) do |wf_post, io|
95
- next wf_post.skip! if session.post_launch.empty?
97
+ before(:launch_jobs) do
98
+ available_args = cli.config.available_option_args
99
+ SCR.stop_on_unknown!(all_available: available_args)
100
+ end
96
101
 
97
- run_it = !options[:dry_run] || options.dig(:post_launch, :run)
98
- unless run_it
99
- wf_post.skip!
102
+ on(:launch_jobs) do
103
+ session.jobs_launch(simulate: options[:dry_run])
104
+ end
100
105
 
101
- log(:info) {
102
- msg = "Although there are post_launch cases, they will NOT be RUN"
103
- msg << ", because we are in dry-run (simulate)." if options[:dry_run]
104
- msg
105
- }
106
+ before(:post_launch) do |wf_post|
107
+ next wf_post.skip! if session.post_launch.empty?
106
108
 
107
- next
108
- end
109
+ run_it = !options[:dry_run] || options.dig(:post_launch, :run)
110
+ unless run_it
111
+ wf_post.skip!
109
112
 
110
- get_people = options.dig(:people, :get)
111
- partial_update = get_people && get_people[:type] == :partial
112
- refresh_data = !options[:dry_run] && partial_update
113
+ log(:info) {
114
+ msg = "Although there are post_launch cases, they will NOT be RUN"
115
+ msg << ", because we are in dry-run (simulate)." if options[:dry_run]
116
+ msg
117
+ }
113
118
 
114
- unless refresh_data
115
- log(:info) {
116
- msg = "Although there are post_launch cases, data will not be refreshed before their run"
117
- if io.options[:dry_run]
118
- msg << ", because we are in dry-run (simulate)."
119
- elsif !partial_update
120
- msg << ", because it is not a partial update (-get-partial option not present)."
121
- end
122
- msg
123
- }
119
+ next
120
+ end
124
121
 
125
- next
126
- end
122
+ get_people = options.dig(:people, :get)
123
+ partial_update = get_people && get_people[:type] == :partial
124
+ refresh_data = !options[:dry_run] && partial_update
125
+
126
+ unless refresh_data
127
+ log(:info) {
128
+ msg = "Although there are post_launch cases, data will not be refreshed before their run"
129
+ if io.options[:dry_run]
130
+ msg << ", because we are in dry-run (simulate)."
131
+ elsif !partial_update
132
+ msg << ", because it is not a partial update (-get-partial option not present)."
133
+ end
134
+ msg
135
+ }
127
136
 
128
- # get target people afresh
129
- peo_aux = session.micro.people_refresh(people: people, include_created: true)
130
- io.base.new(people: peo_aux)
137
+ next
131
138
  end
132
139
 
133
- wf.for(:post_launch) do |wf_post|
134
- wf_post.on(:usecases) do |_wf_pu, io|
135
- session.post_launch.each do |use|
136
- use.launch(io: io).base
137
- rescue Eco::API::UseCases::BaseIO::MissingParameter => e
138
- raise unless e.required == :people
140
+ # get target people afresh
141
+ peo_aux = session.micro.people_refresh(
142
+ people: data,
143
+ include_created: true
144
+ )
145
+ io.base.new(data: peo_aux)
146
+ end
139
147
 
140
- log(:debug) {
141
- "Skipping use case '#{use.name}' -- no base people detected for the current run"
142
- }
143
- end
144
- end
148
+ with(:post_launch) do |wf_post|
149
+ wf_post.on(:usecases) do |_wf_pu, io|
150
+ session.post_launch.each do |use|
151
+ use.launch(io: io).base
152
+ rescue Eco::API::UseCases::BaseIO::MissingParameter => err
153
+ raise unless err.required == :people
145
154
 
146
- wf_post.on(:launch_jobs) do |_wf_pl, _io|
147
- session.jobs_launch(simulate: options[:dry_run])
155
+ log(:debug) {
156
+ "Skipping use case '#{use.name}' -- no base people detected for the current run"
157
+ }
148
158
  end
149
159
  end
150
160
 
151
- wf.on(:report) do |_wf_rep, io|
152
- if (file = options.dig(:report, :people, :csv))
153
- options.deep_merge!(export: {
154
- options: {internal_names: true, nice_header: true, split_schemas: true},
155
- file: {name: file, format: :csv}
156
- })
157
- aux_io = io.new(people: people.updated_or_created)
158
- session.process_case("to-csv", io: aux_io, type: :export)
159
- end
161
+ wf_post.on(:launch_jobs) do |_wf_pl, _io|
162
+ session.jobs_launch(simulate: options[:dry_run])
160
163
  end
164
+ end
161
165
 
162
- wf.on(:end) do |_wf_end, io|
163
- get_people = options.dig(:people, :get)
164
- partial_update = get_people && get_people[:type] == :partial
166
+ on(:report) do |_wf_rep, io|
167
+ if (file = options.dig(:report, :people, :csv))
168
+ options.deep_merge!(export: {
169
+ options: {internal_names: true, nice_header: true, split_schemas: true},
170
+ file: {name: file, format: :csv}
171
+ })
165
172
 
166
- unless !options[:end_get] || options[:dry_run] || partial_update
167
- people_update_cases = cli.config.usecases.active(io: io).any? do |usecase, _data|
168
- %i[transform sync].any? { |type| usecase.type == type }
169
- end
173
+ aux_io = io.new(data: data.updated_or_created)
174
+ session.process_case('to-csv', io: aux_io, type: :export)
175
+ end
176
+ end
170
177
 
171
- if !people_update_cases
172
- # Prevent getting people when there were no use cases that used them
173
- log(:info) {
174
- "Won't be recaching people, as there haven't been any targetted updates"
175
- }
176
- elsif !people
177
- people = session.micro.people_cache
178
- io.new(people: people)
179
- end
178
+ on(:end) do
179
+ get_people = options.dig(:people, :get)
180
+ partial_update = get_people && get_people[:type] == :partial
181
+
182
+ unless !options[:end_get] || options[:dry_run] || partial_update
183
+ if !some_update_case?(io)
184
+ # Prevent getting people when there were no use cases that used them
185
+ log(:info) {
186
+ "Won't be recaching people, as there haven't been any targetted updates"
187
+ }
188
+ elsif !people
189
+ people = session.micro.people_cache
190
+ io.new(data: people)
180
191
  end
181
192
  end
182
193
  end
@@ -1,24 +1,43 @@
1
1
  module Eco
2
2
  module Data
3
3
  class Mapper
4
-
5
4
  # it expects [[v1a, v1b], [v2a, v2b] ...]
6
- def initialize (array_of_arrays = [], internal: :last)
5
+ def initialize (array_of_arrays = [], internal: :last, insensitive: false)
7
6
  @internal_order = internal
8
7
  @source = array_of_arrays
8
+ @insensitive = insensitive
9
+
10
+ return unless @source
11
+
12
+ # internal should be always last in @source
13
+ @source = @source.map(&:reverse) unless internal == :last
14
+
15
+ # first declarations take priority
16
+ @by_external = @source.reverse.to_h.tap do |h_data|
17
+ next unless insensitive?
18
+
19
+ h_data.dup.each do |key, value|
20
+ next if h_data.key?(key.downcase)
9
21
 
10
- if @source
11
- # internal should be always last in @source
12
- @source = @source.map { |a| a.reverse } unless internal == :last
22
+ h_data[key.downcase] = value
23
+ end
24
+ end
25
+
26
+ @by_internal = @source.reverse.map(&:reverse).to_h.tap do |h_data|
27
+ next unless insensitive?
28
+
29
+ h_data.dup.each do |key, value|
30
+ next if h_data.key?(key.downcase)
13
31
 
14
- # first declarations take priority
15
- @by_external = @source.reverse.to_h
16
- @by_internal = @source.reverse.map do |pair|
17
- pair.reverse
18
- end.to_h
32
+ h_data[key.downcase] = value
33
+ end
19
34
  end
20
35
  end
21
36
 
37
+ def insensitive?
38
+ @insensitive
39
+ end
40
+
22
41
  def as_json(internal: @internal_order)
23
42
  to_a(internal: internal)
24
43
  end
@@ -27,13 +46,15 @@ module Eco
27
46
  content = as_json(internal: internal).map do |pair|
28
47
  " " + pair.to_json
29
48
  end.join(",\n")
49
+
30
50
  "[\n#{content}\n]"
31
51
  end
32
52
 
33
53
  def to_a(internal: @internal_order)
34
- @by_internal.map do |int, ext|
35
- internal == :last ? [ext, int] : [int, ext]
36
- end
54
+ src_dup = @source.map {|pair| pair[0..]}
55
+ return src_dup if internal == :last
56
+
57
+ src_dup.map(&:reverse)
37
58
  end
38
59
 
39
60
  def +(array_of_arrays)
@@ -41,40 +62,51 @@ module Eco
41
62
  end
42
63
 
43
64
  def list(type = :internal)
44
- return [] if !@source
65
+ return [] unless @source
66
+
45
67
  @source.map do |pair|
46
68
  type == :internal ? pair.last : pair.first
47
69
  end.uniq
48
70
  end
49
71
 
50
72
  def internal?(value)
51
- return true if !@source
73
+ return true unless @source
74
+
75
+ value = value.downcase if insensitive?
52
76
  @by_internal.key?(value)
53
77
  end
54
78
 
55
79
  def external?(value)
56
- return true if !@source
80
+ return true unless @source
81
+
82
+ value = value.downcase if insensitive?
57
83
  @by_external.key?(value)
58
84
  end
59
85
 
60
86
  def include?(value)
61
- return true if !@source
87
+ return true unless @source
88
+
62
89
  internal?(value) || external?(value)
63
90
  end
64
91
 
65
92
  # Whether `value` maps to itself
66
93
  def self_mapped?(value)
67
94
  return false unless include?(value)
95
+
68
96
  value == to_internal(value)
69
97
  end
70
98
 
71
99
  def to_internal(value)
72
- return value if !@source
100
+ return value unless @source
101
+
102
+ value = value.downcase if insensitive?
73
103
  @by_external[value]
74
104
  end
75
105
 
76
106
  def to_external(value)
77
- return value if !@source
107
+ return value unless @source
108
+
109
+ value = value.downcase if insensitive?
78
110
  @by_internal[value]
79
111
  end
80
112
  end
@@ -1,13 +1,22 @@
1
1
  module Eco
2
2
  module Language
3
3
  module Methods
4
+ # Adds #evaluate, which will run `&block` where `DslAble` has been included.
5
+ # @note
6
+ # 1. If a method is missing on the evaluation object, it will re-try it on
7
+ # on the block context.
8
+ # 2. **Override behaviour**: the above gives precedence to
9
+ # methods defined in the context of the object that evaluates,
10
+ # over those in the block context.
4
11
  module DslAble
5
12
  # It runs the `block` within this object context
6
13
  # @note if the object misses any method, redirects the method to the
7
14
  # original evaluate caller.
8
15
  def evaluate(*args, **kargs, &block)
9
16
  return unless block_given?
17
+
10
18
  @self_before_evaluate = eval('self', block.binding, __FILE__, __LINE__)
19
+
11
20
  instance_exec(*args, **kargs, &block).tap do
12
21
  @self_before_evaluate = nil
13
22
  end
@@ -17,6 +26,7 @@ module Eco
17
26
  # @see https://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
18
27
  def method_missing(method, *args, **kargs, &block)
19
28
  super unless @self_before_evaluate
29
+
20
30
  @self_before_evaluate.send(method, *args, **kargs, &block)
21
31
  end
22
32
 
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = '3.0.21'.freeze
2
+ VERSION = '3.0.23'.freeze
3
3
  end