eco-helpers 3.0.25 → 3.0.27

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -1
  3. data/eco-helpers.gemspec +1 -1
  4. data/lib/eco/api/common/loaders/base.rb +13 -1
  5. data/lib/eco/api/common/loaders/case_base.rb +1 -1
  6. data/lib/eco/api/common/loaders/error_handler.rb +1 -1
  7. data/lib/eco/api/common/loaders/parser.rb +2 -2
  8. data/lib/eco/api/common/loaders/policy.rb +1 -1
  9. data/lib/eco/api/common/loaders/use_case.rb +1 -1
  10. data/lib/eco/api/common/people/default_parsers/archived_parser.rb +19 -0
  11. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +4 -4
  12. data/lib/eco/api/common/people/default_parsers/date_parser.rb +3 -3
  13. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +6 -6
  14. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +3 -3
  15. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +4 -4
  16. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +9 -6
  17. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -5
  18. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +2 -2
  19. data/lib/eco/api/common/people/default_parsers.rb +1 -0
  20. data/lib/eco/api/common/people/entries.rb +16 -15
  21. data/lib/eco/api/common/people/person_entry.rb +53 -37
  22. data/lib/eco/api/common/people/person_parser.rb +8 -6
  23. data/lib/eco/api/common/session/logger/channels.rb +1 -1
  24. data/lib/eco/api/common/session/logger.rb +2 -2
  25. data/lib/eco/api/common/session/mailer/aws_provider.rb +3 -2
  26. data/lib/eco/api/common/session/mailer/provider_base.rb +6 -2
  27. data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +9 -9
  28. data/lib/eco/api/common/session/mailer.rb +8 -3
  29. data/lib/eco/api/common/session/sftp.rb +2 -2
  30. data/lib/eco/api/common/version_patches/object.rb +2 -1
  31. data/lib/eco/api/custom/mailer.rb +1 -1
  32. data/lib/eco/api/error/handlers.rb +3 -3
  33. data/lib/eco/api/error.rb +17 -17
  34. data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +3 -11
  35. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +4 -1
  36. data/lib/eco/api/microcases/people/manage/search.rb +3 -1
  37. data/lib/eco/api/organization/people.rb +1 -0
  38. data/lib/eco/api/policies.rb +2 -2
  39. data/lib/eco/api/session/batch/job.rb +2 -2
  40. data/lib/eco/api/session/batch/launcher.rb +4 -5
  41. data/lib/eco/api/session/batch/searcher.rb +4 -4
  42. data/lib/eco/api/session/config/api.rb +2 -2
  43. data/lib/eco/api/session/config/apis/enviro_spaces.rb +3 -3
  44. data/lib/eco/api/session/config/apis/space_helpers.rb +4 -4
  45. data/lib/eco/api/session/config/apis.rb +1 -1
  46. data/lib/eco/api/session/config/post_launch.rb +7 -4
  47. data/lib/eco/api/session/config/sftp.rb +1 -1
  48. data/lib/eco/api/session/config/tagtree.rb +1 -1
  49. data/lib/eco/api/session/config/workflow.rb +4 -4
  50. data/lib/eco/api/session/config.rb +25 -24
  51. data/lib/eco/api/session.rb +4 -4
  52. data/lib/eco/api/usecases/base_io/validations.rb +4 -3
  53. data/lib/eco/api/usecases/cli/option.rb +5 -2
  54. data/lib/eco/api/usecases/default/people/amend/clear_abilities_case.rb +2 -2
  55. data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +16 -9
  56. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +20 -20
  57. data/lib/eco/api/usecases/default.rb +5 -5
  58. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +8 -8
  59. data/lib/eco/api/usecases/default_cases/upsert_case.rb +4 -4
  60. data/lib/eco/api/usecases/graphql/helpers/base.rb +1 -1
  61. data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +5 -1
  62. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -1
  63. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +3 -3
  64. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +3 -0
  65. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  66. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +9 -3
  67. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +5 -4
  68. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +5 -2
  69. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +3 -3
  70. data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
  71. data/lib/eco/api/usecases/lib/{file_pattern.rb → files/file_pattern.rb} +5 -1
  72. data/lib/eco/api/usecases/lib/{sftp.rb → files/sftp.rb} +27 -16
  73. data/lib/eco/api/usecases/lib/files.rb +7 -0
  74. data/lib/eco/api/usecases/lib.rb +1 -2
  75. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +5 -5
  76. data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +14 -11
  77. data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +14 -23
  78. data/lib/eco/api/usecases/ooze_samples/helpers_migration/typed_fields_pairing.rb +49 -27
  79. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +9 -9
  80. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +1 -1
  81. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +25 -17
  82. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +41 -24
  83. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +16 -15
  84. data/lib/eco/api/usecases/samples/drivers/cli/sftp_cli.rb +15 -15
  85. data/lib/eco/api/usecases/samples/drivers/cli/url_pull_cli.rb +5 -5
  86. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -2
  87. data/lib/eco/api/usecases/use_case.rb +6 -6
  88. data/lib/eco/api/usecases/use_case_chain/chaining.rb +6 -6
  89. data/lib/eco/api/usecases/use_case_chain.rb +4 -4
  90. data/lib/eco/api/usecases/use_case_io.rb +2 -1
  91. data/lib/eco/api/usecases.rb +9 -9
  92. data/lib/eco/cli/config/options_set.rb +4 -4
  93. data/lib/eco/cli/config/use_cases.rb +3 -3
  94. data/lib/eco/cli/scripting/argument.rb +1 -1
  95. data/lib/eco/cli_default/input.rb +9 -9
  96. data/lib/eco/cli_default/options.rb +125 -100
  97. data/lib/eco/cli_default/people.rb +3 -3
  98. data/lib/eco/cli_default/usecases.rb +83 -83
  99. data/lib/eco/cli_default/workflow.rb +7 -7
  100. data/lib/eco/data/files/helpers.rb +3 -3
  101. data/lib/eco/data/fuzzy_match/result.rb +69 -26
  102. data/lib/eco/data/fuzzy_match/results.rb +10 -10
  103. data/lib/eco/data/fuzzy_match/score.rb +13 -8
  104. data/lib/eco/data/fuzzy_match.rb +65 -48
  105. data/lib/eco/data/locations/node_base/treeify.rb +13 -11
  106. data/lib/eco/data/mapper.rb +4 -4
  107. data/lib/eco/language/auxiliar_logger.rb +4 -4
  108. data/lib/eco/language/delegation/const_delegator.rb +64 -0
  109. data/lib/eco/language/delegation/const_lookup_hooks.rb +81 -0
  110. data/lib/eco/language/delegation/delegated_class.rb +84 -0
  111. data/lib/eco/language/delegation.rb +8 -0
  112. data/lib/eco/language/klass/when_inherited.rb +1 -0
  113. data/lib/eco/language/methods/delegate_missing.rb +1 -0
  114. data/lib/eco/language/models/class_helpers.rb +25 -23
  115. data/lib/eco/language/models/collection.rb +12 -2
  116. data/lib/eco/language.rb +1 -0
  117. data/lib/eco/version.rb +1 -1
  118. metadata +12 -6
