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
@@ -23,7 +23,7 @@ module Eco
23
23
  # - if `data` is a `Person` object, its behaviour is `serialise`.
24
24
  # - if `data` is **not** a `Person` object, it does a `parse`.
25
25
  # - currently **in rework**, so there may be subtle differences that make it temporarily unstable (yet it is reliable).
26
- # @param data [Hash, Person] `Person` object to be serialized or hashed entry (note: `CSV::Row` is accepted).
26
+ # @param data [Hash, Ecoportal::API::V1::Person] `Person` object to be serialized or hashed entry to be parsed (note: `CSV::Row` is accepted).
27
27
  # @param person_parser [Common::People::PersonParser] parser/serializer of person attributes (it contains a set of attribute parsers).
28
28
  # @param attr_map [Eco::Data::Mapper] mapper to translate attribute names from _external_ to _internal_ names and _vice versa_.
29
29
  # @param logger [Common::Session::Logger, ::Logger] object to manage logs.
@@ -42,6 +42,7 @@ module Eco
42
42
  else # SERIALIZING
43
43
  @person = data
44
44
  @internal_attrs = @person_parser.all_attrs
45
+ @aliased_attrs = @attr_map.list(:internal)
45
46
  end
46
47
 
47
48
  @core_attrs = @person_parser.target_attrs_core(@internal_attrs)
@@ -53,7 +54,7 @@ module Eco
53
54
  # To know if currently the object is in parse or serialize mode.
54
55
  # @return [Boolean] returns `true` if we are **parsing**, `false` otherwise.
55
56
  def parsing?
56
- !@source.is_a?(Ecoportal::API::Internal::Person)
57
+ !@source.is_a?(Ecoportal::API::V1::Person)
57
58
  end
58
59
 
59
60
  # To know if currently the object is in parse or serialize mode.
@@ -9,6 +9,10 @@ module Eco
9
9
  # @attr_reader details_attrs [Array<String>] internal names of schema details attributes.
10
10
  # @attr_reader all_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
11
11
  class PersonParser
12
+ extend Eco::API::Common::ClassAutoLoader
13
+ autoloads_children_of "Eco::API::Common::Loaders::Parser"
14
+ autoload_namespace_ignore "Eco::API"
15
+
12
16
  CORE_ATTRS = ["id", "external_id", "email", "name", "supervisor_id", "filter_tags", "freemium"]
13
17
  ACCOUNT_ATTRS = ["policy_group_ids", "default_tag", "send_invites", "landing_page_id", "login_provider_ids"]
14
18
  TYPE = [:select, :text, :date, :number, :phone_number, :boolean, :multiple]
@@ -43,12 +47,19 @@ module Eco
43
47
  end
44
48
 
45
49
  @all_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
50
+ self.class.autoload_children(self)
46
51
  end
47
52
 
48
53
  def patched!
49
54
  @patch_version += 1
50
55
  end
51
56
 
57
+ def new(schema: nil)
58
+ self.class.new(schema: schema || self.schema).merge(self)
59
+ end
60
+
61
+ # @!group Scopping attributes (identifying, presence & active)
62
+
52
63
  # Scopes `source_attrs` using the _**core** attributes_.
53
64
  # @note use this helper to know which among your attributes are **core** ones.
54
65
  # @param source_attrs [Array<String>]
@@ -78,9 +89,9 @@ module Eco
78
89
 
79
90
  # Lists all defined attributes, types and formats.
80
91
  # @return [Array<String>] the list of defined parsers/serializers.
81
- #def list_defined
82
- # @parsers.keys
83
- #end
92
+ def defined_list
93
+ @parsers.keys
94
+ end
84
95
 
85
96
  # Returns a list of all the internal attributes of the model that have a parser defined.
86
97
  # @note
@@ -94,10 +105,19 @@ module Eco
94
105
  end
95
106
 
96
107
  # Returns a list of all the internal attributes of the model that have a parser defined & that should be active.
