eco-helpers 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -2
  3. data/LICENSE +21 -0
  4. data/eco-helpers.gemspec +1 -1
  5. data/lib/eco/api.rb +2 -0
  6. data/lib/eco/api/common.rb +4 -0
  7. data/lib/eco/api/common/base_loader.rb +54 -0
  8. data/lib/eco/api/common/class_auto_loader.rb +109 -0
  9. data/lib/eco/api/common/class_helpers.rb +33 -0
  10. data/lib/eco/api/common/class_hierarchy.rb +1 -1
  11. data/lib/eco/api/common/class_meta_basics.rb +16 -0
  12. data/lib/eco/api/common/loaders.rb +13 -0
  13. data/lib/eco/api/common/loaders/error_handler.rb +41 -0
  14. data/lib/eco/api/common/loaders/parser.rb +127 -0
  15. data/lib/eco/api/common/loaders/policy.rb +25 -0
  16. data/lib/eco/api/common/loaders/use_case.rb +40 -0
  17. data/lib/eco/api/common/people/default_parsers.rb +3 -12
  18. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
  19. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
  20. data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
  21. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +15 -25
  22. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
  23. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
  24. data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
  25. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +24 -35
  26. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -25
  27. data/lib/eco/api/common/people/entries.rb +54 -24
  28. data/lib/eco/api/common/people/entry_factory.rb +10 -8
  29. data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
  30. data/lib/eco/api/common/people/person_entry.rb +308 -216
  31. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +3 -2
  32. data/lib/eco/api/common/people/person_parser.rb +51 -18
  33. data/lib/eco/api/common/session/logger.rb +4 -0
  34. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
  35. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +1 -1
  36. data/lib/eco/api/common/version_patches/exception.rb +22 -0
  37. data/lib/eco/api/custom.rb +13 -0
  38. data/lib/eco/api/custom/error_handler.rb +20 -0
  39. data/lib/eco/api/custom/namespace.rb +7 -0
  40. data/lib/eco/api/custom/parser.rb +50 -0
  41. data/lib/eco/api/custom/policy.rb +28 -0
  42. data/lib/eco/api/custom/use_case.rb +16 -0
  43. data/lib/eco/api/error.rb +1 -0
  44. data/lib/eco/api/error/handlers.rb +10 -3
  45. data/lib/eco/api/microcases.rb +17 -13
  46. data/lib/eco/api/microcases/account_excluded.rb +24 -0
  47. data/lib/eco/api/microcases/append_usergroups.rb +19 -0
  48. data/lib/eco/api/microcases/core_excluded.rb +4 -4
  49. data/lib/eco/api/microcases/{set_default_group.rb → fix_default_group.rb} +10 -9
  50. data/lib/eco/api/microcases/fix_filter_tags.rb +26 -6
  51. data/lib/eco/api/microcases/people_cache.rb +17 -0
  52. data/lib/eco/api/microcases/people_load.rb +59 -0
  53. data/lib/eco/api/microcases/people_refresh.rb +31 -0
  54. data/lib/eco/api/microcases/people_search.rb +65 -0
  55. data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
  56. data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
  57. data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
  58. data/lib/eco/api/microcases/set_account.rb +7 -19
  59. data/lib/eco/api/microcases/set_core.rb +5 -5
  60. data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
  61. data/lib/eco/api/microcases/set_supervisor.rb +17 -13
  62. data/lib/eco/api/microcases/strict_search.rb +12 -7
  63. data/lib/eco/api/microcases/with_each.rb +27 -0
  64. data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
  65. data/lib/eco/api/microcases/with_each_present.rb +30 -0
  66. data/lib/eco/api/microcases/with_each_starter.rb +30 -0
  67. data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
  68. data/lib/eco/api/microcases/with_supervisor.rb +36 -0
  69. data/lib/eco/api/organization/people.rb +72 -35
  70. data/lib/eco/api/organization/presets_factory.rb +13 -4
  71. data/lib/eco/api/policies.rb +11 -7
  72. data/lib/eco/api/session.rb +54 -24
  73. data/lib/eco/api/session/batch.rb +1 -1
  74. data/lib/eco/api/session/batch/base_policy.rb +7 -6
  75. data/lib/eco/api/session/batch/errors.rb +28 -4
  76. data/lib/eco/api/session/batch/feedback.rb +7 -1
  77. data/lib/eco/api/session/batch/job.rb +40 -23
  78. data/lib/eco/api/session/batch/jobs.rb +9 -4
  79. data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
  80. data/lib/eco/api/session/batch/request_stats.rb +91 -58
  81. data/lib/eco/api/session/batch/status.rb +35 -31
  82. data/lib/eco/api/session/config.rb +104 -42
  83. data/lib/eco/api/session/config/api.rb +17 -6
  84. data/lib/eco/api/session/config/logger.rb +2 -2
  85. data/lib/eco/api/session/config/post_launch.rb +1 -1
  86. data/lib/eco/api/session/config/workflow.rb +8 -7
  87. data/lib/eco/api/usecases.rb +47 -33
  88. data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
  89. data/lib/eco/api/usecases/backup/create_case.rb +104 -0
  90. data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
  91. data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
  92. data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
  93. data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
  94. data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
  95. data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
  96. data/lib/eco/api/usecases/backup/update_case.rb +112 -0
  97. data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
  98. data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
  99. data/lib/eco/api/usecases/base_case.rb +2 -0
  100. data/lib/eco/api/usecases/base_io.rb +3 -3
  101. data/lib/eco/api/usecases/default_cases.rb +23 -53
  102. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
  103. data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
  104. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
  105. data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
  106. data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
  107. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
  108. data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
  109. data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
  110. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
  111. data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
  112. data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
  113. data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
  114. data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
  115. data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
  116. data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
  117. data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
  118. data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
  119. data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
  120. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
  121. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
  122. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
  123. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
  124. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
  125. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
  126. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
  127. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
  128. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
  129. data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
  130. data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
  131. data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
  132. data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
  133. data/lib/eco/api/usecases/use_case_io.rb +9 -9
  134. data/lib/eco/cli/config.rb +10 -2
  135. data/lib/eco/cli/config/default.rb +2 -1
  136. data/lib/eco/cli/config/default/input_filters.rb +58 -0
  137. data/lib/eco/cli/config/default/options.rb +60 -25
  138. data/lib/eco/cli/config/default/people.rb +4 -4
  139. data/lib/eco/cli/config/default/people_filters.rb +108 -0
  140. data/lib/eco/cli/config/default/usecases.rb +69 -32
  141. data/lib/eco/cli/config/default/workflow.rb +37 -27
  142. data/lib/eco/cli/config/filters.rb +50 -0
  143. data/lib/eco/cli/config/filters/input_filters.rb +29 -0
  144. data/lib/eco/cli/config/filters/people_filters.rb +29 -0
  145. data/lib/eco/cli/config/help.rb +49 -0
  146. data/lib/eco/cli/config/options_set.rb +17 -1
  147. data/lib/eco/cli/config/use_cases.rb +79 -53
  148. data/lib/eco/cli/scripting.rb +10 -2
  149. data/lib/eco/cli/scripting/args_helpers.rb +25 -15
  150. data/lib/eco/cli/scripting/argument.rb +1 -0
  151. data/lib/eco/cli/scripting/arguments.rb +1 -1
  152. data/lib/eco/csv/table.rb +1 -1
  153. data/lib/eco/data/crypto/encryption.rb +3 -0
  154. data/lib/eco/language/match.rb +19 -9
  155. data/lib/eco/language/match_modifier.rb +13 -5
  156. data/lib/eco/language/models/collection.rb +77 -56
  157. data/lib/eco/language/models/parser_serializer.rb +39 -15
  158. data/lib/eco/version.rb +1 -1
  159. metadata +63 -18
  160. data/lib/eco/api/microcases/set_default_tag.rb +0 -23
  161. data/lib/eco/api/session/task.rb +0 -175
  162. data/lib/eco/api/usecases/default_case.rb +0 -19
  163. data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
  164. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -99
  165. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
  166. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
  167. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
  168. data/lib/eco/api/usecases/microed_cases/hris_case.rb +0 -53
  169. data/lib/eco/api/usecases/microed_cases/update_case.rb +0 -33
  170. data/lib/eco/api/usecases/microed_cases/update_details_case.rb +0 -30
  171. data/lib/eco/api/usecases/microed_cases/upsert_case.rb +0 -36
  172. data/lib/eco/cli/config/default/filters.rb +0 -70
  173. data/lib/eco/cli/config/people_filters.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6fbde8a22ee5efad00700ad096396a008f9a8f9ecaf8e2096f22b7730fa28d2