@@ -1,149 +1,149 @@
1
1
  ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
2
2
  cnf.usecases do |cases| # rubocop:disable Metrics/BlockLength
3
- desc = "It exports to a CSV the (filtered) people"
4
- cases.add("-people-to-csv", :export, desc) do |people, session, options|
5
- file = SCR.get_file("-people-to-csv", required: true, should_exist: false)
3
+ desc = 'It exports to a CSV the (filtered) people'
4
+ cases.add('-people-to-csv', :export, desc) do |people, session, options|
5
+ file = SCR.get_file('-people-to-csv', required: true, should_exist: false)
6
6
  options.deep_merge!(export: {file: {name: file, format: :csv}})
7
7
 
8
- case_name = options.dig(:export, :options, :detailed) ? "to-csv-detailed" : "to-csv"
8
+ case_name = options.dig(:export, :options, :detailed) ? 'to-csv-detailed' : 'to-csv'
9
9
  session.usecases.case(case_name)
10
- end.add_option("-nice-header", "Outputs more descriptive standard headers") do |options|
10
+ end.add_option('-nice-header', 'Outputs more descriptive standard headers') do |options|
11
11
  options.deep_merge!(export: {options: {nice_header: true}})
12
- end.add_option("-internal-names", "It is the most raw export. Useful to see all the data when name mappings override/overlap") do |options|
12
+ end.add_option('-internal-names', 'It is the most raw export. Useful to see all the data when name mappings override/overlap') do |options|
13
13
  options.deep_merge!(export: {options: {internal_names: true}})