97
- # @param [Hash, Array<String>]
98
- # @return [Array<String>] list of all attribute defined parsers that should be active.
99
- def active_attrs(source_data)
100
- defined_attrs.select {|attr| @parsers[attr].parser_active?(source_data)}
108
+ # @param source_data [Hash, Array<String>] the data that we scope for parsing
109
+ # @param phase [Symbol] the phase when the attr parser is expected to be called.
110
+ # Can be [:internal, :final, :person]
111
+ # @param process [Symbol] either `:parse` or `:serialize`, depending if we want to parse or serialize the `attr`.
112
+ # @return [Array<String>] list of all attribute defined parsers that should be active for the given `source_data`.
113
+ def active_attrs(source_data, phase = :any, process: :parse)
114
+ defined_attrs.select do |attr|
115
+ if process == :serialize
116
+ @parsers[attr].serializer_active?(phase)
117
+ else
118
+ @parsers[attr].parser_active?(source_data, phase)
119
+ end
120
+ end
101
121
  end
102
122
 
103
123
  # Returns a list of all the internal attributes of the model that do **not** have a parser defined.
@@ -112,6 +132,9 @@ module Eco
112
132
  def defined?(attr)
113
133
  @parsers.key?(attr)
114
134
  end
135
+ # @!endgroup
136
+
137
+ # @!group Defining attributes
115
138
 
116
139
  # Helper to **merge** a set of parsers of another `PersonParser` into the current object.
117
140
  # @note if there are parsers with same name, it **overrides** the ones of the current object with them.
@@ -120,12 +143,11 @@ module Eco
120
143
  def merge(parser)
121
144
  return self if !parser
122
145
  raise "Expected a PersonParser object. Given #{parser}" if !parser.is_a?(PersonParser)
123
- @parsers.merge!(parser.hash)
146
+ to_h.merge!(parser.to_h)
124
147
  patched!
125
148
  self
126
149
  end
127
150
 
128
-
129
151
  # Helper to define and associate a parser/serializer to a type or attribute.
130
152
  # @raise [Exception] if trying to define a parser/serializer for:
131
153
  # - an unkown attribute (`String`)
@@ -136,7 +158,7 @@ module Eco
136
158
  # @yieldparam parser [Eco::Language::Models::ParserSerializer] parser to define.
137
159
  # @return [Eco::API::Common::People::PersonParser] the current object (to ease chainig).
138
160
  def define_attribute(attr, dependencies: {}, &definition)
139
- if !valid?(attr)
161
+ unless valid?(attr)
140
162
  msg = "The attribute '#{attr_to_str(attr)}' is not part of core, account or target schema, or does not match any type: #{@details_attrs}"
141
163
  raise msg
142
164
  end
@@ -147,6 +169,9 @@ module Eco
147
169
  patched!
148
170
  self
149
171
  end
172
+ # @!endgroup
173
+
174
+ # @!group Launching parser/serializer
150
175
 
151
176
  # Call to parser `source` value of attribute or type `attr` into an internal valid value.
152
177
  # @note dependencies introduced on `parse` call will be merged with those defined during the
@@ -154,11 +179,13 @@ module Eco
154
179
  # @raise [Exception] if there is **no** parser for attribute or type `attr`.
155
180
  # @param attr [String] target attribute or type to **parse**.
156
181
  # @param source [Any] source value to be parsed.
182
+ # @param phase [Symbol] the phase when the attr parser is expected to be called.
183
+ # Must be [:internal, :final]
157
184
  # @param deps [Hash] key-value pairs of call dependencies.
158
185
  # @return [Any] a valid internal value.
159
- def parse(attr, source, deps: {})
186
+ def parse(attr, source, phase = :internal, deps: {})
160
187
  raise "There is no parser for attribute '#{attr}'" if !self.defined?(attr)
161
- @parsers[attr].parse(source, dependencies: deps)
188
+ @parsers[attr].parse(source, phase, dependencies: deps)
162
189
  end
163
190
 
164
191
  # Call to serialise `object` value of attribute or type `attr` into an external valid value.
@@ -167,26 +194,32 @@ module Eco
167
194
  # @raise [Exception] if there is **no** serialiser for attribute or type `attr`.