4
- data.tar.gz: dc498ae2c6f853f92f3e2703d116a442c2814b2c0a230270e319fabf8678342c
3
+ metadata.gz: afef384678f171e737391056ca300ac9d9c813240d32422445ad1e256911be31
4
+ data.tar.gz: 82f7b611239cc9e5d58778d1db9ffaef7cef748360fd82abeba3df710c56ac60
5
5
  SHA512:
6
- metadata.gz: 9cb6d878d32370e81c512b01de2da8c6c32abcd79d636f1d70189228445c0094acef7236ffc4447c0cdd79e05576c22ceeb4798160da8752d655ff71e35440fb
7
- data.tar.gz: 14283f84d4fbdc87a160dcdb842a3b154987d606333018acc0a636bd2ee2db9a25167c0106b8c8ba5fc56b4107324c9afa07caaeebe9e219bdaac1aac9d21687
6
+ metadata.gz: 6516df10c5fbf6d48f8fa5bfdb993320a15043fecdcbe84c2927c6c84ab9fd817d298f9ae0806a6e43476d2342e862fbecb55ed14fc532bc4cf007f32a9ff7e6
7
+ data.tar.gz: 13763cf62b5d0741d0d23837f66480fcf678ac317d6ac726cdea0fbd12cb4ce048b57e3278053536c214661f9aa591a90a22e06b5a24720bba087459c6536d72
@@ -1,7 +1,87 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [1.5.1] - 2020-10-xx
4
+ ## [1.5.2] - 2020-10-29
5
+
6
+ ### Added
7
+ - **custom** usecases, policies and error handlers can now be **declared within its own class**
8
+ * helper classes to inherit from: `Eco::API::Custom::UseCase`, `Eco::API::Custom::Policy`, `Eco::API::Custom::ErrorHandler` and `Eco::API::Custom::Parser`
9
+ * please, notice that you should create new classes under the following namespaces
10
+ - `Custom::UseCase`: custom use cases
11
+ - `Custom::Policy`: custom policy
12
+ - `Custom::ErrorHandler`: custom error handler
13
+ - `Custom::Parser`: custom parser
14
+ * this also allows to inherit from existing defaults and models (models to come)
15
+ - implemented first **microcases** (evaluation stage): to be able to centralize common code between use cases
16
+ - see `Eco::API::MicroCases` class
17
+ - **command line** added `--help` to list all `usecases`, `options` and `filters`
18
+ * `--help -options` will print a documented overview of options
19
+ * `--help -filters` will print a documented overview of people filters
20
+ * `--help -input-filters` will print a documented overview of input data filters
21
+ * `--help -usecases` will print a documented overview of the usecases
22
+ - **command line** filters for `filter_tags` on:
23
+ * input data: `-input-filter-tags-all`, `input-filter-tags-any`, `input-filter-tags-tree`
24
+ * people data: `-filter-tags-all`, `-filter-tags-any`, `-filter-tags-tree`
25
+ - **batch stats** & **batch policy**
26
+ * `Eco::API::Session::Batch::RequestStats`: included additional guide on what has been **blanked**.
27
+ - now on you should see how many have been blanked, i.e.: `blanked_email`, `blanked_filter_tags`, `blanked_policy_group_ids`, `blanked_supervisor_id`
28
+ * Moreover, the new `blanked_*` properties are available for `config.batch_policies` provided that you can limit the `max` and/or `min` expected on each batch **type**
29
+ - **csv** generation (`-people-to-csv` and `-people-to-csv -detailed`):
30
+ * now includes `"Has Account?"` new column
31
+ * removed the useless `send_invites` column
32
+ - **errors** improved error message when setting values to a `person` from an `entry`:
33
+ * it now shows the **row number**
34
+ * it now gives the specific value that failed in case of `Exception`
35
+ - `Eco::API::Common::DefaultPasers::LoginProvidersParser`: made native
36
+ - `Eco::API::UseCases::DefaultUsecases::TransferAccountCase`: added `-transer-account-from` usecase
37
+ * to allow actually transfer an account/user from one person to another in the org
38
+ - `Ecoportal::API::V1::Person#entry`: method to be able to have a reference to the update/creation input data entry.
39
+ - new filter methods for `Eco::API::Common::People::Entries` and `Eco::API::Organization::People`
40
+ * `#filter_tags_any` & `#filter_tags_all`: those that have any or all the target tags
41
+ * `#policy_group_ids_any` & `#policy_groups_all`: those that have any or all the target policy groups
42
+
43
+ ### Changed
44
+ - updated dependency on `ecoportal-api` gem
45
+ - **command line** some changes:
46
+ - renamed `-refresh-presets` to `-refresh-abilities`
47
+ - renamed `-recover-db` to `restore-db`
48
+ - removed `Eco::API::Session::Tasks`: all the helpers have been moved and documented as part of `Eco::API::MicroCases` (some have been renamed)
49
+ - as a consequence, removed method `Eco::API::Session#do`
50
+ - `Eco::API::Common::People::PersonEntry#to_hash` has been removed
51
+ - now you should use the more explicit `Eco::API::Common::People::PersonEntry#external_entry`
52
+ - **internal refactor** of `Eco::API::UseCases::DefaultCases`:
53
+ * made so they inherit from `Eco::API::Common::Loaders::UseCase` and cases are autoloaded during run-time
54
+ - **internal refactor** of input entries processing:
55
+ * `Eco::API::Common::People::PersonEntry` internal refactor
56
+ - need to make the code clearer and make the `parsing` and `serializing` symmetrical
57
+ - the `serializers` were expecting an `Ecoportal::API::V1::Person`, which was at a different to that of when the `parsers` kicked in.
58
+ - now it has been introduced the possibility to launch the serializer in a different stage of the process
59
+ - to keep backwards compatibility, now it is possible to define at which `phase` of the parsing/serializing each parser and each serializer should kick in, which entailed changes in other classes and a new parameter in some methods thereof...
60
+ * `Eco::Language::Models::ParserSerializer` offers `category` parameter so you can have multiple parsers and serializers per each parser/serializer (one per category).
61
+ * `Eco::API::Common::People::PersonParser` uses `category` to define a `phase` when the `parser` or the `serializer` should be active => the expected object in the parser `callback` will be different depending on at which phase it is active and therefore called
62
+ - for `parser` valid **phases** are `:internal` (default) and `:final`
63
+ - for `serializer` valid **phases** are `:person` (default), `:final` and `:internal`
64
+ - the expected output of such **callbacks** is the same as before: either the single `value` to return or a `Hash` with pair key/values of virtually-generated or existing-modified attributes of the source/input data passed to the parser
65
+
66
+ ### Fixed
67
+ - **command line**
68
+ * `-search-soft` was being ignored in orgs with org config `session.config.people.strict_search = true`
69
+ * Log connection information (**enabled**): it was not printing where the connection was being made
70
+ * enabled chaining between usecases: they will be processed in the order they hold in the command line
71
+ - Removed error double backtrace (now it should only show one)
72
+ - `Eco::API::Common::People::EntryFactory#entries` was not using `encoding` parameter properly.
73
+ - `Eco::API::Common::People::DefaultParsers::CSVParser` does at `strip` (trim) of the header names.
74
+ - `Eco::API::Organization::PresetsFactory#merge` was including abilities that were not included in the custom presets
75
+ - fix: it will include only those that are defined, provided that using it will not override account abilities that should not be targeted, such as `tasks`
76
+ - this new behavior will preserve account abilities that should be preserved; not targeted by the custom presets
77
+ - some use cases where giving incorrect row number, fixed so they do:
78
+ - `Eco::API::Common::People::EntryFactory#entries` adds `idx` key to each `entry`
79
+ - `Eco::API::Common::People::PersonEntry`: serialization process has been normalized (previously there were missing fields)
80
+ - this fix makes the `csv` with the complete set of fields that should be exported
81
+ - `Ecoportal::API::Internal::Person#account_added` fixed typo
82
+ - `Ecoportal::API::Session::Batch#get_people` should return `Array<Person>` invariably
83
+
84
+ ## [1.5.1] - 2020-10-08
5
85
 