14
- end.add_option("-detailed", "Includes much more information to the file (i.e. permissions_merged abilities, preferences)") do |options|
14
+ end.add_option('-detailed', 'Includes much more information to the file (i.e. permissions_merged abilities, preferences)') do |options|
15
15
  options.deep_merge!(export: {options: {detailed: true}})
16
- end.add_option("-permissions-custom", "Used with -detailed. Adds the permissions_custom abilities") do |options|
16
+ end.add_option('-permissions-custom', 'Used with -detailed. Adds the permissions_custom abilities') do |options|
17
17
  options.deep_merge!(export: {options: {permissions_custom: true}})
18
- end.add_option("-split-schemas", "It will generate 1 file per each schema") do |options|
18
+ end.add_option('-split-schemas', 'It will generate 1 file per each schema') do |options|
19
19
  options.deep_merge!(export: {options: {split_schemas: true}})
20
20
  end
21
21
 
22
22
  desc = "Forces a change of email in the same org. It won't succeed if email taken by an org member user"
23
- cases.add("-change-email-from", :sync, desc, case_name: "change-email")
23
+ cases.add('-change-email-from', :sync, desc, case_name: 'change-email')
24
24
 
25
25
  desc = "Sets to -new-super the supervisor_id of the -old-super's subordinates"
26
- cases.add("-switch-supervisor", :transform, desc, case_name: "switch-supervisor") do |people, session, options|
26
+ cases.add('-switch-supervisor', :transform, desc, case_name: 'switch-supervisor') do |people, session, options|
27
27
  unless options[:super]&.key?(:old)
28
- msg = "You must specify an -old-super to target whose supervisor is changing"
28
+ msg = 'You must specify an -old-super to target whose supervisor is changing'
29
29
  session.log(:error) { msg }
30
30
  exit(1)
31
31
  end
32
32
  unless options[:super]&.key?(:new)
33
- msg = "You must specify the -new-super id. To reset to nil the supervisor, please, specify nil."
33
+ msg = 'You must specify the -new-super id. To reset to nil the supervisor, please, specify nil.'
34
34
  session.log(:error) { msg }
35
35
  exit(1)
36
36
  end
37
- end.add_option("-old-super", "The supervisor id to be replaced on the subordinates") do |options|
38
- if old_id = SCR.get_arg("-old-super", with_param: true)
39
- old_id = old_id == "nil"? nil : old_id
37
+ end.add_option('-old-super', 'The supervisor id to be replaced on the subordinates') do |options|
38
+ if (old_id = SCR.get_arg('-old-super', with_param: true))
39
+ old_id = old_id == 'nil'? nil : old_id
40
40
  options.deep_merge!(super: {old: old_id})
41
41
  end
42
- end.add_option("-new-super", "The new supervisor id") do |options|
43
- if new_id = SCR.get_arg("-new-super", with_param: true)
44
- new_id = new_id == "nil"? nil : new_id
42
+ end.add_option('-new-super', 'The new supervisor id') do |options|
43
+ if (new_id = SCR.get_arg('-new-super', with_param: true))
44
+ new_id = new_id == 'nil'? nil : new_id
45
45
  options.deep_merge!(super: {new: new_id})
46
46
  end
47
47
  end
48
48
 
49
- desc = "Input file dump into a CSV as is."
50
- cases.add("-entries-to-csv", :import, desc, case_name: "entries-to-csv")
51
- .add_option("-out") do |options|
52
- file = SCR.get_file("-out")
49
+ desc = 'Input file dump into a CSV as is.'
50
+ cases.add('-entries-to-csv', :import, desc, case_name: 'entries-to-csv')
51
+ .add_option('-out') do |options|
52
+ file = SCR.get_file('-out')
53
53
  options.deep_merge!(export: {file: file})
54
54
  end
55
55
 
56
- desc = "Clears the `permissions_custom`, provided that Policy Group abilities alone apply."
57
- desc += " Please be mindfull if you use this option (there may be users that have been upgraded in ad-hoc manner)."
58
- cases.add("-clear-abilities", :transform, desc, case_name: "clear-abilities")
56
+ desc = 'Clears the `permissions_custom`, provided that Policy Group abilities alone apply.'
57
+ desc << ' Please be mindfull if you use this option (there may be users that have been upgraded in ad-hoc manner).'
58
+ cases.add('-clear-abilities', :transform, desc, case_name: 'clear-abilities')
59
59
 