168
195
  # @param attr [String] target attribute or type to **serialize**.
169
196
  # @param object [Any] object value to be serialized.
197
+ # @param phase [Symbol] the phase when the attr serializer is expected to be called.
198
+ # Must be [:internal, :final, :person]
170
199
  # @param deps [Hash] key-value pairs of call dependencies.
171
200
  # @return a valid external value.
172
- def serialize(attr, object, deps: {})
201
+ def serialize(attr, object, phase = :person, deps: {})
173
202
  raise "There is no parser for attribute '#{attr}'" if !self.defined?(attr)
174
- @parsers[attr].serialize(object, dependencies: deps)
203
+ @parsers[attr].serialize(object, phase, dependencies: deps)
175
204
  end
205
+ # @!endgroup
176
206
 
177
207
  protected
178
208
 
179
209
  # @return [Hash] attr-parser pairs with all the defined type and attribute parsers/serializers.
180
- def hash
210
+ def to_h
211
+ self.class.autoload_children(self)
181
212
  @parsers
182
213
  end
183
214
 
184
215
  private
185
216
 
217
+ # Some attribute parsers are **inactive**, and therefore out of scope
218
+ # @param source_attrs [Array<String>] the attrs we want to filter from to only those in scope.
219
+ # @param section_attrs [Array<String>] the attrs of reference to scope `source_attrs`.
220
+ # @return [Array<String>] the `source_attrs` in `section_attrs` + the `section_attrs` with active parser
186
221
  def scoped_attrs(source_attrs, section_attrs)
187
- direct_attrs = source_attrs & section_attrs
188
- parsed_attrs = active_attrs(source_attrs) & section_attrs
189
- (source_attrs + parsed_attrs) & (direct_attrs + parsed_attrs)
222
+ (source_attrs | active_attrs(source_attrs)) & section_attrs
190
223
  end
191
224
 
192
225
  def attr_to_str(attr)
@@ -28,6 +28,10 @@ module Eco
28
28
  end
29
29
  end
30
30
 
31
+ def level=(value)
32
+ @console_logger.level = value
33
+ end
34
+
31
35
  def debug(*args, &block)
32
36
  log(:debug, *args, &block)
33
37
  end
@@ -1,7 +1,9 @@
1
1
  module Ecoportal
2
2
  module API
3
3
  class V1
4
+ # @attr entry [Eco::API::Common::People::PersonEntry, Hash] the input entry plain hash data used to update/create this person.
4
5
  class Person
6
+ attr_accessor :entry
5
7
 
6
8
  def reset_details!
7
9
  doc["details"] = JSON.parse(original_doc["details"])
@@ -16,7 +16,7 @@ module Ecoportal
16
16
  end
17
17
 
18
18
  def account_added?
19
- person.account && !initial_doc["account"]
19
+ account && !initial_doc["account"]
20
20
  end
21
21
 
22
22
  end
@@ -6,3 +6,25 @@ class ::Exception
6
6
  msg.join("\n")
7
7
  end
8
8
  end