6
86
  ### Added
7
87
  - `presets_values.json`: added the new ability `tasks` (eP release `1.5.3`)
@@ -37,7 +117,7 @@ All notable changes to this project will be documented in this file.
37
117
  ```
38
118
  ### Changed
39
119
  - internally: load `Eco::API::Common::Session` before `Eco::API::Common::People`
40
- - `Eco::API::Common::Person::EntryFactory`: made child of `Eco::API::Common::Session::BaseSession`
120
+ - `Eco::API::Common::People::EntryFactory`: made child of `Eco::API::Common::Session::BaseSession`
41
121
  - refactored all the `api` connection creation for simplicity and to support multi api version
42
122
  - delegated `Eco::API::Session::Batch#get` to `Ecoportal::API::V1::People#get_all`
43
123
 
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 ecoPortal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency "yard", ">= 0.9.18", "< 0.10"
29
29
  s.add_development_dependency "redcarpet", ">= 3.5.0", "< 3.6"
30
30
 
31
- s.add_dependency 'ecoportal-api', '>= 0.7.1', '< 0.8'
31
+ s.add_dependency 'ecoportal-api', '>= 0.7.2', '< 0.8'
32
32
  s.add_dependency 'ecoportal-api-oozes', '>= 0.7.2', '< 0.8'