60
- desc = "Deletes everybody that has been filtered from the people manager"
61
- cases.add("-delete", :transform, desc, case_name: "delete")
62
- desc = "Deletes the people specified in the input data"
63
- cases.add("-delete-from", :sync, desc, case_name: "delete")
60
+ desc = 'Deletes everybody that has been filtered from the people manager'
61
+ cases.add('-delete', :transform, desc, case_name: 'delete')
62
+ desc = 'Deletes the people specified in the input data'
63
+ cases.add('-delete-from', :sync, desc, case_name: 'delete')
64
64
 
65
- desc = "Re-freshes the default_tag of users"
66
- cases.add("-set-default-tag", :transform, desc, case_name: "set-default-tag")
65
+ desc = 'Re-freshes the default_tag of users'
66
+ cases.add('-set-default-tag', :transform, desc, case_name: 'set-default-tag')
67
67
 
68
- desc = "Creates people with with details and account"
69
- as1 = "During the run, if new people is created, they are included in the People object of the current session."
70
- as1 << " This makes them available to find them (i.e. via 'external-id') before they exist"
71
- cases.add("-create-from", :sync, desc, case_name: "create")
72
- .add_option("-append-starters", as1) do |options|
73
- options.deep_merge!(people: {append_created: true})
74
- end
68
+ desc = 'Creates people with with details and account'
69
+ as_1 = 'During the run, if new people is created, they are included in the People object of the current session.'
70
+ as_1 << " This makes them available to find them (i.e. via 'external-id') before they exist"
71
+ cases.add('-create-from', :sync, desc, case_name: 'create').
72
+ add_option('-append-starters', as_1) do |options|
73
+ options.deep_merge!(people: {append_created: true})
74
+ end
75
75
 
76
- desc = "It just adds everybody to an update job without doing any change. If the org has policies, it will refresh"
77
- cases.add("-refresh", :transform, desc, case_name: "refresh")
76
+ desc = 'It just adds everybody to an update job without doing any change. If the org has policies, it will refresh'
77
+ cases.add('-refresh', :transform, desc, case_name: 'refresh')
78
78
 
79
- desc = "Updates the people specified in the input data"
80
- cases.add("-update-from", :sync, desc, case_name: "update")
79
+ desc = 'Updates the people specified in the input data'
80
+ cases.add('-update-from', :sync, desc, case_name: 'update')
81
81
 
82
82
  desc = "Does an actual transfer of USER from id|external_id account to 'destination-id' person"
83
- cases.add("-transfer-account-from", :sync, desc, case_name: "transfer-account")
84
- .add_option("-include-email", "Specifies if the email should also be moved. Otherwise it only moves the account") do |options|
85
- options.deep_merge!(include: {email: true})
86
- end
83
+ cases.add('-transfer-account-from', :sync, desc, case_name: 'transfer-account').
84
+ add_option('-include-email', 'Specifies if the email should also be moved. Otherwise it only moves the account') do |options|
85
+ options.deep_merge!(include: {email: true})
86
+ end
87
87
 
88
- desc = "Tries to find the input entries and update them. It creates them if not found"
89
- cases.add("-upsert-from", :sync, desc, case_name: "upsert")
90
- .add_option("-append-starters", as1) do |options|
91
- options.deep_merge!(people: {append_created: true})
92
- end
88
+ desc = 'Tries to find the input entries and update them. It creates them if not found'
89
+ cases.add('-upsert-from', :sync, desc, case_name: 'upsert').
90
+ add_option('-append-starters', as_1) do |options|
91
+ options.deep_merge!(people: {append_created: true})
92
+ end
93
93
 
94
- desc = "It does like -upsert-from and additionally removes account and supervisor of those in people that are not in the entries (leavers)"
95
- cases.add("-hris-from", :sync, desc, case_name: "hris")
96
- .add_option("-append-starters", as1) do |options|
97
- options.deep_merge!(people: {append_created: true})
98
- end
94
+ desc = 'It does like -upsert-from and additionally removes account and supervisor of those in people that are not in the entries (leavers)'
95
+ cases.add('-hris-from', :sync, desc, case_name: 'hris').
96
+ add_option('-append-starters', as_1) do |options|
97
+ options.deep_merge!(people: {append_created: true})
98
+ end
99
99
 