9
+
10
+ # To extend an exception message preserving same exception object
11
+ # @see https://stackoverflow.com/a/30133010/4352306
12
+ Exception.class_eval do
13
+ def prepend_message(message)
14
+ mod = Module.new do
15
+ define_method :to_s do
16
+ String(message) + super()
17
+ end
18
+ end
19
+ self.extend mod
20
+ end
21
+
22
+ def append_message(message)
23
+ mod = Module.new do
24
+ define_method :to_s do
25
+ super() + String(message)
26
+ end
27
+ end
28
+ self.extend mod
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Eco
2
+ module API
3
+ # Set of helper classes to boost configuration easiness
4
+ module Custom
5
+ end
6
+ end
7
+ end
8
+
9
+ require_relative 'custom/namespace'
10
+ require_relative 'custom/use_case'
11
+ require_relative 'custom/policy'
12
+ require_relative 'custom/error_handler'
13
+ require_relative 'custom/parser'
@@ -0,0 +1,20 @@
1
+ # Helper class to create a custom `ErrorHandler`
2
+ # @example Example of usage:
3
+ # class Custom::ErrorHandler::EmailTaken < Eco::API::Custom::ErrorHandler
4
+ # error Eco::API::Error::EmailTaken
5
+ #
6
+ # def main(people, session, options, handler, job)
7
+ # people.each do |person|
8
+ # prev_email = person.initial_doc["email"]
9
+ # if person.email != prev_email
10
+ # person.email = prev_email
11
+ # else
12
+ # person.account = nil
13
+ # end
14
+ # job.add(person)
15
+ # end
16
+ # end
17
+ # end
18
+ #
19
+ class Eco::API::Custom::ErrorHandler < Eco::API::Common::Loaders::ErrorHandler
20
+ end
@@ -0,0 +1,7 @@
1
+ # Provides a namespace to declare custom policies, usecases and handlers
2
+ module Custom
3
+ module UseCase; end
4
+ module Policy; end
5
+ module ErrorHandler; end
6
+ module Parser; end
7
+ end
@@ -0,0 +1,50 @@
1
+ # Helper class to create a custom `Parser`
2
+ # @example Example of usage:
3
+ # class Custom::Parser::LoginProviders < Eco::API::Custom::Parser
4
+ # attribute "login_provider_ids"
5
+ #
6
+ # active_when_any "some-field1", "some-field2" # optional
7
+ # parsing_phase :final # optional, default is (default :internal)
8
+ # serializing_phase :final # optional, it will be (default :person)
9
+ #
10
+ # def parser(hash, deps)
11
+ # get_values(hash).map do |name|
12
+ # login_providers.to_id(name&.downcase.strip)
13
+ # end.compact
14
+ # end
15
+ #
16
+ # def serializer(hash, deps)
17
+ # if ids = hash["login_provider_ids"]
18
+ # login_providers.to_name(ids)
19
+ # else
20
+ # []
21
+ # end
22
+ # end
23
+ #
24
+ # private
25
+ #
26
+ # def get_values(hash)
27
+ # value, field1, field2 = hash.values_at("login_provider_ids", "some-field1", "some-field2")
28
+ # return value if value # at the :final parsing phase, login_provider_ids is already an Array
29
+ # some_logics(field1, field2)
30
+ # end
31
+ #
32
+ # def some_logics(a, b)
33
+ # case a
34
+ # when "staff"
35
+ # ["Company SSO"]
36
+ # when "contractor"
37
+ # ["Password"]
38
+ # elsif b
39
+ # return ["Password"] if b.end_with?("Owner")
40
+ # ["Password", "Company SSO 2"]
41
+ # end
42
+ # end
43
+ #
44
+ # def login_providers
45
+ # @login_providers ||= ASSETS.config.login_providers
46
+ # end
47
+ #
48
+ # end
49
+ class Eco::API::Custom::Parser < Eco::API::Common::Loaders::Parser
50
+ end
@@ -0,0 +1,28 @@
1
+ # Helper class to create a custom `Policy`
2
+ # @example Example of usage:
3
+ # class Custom::Policy::StartersNLeavers < Eco::API::Custom::Policy
4
+ # name "starters'n'leavers"
5
+ #
6
+ # INACTIVE = "Non active"
7
+ #
8
+ # def main(people, session, options, policy, job)
9
+ # people.each do |person|
10
+ # next unless details = person.details
11
+ # # starters
12
+ # if person.new?
13
+ # details["status"] = "Active"
14
+ # details["hris-managed"] = true unless options.dig(:include, :excluded)
15
+ # end
16
+ #
17
+ # # leavers: native job queue to remove account
18
+ # if job.name == "leavers"
19
+ # details["status"] = INACTIVE
20
+ # person.external_id = person.name
21
+ # details["staff-id"] = person.name
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # end
27
+ class Eco::API::Custom::Policy < Eco::API::Common::Loaders::Policy
28
+ end
@@ -0,0 +1,16 @@
1
+ # Helper class to create a custom `UseCase`
2
+ # @example Example of usage:
3
+ # class Custom::UseCase::Sync < Eco::API::Custom::UseCase
4
+ # name "custom-case"
5
+ # type :sync
6
+ #
7
+ # def main(entries, people, session, options, usecase)
8
+ # update = session.new_job("main", "update", :update, usecase)
9
+ # session.micro.with_each(entries, people, options) do |entry, person|
10
+ # # update some data in person using data from entry
11
+ # end
12
+ # end
13
+ #
14
+ # end
15
+ class Eco::API::Custom::UseCase < Eco::API::Common::Loaders::UseCase
16
+ end
@@ -13,6 +13,7 @@ module Eco
13
13
  @match = /.*/
