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.
- checksums.yaml +4 -4
- data/.idea/.gitignore +10 -0
- data/CHANGELOG.md +44 -2
- data/eco-helpers.gemspec +5 -3
- data/lib/eco/api/common/class_helpers.rb +2 -1
- data/lib/eco/api/common/class_hierarchy.rb +6 -9
- data/lib/eco/api/common/loaders/case_base.rb +12 -4
- data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
- data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
- data/lib/eco/api/common/loaders/error_handler.rb +3 -2
- data/lib/eco/api/common/loaders/policy.rb +3 -2
- data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
- data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
- data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
- data/lib/eco/api/common/loaders/use_case.rb +16 -43
- data/lib/eco/api/error/handler.rb +6 -4
- data/lib/eco/api/error/handlers.rb +12 -5
- data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
- data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
- data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
- data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
- data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
- data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
- data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
- data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
- data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
- data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
- data/lib/eco/api/microcases/people/fetch.rb +23 -0
- data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
- data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
- data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
- data/lib/eco/api/microcases/people/integrity.rb +17 -0
- data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
- data/lib/eco/api/microcases/people/macro.rb +13 -0
- data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
- data/lib/eco/api/microcases/people/manage/load.rb +90 -0
- data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
- data/lib/eco/api/microcases/people/manage/search.rb +118 -0
- data/lib/eco/api/microcases/people/manage.rb +19 -0
- data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
- data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
- data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
- data/lib/eco/api/microcases/people/preserve.rb +17 -0
- data/lib/eco/api/microcases/people.rb +21 -0
- data/lib/eco/api/microcases/person_update.rb +1 -1
- data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
- data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
- data/lib/eco/api/microcases.rb +3 -23
- data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
- data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
- data/lib/eco/api/organization/people.rb +40 -66
- data/lib/eco/api/organization.rb +0 -1
- data/lib/eco/api/policies/policy.rb +7 -5
- data/lib/eco/api/policies.rb +9 -4
- data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
- data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
- data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
- data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
- data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
- data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
- data/lib/eco/api/session/batch/feedback.rb +45 -119
- data/lib/eco/api/session/batch/job/sets.rb +23 -0
- data/lib/eco/api/session/batch/job/type.rb +22 -0
- data/lib/eco/api/session/batch/job.rb +8 -18
- data/lib/eco/api/session/batch/jobs.rb +6 -2
- data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
- data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
- data/lib/eco/api/session/batch/launcher.rb +2 -2
- data/lib/eco/api/session/batch/policies.rb +4 -4
- data/lib/eco/api/session/batch/searcher.rb +2 -1
- data/lib/eco/api/session/batch.rb +0 -1
- data/lib/eco/api/session/config/workflow.rb +19 -9
- data/lib/eco/api/usecases/base_case/model.rb +54 -0
- data/lib/eco/api/usecases/base_case/type.rb +52 -0
- data/lib/eco/api/usecases/base_case.rb +5 -29
- data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
- data/lib/eco/api/usecases/base_io/validations.rb +114 -0
- data/lib/eco/api/usecases/base_io.rb +65 -115
- data/lib/eco/api/usecases/cli/dsl.rb +3 -1
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
- data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/samples/sftp.rb +3 -0
- data/lib/eco/api/usecases/default_cases/samples.rb +1 -1
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
- data/lib/eco/api/usecases/graphql/base.rb +3 -2
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
- data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
- data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
- data/lib/eco/api/usecases/{default_cases/samples → samples/drivers}/cli/sftp_cli.rb +1 -1
- data/lib/eco/api/usecases/samples/drivers/cli/url_pull_cli.rb +15 -0
- data/lib/eco/api/usecases/{default_cases/samples/sftp_case.rb → samples/drivers/sftp_sample.rb} +8 -8
- data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +110 -0
- data/lib/eco/api/usecases/samples/drivers.rb +13 -0
- data/lib/eco/api/usecases/samples.rb +11 -0
- data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
- data/lib/eco/api/usecases/use_case.rb +32 -23
- data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
- data/lib/eco/api/usecases/use_case_chain.rb +17 -62
- data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
- data/lib/eco/api/usecases/use_case_io.rb +17 -22
- data/lib/eco/api/usecases.rb +15 -6
- data/lib/eco/assets.rb +1 -1
- data/lib/eco/cli/config/filters/people_filters.rb +6 -5
- data/lib/eco/cli/config/input.rb +6 -2
- data/lib/eco/cli/config/use_cases.rb +4 -2
- data/lib/eco/cli_default/people_filters.rb +1 -0
- data/lib/eco/cli_default/workflow.rb +149 -138
- data/lib/eco/data/mapper.rb +51 -19
- data/lib/eco/language/methods/dsl_able.rb +10 -0
- data/lib/eco/version.rb +1 -1
- metadata +87 -35
- data/lib/eco/api/microcases/account_excluded.rb +0 -26
- data/lib/eco/api/microcases/core_excluded.rb +0 -20
- data/lib/eco/api/microcases/fix_default_group.rb +0 -33
- data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
- data/lib/eco/api/microcases/people_cache.rb +0 -30
- data/lib/eco/api/microcases/people_load.rb +0 -84
- data/lib/eco/api/microcases/people_refresh.rb +0 -53
- data/lib/eco/api/microcases/people_search.rb +0 -112
- data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
- data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
- data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
- data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
- data/lib/eco/api/microcases/set_account.rb +0 -18
- data/lib/eco/api/microcases/set_core.rb +0 -17
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
- data/lib/eco/api/microcases/set_supervisor.rb +0 -63
- data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
- data/lib/eco/api/microcases/with_each.rb +0 -103
- data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
- data/lib/eco/api/microcases/with_each_present.rb +0 -36
- data/lib/eco/api/microcases/with_each_starter.rb +0 -37
- data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
- data/lib/eco/api/microcases/with_supervisor.rb +0 -35
- data/lib/eco/api/session/batch/request_stats.rb +0 -266
@@ -1,182 +1,193 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
19
|
+
# default rescue
|
20
|
+
exception do |err, io|
|
21
|
+
next io if rescued
|
16
22
|
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
42
|
-
|
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
|
-
|
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
|
-
|
49
|
-
|
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
|
-
|
54
|
+
io.new(input: cli.config.input_filters.process(io: io))
|
55
|
+
end
|
56
|
+
end
|
55
57
|
|
56
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
63
|
-
end
|
68
|
+
io.new(data: cli.config.people(io: io))
|
64
69
|
end
|
65
|
-
end
|
66
70
|
|
67
|
-
|
68
|
-
|
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
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
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
|
-
|
86
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
+
log(:info) { "No update operation specified... quitting" }
|
94
|
+
exit 0
|
95
|
+
end
|
93
96
|
|
94
|
-
|
95
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
102
|
+
on(:launch_jobs) do
|
103
|
+
session.jobs_launch(simulate: options[:dry_run])
|
104
|
+
end
|
100
105
|
|
101
|
-
|
102
|
-
|
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
|
-
|
108
|
-
|
109
|
+
run_it = !options[:dry_run] || options.dig(:post_launch, :run)
|
110
|
+
unless run_it
|
111
|
+
wf_post.skip!
|
109
112
|
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
115
|
-
|
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
|
-
|
126
|
-
|
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
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
152
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
data/lib/eco/data/mapper.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
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
|
-
@
|
35
|
-
|
36
|
-
|
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 []
|
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
|
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
|
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
|
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
|
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
|
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