100
100
  # Ooze cases
101
- desc = "APIv2 Case: Exports the target register into a CSV"
102
- cases.add("-export-register", :other, desc, case_name: "export-register") do |session, options, usecase|
103
- file = SCR.get_file("-export-register", required: false, should_exist: false)
104
- options.deep_merge!(export: {file: {name: file || "RegisterExport.csv", format: :csv}})
101
+ desc = 'APIv2 Case: Exports the target register into a CSV'
102
+ cases.add('-export-register', :other, desc, case_name: 'export-register') do |session, options, usecase|
103
+ file = SCR.get_file('-export-register', required: false, should_exist: false)
104
+ options.deep_merge!(export: {file: {name: file || 'RegisterExport.csv', format: :csv}})
105
105
 
106
106
  unless options.dig(:source, :register_id)
107
107
  session.log(:error) {
108
- "You should specify the target register id"
108
+ 'You should specify the target register id'
109
109
  }
110
110
  exit(1)
111
111
  end
112
- end.add_option("-register-id", "Target register id") do |options|
113
- reg_id = SCR.get_arg("-register-id", with_param: true)
112
+ end.add_option('-register-id', 'Target register id') do |options|
113
+ reg_id = SCR.get_arg('-register-id', with_param: true)
114
114
  options.deep_merge!(source: {register_id: reg_id})
115
- end.add_option("-include-deindexed", "Tells if deindexed fields should be included") do |options|
115
+ end.add_option('-include-deindexed', 'Tells if deindexed fields should be included') do |options|
116
116
  options.deep_merge!(export: {options: {include: {deindexed: true}}})
117
- end.add_option("-include-unnamed", "Tells if unnamed fields should be included") do |options|
117
+ end.add_option('-include-unnamed', 'Tells if unnamed fields should be included') do |options|
118
118
  options.deep_merge!(export: {options: {include: {unnamed: true}}})
119
- end.add_option("-include-unhashed", "Tells if fields with no hash reference (very short label) should be included") do |options|
119
+ end.add_option('-include-unhashed', 'Tells if fields with no hash reference (very short label) should be included') do |options|
120
120
  options.deep_merge!(export: {options: {include: {unhashed: true}}})
121
- end.add_option("-delimiter", "Sets the delimiter to be used in fields multi value") do |options|
122
- str = SCR.get_arg("-delimiter", with_param: true)
121
+ end.add_option('-delimiter', 'Sets the delimiter to be used in fields multi value') do |options|
122
+ str = SCR.get_arg('-delimiter', with_param: true)
123
123
  options.deep_merge!(export: {options: {delimiter: str}})
124
- end.add_option("-created-from", "Filters the register to the entries created FROM the specified date") do |options|
125
- str = SCR.get_arg("-created-from", with_param: true)
124
+ end.add_option('-created-from', 'Filters the register to the entries created FROM the specified date') do |options|
125
+ str = SCR.get_arg('-created-from', with_param: true)
126
126
  date = Time.parse(str)
127
127
  options.deep_merge!(export: {options: {filters: {created_at: {from: date}}}})
128
- end.add_option("-created-to", "Filters the register to the entries created up TO the specified date") do |options|
129
- str = SCR.get_arg("-created-to", with_param: true)
128
+ end.add_option('-created-to', 'Filters the register to the entries created up TO the specified date') do |options|
129
+ str = SCR.get_arg('-created-to', with_param: true)
130
130
  date = Time.parse(str)
131
131
  options.deep_merge!(export: {options: {filters: {created_at: {to: date}}}})
132
- end.add_option("-updated-from", "Filters the register by entries updated FROM the specified date") do |options|
133
- str = SCR.get_arg("-updated-from", with_param: true)
132
+ end.add_option('-updated-from', 'Filters the register by entries updated FROM the specified date') do |options|
133
+ str = SCR.get_arg('-updated-from', with_param: true)
134
134
  date = Time.parse(str)
135
135
  options.deep_merge!(export: {options: {filters: {updated_at: {from: date}}}})
136
- end.add_option("-updated-to", "Filters the register by entries updated up TO the specified date") do |options|
137
- str = SCR.get_arg("-updated-to", with_param: true)
136
+ end.add_option('-updated-to', 'Filters the register by entries updated up TO the specified date') do |options|
137
+ str = SCR.get_arg('-updated-to', with_param: true)
138
138
  date = Time.parse(str)