14
14
  #RxValidId = /[a-f0-9]{24}/
15
15
 
16
+
16
17
  class Unclassified < Eco::API::Error
17
18
  @str_error = "Unclassified error message"
18
19
  @match = /.*/
@@ -2,12 +2,14 @@ module Eco
2
2
  module API
3
3
  class Error
4
4
  class Handlers < Eco::API::UseCases
5
+ autoloads_children_of "Eco::API::Common::Loaders::ErrorHandler"
6
+ autoload_namespace_ignore "Eco::API"
5
7
 
6
- def add(handler)
7
- raise "Expected Eco::API::Error::Handler object. Given: #{policy}" unless handler.is_a?(Eco::API::Error::Handler)
8
- super(handler)
8
+ def define(*args)
9
+ raise "Missusage. You should use 'on' method instead"
9
10
  end
10
11
 
12
+ # @param klass_err [Eco::API::Error] the specific error class that triggers this handler.
11
13
  def on(klass_err, type: :error_handler, retry: true, &block)
12
14
  Eco::API::Error.validate_err_class(klass_err)
13
15
  raise "Expected block but not given" unless block
@@ -16,6 +18,11 @@ module Eco
16
18
  end
17
19
  end
18
20
 
21
+ def add(handler)
22
+ raise "Expected Eco::API::Error::Handler object. Given: #{policy}" unless handler.is_a?(Eco::API::Error::Handler)
23
+ super(handler)
24
+ end
25
+
19
26
  end
20
27
  end
21
28
  end
@@ -1,17 +1,6 @@
1
1
  module Eco
2
2
  module API
3
3
  class MicroCases < Eco::API::Common::Session::BaseSession
4
- class << self
5
- def define(name, &block)
6
- name = name.to_sym
7
- @helpers[name] = block
8
- define_method(name.to_sym, &block)
9
- end
10
- end
11
-
12
- def define(*args)
13
- self.class.define(*args)
14
- end
15
4
 
16
5
  def micro
17
6
  self
@@ -21,11 +10,26 @@ module Eco
21
10
  end
22
11
  end
23
12
 
13
+ require_relative 'microcases/account_excluded'
14
+ require_relative 'microcases/append_usergroups'
24
15
  require_relative 'microcases/core_excluded'
16
+ require_relative 'microcases/fix_default_group'
25
17
  require_relative 'microcases/fix_filter_tags'
18
+ require_relative 'microcases/people_cache'
19
+ require_relative 'microcases/people_load'
20
+ require_relative 'microcases/people_refresh'
21
+ require_relative 'microcases/people_search'
22
+ require_relative 'microcases/refresh_abilities'
26
23
  require_relative 'microcases/set_account'
24
+ require_relative 'microcases/set_core_with_supervisor'
27
25
  require_relative 'microcases/set_core'
28
- require_relative 'microcases/set_default_group'
29
- require_relative 'microcases/set_default_tag'
26
+ require_relative 'microcases/refresh_default_tag'
30
27
  require_relative 'microcases/set_supervisor'
31
28
  require_relative 'microcases/strict_search'
29
+ require_relative 'microcases/s3upload_targets'
30
+ require_relative 'microcases/with_each'
31
+ require_relative 'microcases/with_each_leaver'
32
+ require_relative 'microcases/with_each_present'
33
+ require_relative 'microcases/with_each_starter'
34
+ require_relative 'microcases/with_each_subordinate'
35
+ require_relative 'microcases/with_supervisor'