33
33
  s.add_dependency 'aws-sdk-s3', '>= 1.64.0', '< 2'
34
34
  s.add_dependency 'aws-sdk-ses', '>= 1.29.0', '< 2'
@@ -7,7 +7,9 @@ module Eco
7
7
  end
8
8
 
9
9
  require_relative 'api/common'
10
+ require_relative 'api/custom'
10
11
  require_relative 'api/usecases'
12
+ require_relative 'api/microcases'
11
13
  require_relative 'api/policies'
12
14
  require_relative 'api/error'
13
15
  require_relative 'api/organization'
@@ -7,6 +7,10 @@ end
7
7
 
8
8
  require_relative 'common/version_patches'
9
9
  require_relative 'common/class_helpers'
10
+ require_relative 'common/class_auto_loader'
10
11
  require_relative 'common/class_hierarchy'
12
+ require_relative 'common/class_meta_basics'
13
+ require_relative 'common/base_loader'
14
+ require_relative 'common/loaders'
11
15
  require_relative 'common/session'
12
16
  require_relative 'common/people'
@@ -0,0 +1,54 @@
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
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,109 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ # Helpers for dynamic object loading based on class declaration
5
+ # @note
6
+ # - this helpers aim to boost the usage of the ruby language in complex api configurations.
7
+ module ClassAutoLoader
8
+ include Eco::API::Common::ClassHelpers
9
+
10
+ # To enable the class autoloader, you should use this method
11
+ def autoloads_children_of(klass)
12
+ class_resolver :autoloader_class, klass
13
+ @autoloaded_class = klass
14
+ end
15
+
16
+ # Resolves the class `autoloader_class` if it has been defined via `autoloads_children_of`
17
+ def autoloaded_class
18
+ return nil unless @autoloaded_class
19
+ autoloader_class
20
+ end
21
+
22
+ # To which restricted namespaces this class autoloads from
23
+ def autoloaded_namespaces(type = :include)
24
+ @autoloaded_namespaces ||= {}
25
+ @autoloaded_namespaces[type] ||= []
26
+ end
27
+
28
+ # To restrict which namespaces it is allowed to load from
29
+ def autoload_namespace(*namespaces)
30
+ _autoload_namespace(:include, *namespaces)
31
+ end
32
+
33
+ # To ignore certain namespaces this class should not autoload from
34
+ def autoload_namespace_ignore(*namespaces)
35
+ _autoload_namespace(:ignore, *namespaces)
36
+ end
37
+
38
+ def _autoload_namespace(type, *namespaces)
39
+ autoloaded_namespaces(type).concat(namespaces) unless namespaces.empty?
40
+ end
41
+
42
+ # @param constant [Class, String] a class or namespace we want to check auto-load entitlement thereof.
43
+ # @return [Boolean] determines if a given namespace is entitled for autoloading
44
+ def autoload_class?(constant)
45
+ constants = "#{constant}".split("::").compact
46
+ autoload = true
47
+ unless autoloaded_namespaces(:include).empty?
48
+ autoload = autoloaded_namespaces(:include).any? do |ns|
49
+ "#{ns}".split("::").compact.zip(constants).all? {|(r, c)| r == c}
50
+ end
51
+ end
52
+ unless autoloaded_namespaces(:ignore).empty?
53
+ autoload &&= autoloaded_namespaces(:ignore).none? do |ns|
54
+ "#{ns}".split("::").compact.zip(constants).all? {|(r, c)| r == c}
55
+ end
56
+ end
57
+ autoload
58
+ end
59
+
60
+ # As children are loaded as they are declared, we should not load twice same children.
61
+ def autoloaded_children
62
+ @auto_loaded_children ||= []
63
+ end
64
+
65
+ # Children classes of `autoloader_class` that have not been created an instance of.
66
+ def unloaded_children
67
+ return [] unless autoloaded_class
68
+ new_detected = new_classes
69
+ known_class!(*new_detected)
70
+ descendants(parent_class: autoloaded_class, scope: new_detected).select do |child_class|
71
+ !autoloaded_children.include?(child_class) && autoload_class?(child_class)
72
+ end.sort
73
+ end
74
+
75
+ # It loads/creates a new instance of children classes pending to be loaded.
76
+ # @return [Boolean] `true` if there were children loaded, `false` otherwise.
77
+ def autoload_children(object)
78
+ return false if !autoloaded_class || @loading_children
79
+ pending_children = unloaded_children
80
+ return false if pending_children.empty?
81
+ @loading_children = true
82
+ pending_children.each do |klass|
83
+ @child = klass.new(object)
84
+ autoloaded_children.push(klass)
85
+ end
86
+ @loading_children = false
87
+ true
88
+ end
89
+
90
+ # Known namespaces serves the purpose to discover recently added namespaces
91
+ # provided that the namespace discovery is optimized
92
+ def known_classes
93
+ @known_classes ||= []
94
+ end
95
+
96
+ # Add to known namespaces
97
+ def known_class!(*classes)
98
+ known_classes.concat(classes)
99
+ end
100
+
101
+ # List all new namespaces
102
+ def new_classes
103
+ ObjectSpace.each_object(::Class).to_a - known_classes
104
+ end
105
+
106
+ end
107
+ end
108
+ end
109
+ end
@@ -3,11 +3,14 @@ module Eco
3
3
  module Common