139
139
  options.deep_merge!(export: {options: {filters: {updated_at: {to: date}}}})
140
- end.add_option("-all-tags", "Filters the register to entries with ALL specified tags (| separator)") do |options|
141
- str = SCR.get_arg("-all-tags", with_param: true)
142
- tags = str.split("|")
140
+ end.add_option('-all-tags', 'Filters the register to entries with ALL specified tags (| separator)') do |options|
141
+ str = SCR.get_arg('-all-tags', with_param: true)
142
+ tags = str.split('|')
143
143
  options.deep_merge!(export: {options: {filters: {tags: {all: tags}}}})
144
- end.add_option("-any-tags", "Filters the register to entries with ANY specified tags (| separator)") do |options|
145
- str = SCR.get_arg("-all-tags", with_param: true)
146
- tags = str.split("|")
144
+ end.add_option('-any-tags', 'Filters the register to entries with ANY specified tags (| separator)') do |options|
145
+ str = SCR.get_arg('-all-tags', with_param: true)
146
+ tags = str.split('|')
147
147
  options.deep_merge!(export: {options: {filters: {tags: {any: tags}}}})
148
148
  end
149
149
  end
@@ -11,7 +11,7 @@ class Eco::CliDefault::Workflow < Eco::API::Common::Loaders::Workflow
11
11
  # workflows that assembly those classes?
12
12
  # 5. Right on the load:data stage, set the io model
13
13
  # based on (1).
14
-
14
+ #
15
15
  class << self
16
16
  attr_accessor :rescued
17
17
  end
@@ -90,7 +90,7 @@ class Eco::CliDefault::Workflow < Eco::API::Common::Loaders::Workflow
90
90
  on(:usecases) do
91
91
  next if cli_usecases.process(io: io)
92
92
 
93
- log(:info) { "No update operation specified... quitting" }
93
+ log(:info) { 'No update operation specified... quitting' }
94
94
  exit 0
95
95
  end
96
96
 
@@ -111,8 +111,8 @@ class Eco::CliDefault::Workflow < Eco::API::Common::Loaders::Workflow
111
111
  wf_post.skip!
112
112
 
113
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]
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
116
  msg
117
117
  }
118
118
 
@@ -125,11 +125,11 @@ class Eco::CliDefault::Workflow < Eco::API::Common::Loaders::Workflow
125
125
 
126
126
  unless refresh_data
127
127
  log(:info) {
128
- msg = "Although there are post_launch cases, data will not be refreshed before their run"
128
+ msg = 'Although there are post_launch cases, data will not be refreshed before their run'
129
129
  if io.options[:dry_run]
130
- msg << ", because we are in dry-run (simulate)."
130
+ msg << ', because we are in dry-run (simulate).'
131
131
  elsif !partial_update
132
- msg << ", because it is not a partial update (-get-partial option not present)."
132
+ msg << ', because it is not a partial update (-get-partial option not present).'
133
133
  end
134
134
  msg
135
135
  }
@@ -112,7 +112,7 @@ module Eco
112
112
  File.join(path, basename)
113
113
  end
114
114
 
115
- def folder_files(folder = ".", pattern = "*", regexp: nil, older_than: nil)
115
+ def folder_files(folder = '.', pattern = '*', regexp: nil, older_than: nil)
116
116
  target = File.join(File.expand_path(folder), pattern)
117
117
  Dir[target].tap do |dir_files|
118
118
  dir_files.select! {|f| File.file?(f)}
@@ -131,8 +131,8 @@ module Eco
131
131
  end.sort
132
132
  end
133
133
 
134
- def csv_files(folder = ".", regexp: nil, older_than: nil)
135
- folder_files(folder, "*.csv", regexp: regexp, older_than: older_than).sort
134
+ def csv_files(folder = '.', regexp: nil, older_than: nil)
135
+ folder_files(folder, '*.csv', regexp: regexp, older_than: older_than).sort
136
136
  end
137
137
  end
138
138
 
@@ -1,23 +1,64 @@
1
1
  module Eco
2
2
  module Data
3
3
  module FuzzyMatch
4
- class Result < Struct.new(:match, :value, :needle_value, :dice, :levenshtein, :jaro_winkler, :ngrams, :words_ngrams, :chars_position)
5
- ALL_METHODS = [:dice, :levenshtein, :jaro_winkler, :ngrams, :words_ngrams, :chars_position]
4
+ class Result < Struct.new(
5
+ :match,
6
+ :value,
7
+ :needle_value,
8
+ :dice,
9
+ :levenshtein,
10
+ :jaro_winkler,
11
+ :ngrams,
12
+ :words_ngrams,
13
+ :chars_position
14
+ )
15
+ ALL_METHODS = %i[
16
+ dice levenshtein jaro_winkler
17
+ ngrams words_ngrams chars_position
18
+ ].freeze
6
19
 
7
20
  attr_accessor :pivot
8
21
 
9
- def dice; super&.round(3); end
10
- def levenshtein; super&.round(3); end
11
- def jaro_winkler; super&.round(3); end
12
- def ngrams; super&.round(3); end
13
- def words_ngrams; super&.round(3); end
14
- def chars_position; super&.round(3); end
22
+ def dice
23
+ super&.round(3)
24
+ end
25
+
26
+ def levenshtein
27
+ super&.round(3)
28
+ end
29
+
30
+ def jaro_winkler
31
+ super&.round(3)
32
+ end
33
+
34
+ def ngrams
35
+ super&.round(3)
36
+ end
37
+
38
+ def words_ngrams
39
+ super&.round(3)
40
+ end
41
+
42
+ def chars_position
43
+ super&.round(3)
44
+ end
15
45
 
16
46
  #Shortcuts
17
- def lev; levenshtein; end
18
- def jaro; jaro_winkler; end
19
- def wngrams; words_ngrams; end
20
- def pos; chars_position; end
47
+ def lev
48
+ levenshtein
49
+ end
50
+
51
+ def jaro
52
+ jaro_winkler
53
+ end
54
+
55
+ def wngrams
56
+ words_ngrams
57
+ end
58
+
59
+ def pos
60
+ chars_position
61
+ end
21
62
 
22
63
  def average
23
64
  values = [dice, levenshtein, jaro_winkler, ngrams, words_ngrams, chars_position]
@@ -36,52 +77,54 @@ module Eco
36
77
 
37
78
  def all_threshold?(methods = order, threshold = 0.15)
38
79
  return true unless threshold
80
+
39
81
  [methods].flatten.compact.all? {|method| threshold?(method, threshold)}
40
82
  end
41
83
 
42
84
  def any_threshold?(methods = order, threshold = 0.15)
43
85
  return true unless threshold
86
+
44
87
  [methods].flatten.compact.any? {|method| threshold?(method, threshold)}
45
88
  end
46
89
 
47
90
  def threshold?(method = :dice, threshold = 0.15)
48
- raise "Uknown method '#{method}'" unless self.respond_to?(method)
49
- self.send(method) >= threshold
91
+ raise ArgumentError, "Uknown method '#{method}'" unless respond_to?(method, true)
92
+
93
+ send(method) >= threshold
50
94
  end
51
95
 
52
96
  def order=(values)
53
97
  @order = [values].flatten.compact.tap do |o|
54
- o << [:words_ngrams, :dice] if o.empty?
98
+ o << %i[words_ngrams dice] if o.empty?
55
99
  end
56
100
  end
57
101
 
58
102
  def order
59
- @order ||= [:words_ngrams, :dice]
103
+ @order ||= %i[words_ngrams dice]
60
104
  end
61
105
 
62
- def <=>(result)
63
- compare(result)
106
+ def <=>(other)
107
+ compare(other)
64
108
  end
65
109
 
66
110
  def values_at(*keys)
67
111
  keys.map do |key|
68
- self.send(key) if self.respond_to?(key)
112
+ send(key) if respond_to?(key)
69
113
  end
70
114
  end
71
115
 
72
116
  private
73
117
 
74
118
  def compare(other, order: self.order)
75
- return 0 unless method = order.first
76
- raise "Uknown method '#{method}'" unless self.respond_to?(method) && other.respond_to?(method)
77
- return -1 if self.send(method) > other.send(method)
78
- return 1 if self.send(method) < other.send(method)
79
- compare(other, order: order[1..-1])
80
- end
119
+ return 0 unless (method = order.first)
81
120
 
121
+ raise "Uknown method '#{method}'" unless respond_to?(method, true) && other.respond_to?(method, true)
82
122
 