4
4
  module ClassHelpers
5
5
 
6
+ # Creates an class and instance object methods with name `name` to resolve `klass` name
6
7
  def class_resolver(name, klass)
7
8
  define_singleton_method(name) { resolve_class(klass) }
8
9
  define_method(name) { self.class.resolve_class(klass) }
9
10
  end
10
11
 
12
+ # With given a `klass` name it resolves to an actual `Class`
13
+ # @return [Class] the class that was being searched by name `klass`.
11
14
  def resolve_class(klass, exception: true)
12
15
  @resolved ||= {}
13
16
  @resolved[klass] ||=
@@ -59,6 +62,36 @@ module Eco
59
62
  end
60
63
  end
61
64
 
65
+ # Finds all child classes of the current class.
66
+ # @param parent_class [Class] the parent class we want to find children of.
67
+ # @param direct [Boolean] it will only include direct child classes.
68
+ # @param scope [nil, Array] to only look for descendants among the ones in `scope`.
69
+ # @return [Arrary<Class>] the child classes in hierarchy order.
70
+ def descendants(parent_class: self, direct: false, scope: nil)
71
+ scope ||= ObjectSpace.each_object(::Class)
72
+ return [] if scope.empty?
73
+ scope.select do |klass|
74
+ klass < parent_class
75
+ end.sort do |k1, k2|
76
+ next -1 if k2 < k1
77
+ next 1 if k1 < k2
78
+ 0
79
+ end.tap do |siblings|
80
+ if direct
81
+ siblings.reject! do |si|
82
+ siblings.any? {|s| si < s}
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ # @param parent_class [Class] the parent class we want to find children of.
89
+ # @param direct [Boolean] it will only include direct child classes.
90
+ # @return [Boolean] `true` if the current class has child classes, and `false` otherwise.
91
+ def descendants?(parent_class: self, direct: false)
92
+ descendants(parent_class: parent_class, direct: direct).length > 0
93
+ end
94
+
62
95
  end