123
+ return -1 if send(method) > other.send(method)
124
+ return 1 if send(method) < other.send(method)
125
+ compare(other, order: order[1..])
126
+ end
83
127
  end
84
-
85
128
  end
86
129
  end
87
130
  end
@@ -12,14 +12,16 @@ module Eco
12
12
 
13
13
  def each(&block)
14
14
  return to_enum(:each) unless block
15
+
15
16
  raw_results.each(&block)
16
17
  end
17
18
 
18
19
  # Merges the results of both Results object
19
20
  def merge(res)
20
- unless self.needle == res.needle
21
+ unless needle == res.needle
21
22
  raise "To merge 2 Results, needle should be the same ('#{value}'). Given '#{res.value}'"
22
23
  end
24
+
23
25
  self.class.new(needle, value, raw_results.concat(res.raw_results))
24
26
  end
25
27
 
@@ -29,9 +31,10 @@ module Eco
29
31
 
30
32
  def relevant_results(**options)
31
33
  options = {order: order, threshold: threshold || 0.5}.merge(options)
34
+
32
35
  raw_results.select do |result|
33
36
  result.all_threshold?(options[:order], options[:threshold])
34
- end.yield_self do |filtered|
37
+ end.then do |filtered|
35
38
  self.class.new(needle, value, filtered).tap do |results|
36
39
  results.order = options[:order]
37
40
  end
@@ -47,7 +50,7 @@ module Eco
47
50
  end
48
51
 
49
52
  def order
50
- @order ||= [:words_ngrams, :dice]
53
+ @order ||= %i[words_ngrams dice]
51
54
  end
52
55
 
53
56
  def results
@@ -55,23 +58,20 @@ module Eco
55
58
  end
56
59
 
57
60
  def print
58
- msg = results.map do |result|
59
- result.print
60
- end.join("\n ")
61
+ msg = results.map(&:print).join("\n ")
61
62
 
62
63
  puts "'#{value}':\n " + msg
63
64
  end
64
65
 
65
66
  private
66
67
 
67
- def item_string(item, attr = self.method)
68
+ def item_string(item, attr = self.method) # rubocop:disable Style/RedundantSelf
68
69
  return item if !item || item.is_a?(String) || !attr
70
+
69
71
  attr = attr.to_sym
70
- return item.send(attr) if item.respond_to?(attr)
72
+ item.send(attr) if item.respond_to?(attr, true)
71
73
  end
72
-
73
74
  end
74
-
75
75
  end
76
76
  end
77
77
  end
@@ -2,11 +2,13 @@ module Eco
2
2
  module Data
3
3
  module FuzzyMatch
4
4
  class Score < Struct.new(:score, :total)
5
-
6
5
  def ratio(decimals = 6)
7
- tot = self.total; sc = self.score
8
- tot = tot && tot > 0 ? tot : 1
9
- sc = sc && sc > 0 ? sc : 0
6
+ tot = total
7
+ sc = score
8
+
9
+ tot = 1 unless tot&.positive?
10
+ sc = 0 unless sc&.positive?
11
+
10
12
  (sc.to_f / tot).round(decimals)
11
13
  end
12
14
 
@@ -16,7 +18,10 @@ module Eco
16
18
 
17
19
  def increase(value = 1)
18
20
  self.score += value
19
- raise "Score #{self.score} (increase: #{value}) can't be greater than total #{self.total}" if self.score > self.total
21
+
22
+ msg = "Score #{self.score} (increase: #{value}) can't be greater than total #{total}"
23
+ raise msg if score > total
24
+
20
25
  self.score
21
26
  end
22
27
 
@@ -26,7 +31,7 @@ module Eco
26
31
 
27
32
  def values_at(*keys)
28
33
  keys.map do |key|
29
- self.send(key) if self.respond_to?(key)
34
+ send(key) if respond_to?(key, true)
30
35
  end
31
36
  end
32
37
 
@@ -37,13 +42,13 @@ module Eco
37
42
 
38
43
  def merge!(scr)
39
44
  raise "Expecting Score object. Given: #{scr.class}" unless scr.is_a?(Score)
45
+
40
46
  increase_total(scr.total)
41
47
  increase(scr.score)
48
+
42
49
  self
43
50
  end
44
-
45
51
  end
46
-
47
52
  end
48
53
  end
49
54
  end