63
96
  end
64
97
  end
@@ -19,7 +19,7 @@ module Eco
19
19
  end
20
20
 
21
21
  # Thanks to this step the format on the declaration of the model is flexible
22
- # @param value [Hash, Enumerable, String, Symbol, nil]
22
+ # @param model [Hash, Enumerable, String, Symbol, nil]
23
23
  # @return [Hash, nil] where keys are `Symbol` s
24
24
  def parse_model(model)
25
25
  case model
@@ -0,0 +1,16 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module ClassMetaBasics
5
+
6
+ # Helps to define methods and keep track on them
7
+ def define(name, &block)
8
+ name = name.to_sym
9
+ @helpers[name] = block
10
+ define_method(name.to_sym, &block)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module Loaders
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require_relative 'loaders/use_case'
11
+ require_relative 'loaders/policy'
12
+ require_relative 'loaders/error_handler'
13
+ require_relative 'loaders/parser'
@@ -0,0 +1,41 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module Loaders
5
+ class ErrorHandler < Eco::API::Common::BaseLoader
6
+
7
+ class << self
8
+ attr_writer :error
9
+
10
+ # @return [Eco::API::Error] the error class, child of `Eco::API::Error`.
11
+ def error(value = nil)
12
+ unless value
13
+ return @error || raise("You should specify an error type for #{self.class}")
14
+ end
15
+ @error = value
16
+ end
17
+ end
18
+
19
+ def initialize(handlers)
20
+ raise "Expected Eco::API::Policies. Given #{handlers.class}" unless handlers.is_a?(Eco::API::Error::Handlers)
21
+ handlers.on(self.error, &self.method(:main))
22
+ end
23
+
24
+ # @param people [Eco::API::Organization::People] the people in the queue of the current `job`
25
+ # @param session [Eco::API::Session] the current session where the usecase kicks in.
26
+ # @param options [Hash] the options that modify the case behaviour or bring some dependencies.
27
+ # @param handler [Eco::API::Error::Hanlder] the `error handler` instance object.
28
+ # @param job [Eco::API::Session::Batch::Job] the `Batch::Job` made on purpose for this handler.
29
+ def main(people, session, options, handler, job)
30
+ raise "You should implement this method"
31
+ end
32
+
33
+ def error
34
+ self.class.error
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end