eco-helpers 1.5.0 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +147 -2
  3. data/LICENSE +21 -0
  4. data/eco-helpers.gemspec +11 -10
  5. data/lib/eco/api.rb +3 -0
  6. data/lib/eco/api/common.rb +5 -1
  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 +5 -10
  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 +20 -0
  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 +31 -0
  26. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
  27. data/lib/eco/api/common/people/entries.rb +54 -24
  28. data/lib/eco/api/common/people/entry_factory.rb +18 -15
  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 +5 -2
  32. data/lib/eco/api/common/people/person_parser.rb +52 -19
  33. data/lib/eco/api/common/session/base_session.rb +3 -6
  34. data/lib/eco/api/common/session/environment.rb +2 -23
  35. data/lib/eco/api/common/session/logger.rb +4 -0
  36. data/lib/eco/api/common/version_patches.rb +1 -0
  37. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
  38. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +9 -1
  39. data/lib/eco/api/common/version_patches/exception.rb +22 -0
  40. data/lib/eco/api/common/version_patches/object.rb +10 -0
  41. data/lib/eco/api/custom.rb +13 -0
  42. data/lib/eco/api/custom/error_handler.rb +20 -0
  43. data/lib/eco/api/custom/namespace.rb +7 -0
  44. data/lib/eco/api/custom/parser.rb +50 -0
  45. data/lib/eco/api/custom/policy.rb +28 -0
  46. data/lib/eco/api/custom/use_case.rb +16 -0
  47. data/lib/eco/api/error.rb +1 -0
  48. data/lib/eco/api/error/handlers.rb +10 -3
  49. data/lib/eco/api/microcases.rb +35 -0
  50. data/lib/eco/api/microcases/account_excluded.rb +24 -0
  51. data/lib/eco/api/microcases/append_usergroups.rb +19 -0
  52. data/lib/eco/api/microcases/core_excluded.rb +20 -0
  53. data/lib/eco/api/microcases/fix_default_group.rb +34 -0
  54. data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
  55. data/lib/eco/api/microcases/people_cache.rb +17 -0
  56. data/lib/eco/api/microcases/people_load.rb +59 -0
  57. data/lib/eco/api/microcases/people_refresh.rb +31 -0
  58. data/lib/eco/api/microcases/people_search.rb +65 -0
  59. data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
  60. data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
  61. data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
  62. data/lib/eco/api/microcases/set_account.rb +20 -0
  63. data/lib/eco/api/microcases/set_core.rb +18 -0
  64. data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
  65. data/lib/eco/api/microcases/set_supervisor.rb +30 -0
  66. data/lib/eco/api/microcases/strict_search.rb +19 -0
  67. data/lib/eco/api/microcases/with_each.rb +27 -0
  68. data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
  69. data/lib/eco/api/microcases/with_each_present.rb +30 -0
  70. data/lib/eco/api/microcases/with_each_starter.rb +30 -0
  71. data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
  72. data/lib/eco/api/microcases/with_supervisor.rb +36 -0
  73. data/lib/eco/api/organization/people.rb +72 -35
  74. data/lib/eco/api/organization/presets_factory.rb +13 -4
  75. data/lib/eco/api/organization/presets_values.json +1 -0
  76. data/lib/eco/api/policies.rb +11 -7
  77. data/lib/eco/api/session.rb +62 -29
  78. data/lib/eco/api/session/batch.rb +2 -45
  79. data/lib/eco/api/session/batch/base_policy.rb +7 -6
  80. data/lib/eco/api/session/batch/errors.rb +28 -4
  81. data/lib/eco/api/session/batch/feedback.rb +7 -1
  82. data/lib/eco/api/session/batch/job.rb +40 -23
  83. data/lib/eco/api/session/batch/jobs.rb +9 -4
  84. data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
  85. data/lib/eco/api/session/batch/request_stats.rb +95 -58
  86. data/lib/eco/api/session/batch/status.rb +35 -31
  87. data/lib/eco/api/session/config.rb +106 -44
  88. data/lib/eco/api/session/config/api.rb +132 -7
  89. data/lib/eco/api/session/config/apis.rb +24 -25
  90. data/lib/eco/api/session/config/logger.rb +2 -2
  91. data/lib/eco/api/session/config/post_launch.rb +1 -1
  92. data/lib/eco/api/session/config/workflow.rb +8 -7
  93. data/lib/eco/api/usecases.rb +47 -33
  94. data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
  95. data/lib/eco/api/usecases/backup/create_case.rb +104 -0
  96. data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
  97. data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
  98. data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
  99. data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
  100. data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
  101. data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
  102. data/lib/eco/api/usecases/backup/update_case.rb +112 -0
  103. data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
  104. data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
  105. data/lib/eco/api/usecases/base_case.rb +2 -0
  106. data/lib/eco/api/usecases/base_io.rb +3 -3
  107. data/lib/eco/api/usecases/default_cases.rb +23 -53
  108. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
  109. data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
  110. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
  111. data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
  112. data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
  113. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
  114. data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
  115. data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
  116. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
  117. data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
  118. data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
  119. data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
  120. data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
  121. data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
  122. data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
  123. data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
  124. data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
  125. data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
  126. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
  127. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
  128. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
  129. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
  130. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
  131. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
  132. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
  133. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
  134. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
  135. data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
  136. data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
  137. data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
  138. data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
  139. data/lib/eco/api/usecases/use_case_io.rb +9 -9
  140. data/lib/eco/cli/config.rb +10 -2
  141. data/lib/eco/cli/config/default.rb +2 -1
  142. data/lib/eco/cli/config/default/input_filters.rb +58 -0
  143. data/lib/eco/cli/config/default/options.rb +60 -25
  144. data/lib/eco/cli/config/default/people.rb +4 -4
  145. data/lib/eco/cli/config/default/people_filters.rb +108 -0
  146. data/lib/eco/cli/config/default/usecases.rb +69 -32
  147. data/lib/eco/cli/config/default/workflow.rb +37 -27
  148. data/lib/eco/cli/config/filters.rb +50 -0
  149. data/lib/eco/cli/config/filters/input_filters.rb +29 -0
  150. data/lib/eco/cli/config/filters/people_filters.rb +29 -0
  151. data/lib/eco/cli/config/help.rb +49 -0
  152. data/lib/eco/cli/config/options_set.rb +17 -1
  153. data/lib/eco/cli/config/use_cases.rb +79 -53
  154. data/lib/eco/cli/scripting.rb +10 -2
  155. data/lib/eco/cli/scripting/args_helpers.rb +25 -15
  156. data/lib/eco/cli/scripting/argument.rb +1 -0
  157. data/lib/eco/cli/scripting/arguments.rb +1 -1
  158. data/lib/eco/csv/table.rb +1 -1
  159. data/lib/eco/data/crypto/encryption.rb +3 -0
  160. data/lib/eco/language/match.rb +19 -9
  161. data/lib/eco/language/match_modifier.rb +13 -5
  162. data/lib/eco/language/models/collection.rb +77 -56
  163. data/lib/eco/language/models/parser_serializer.rb +39 -15
  164. data/lib/eco/version.rb +1 -1
  165. metadata +149 -62
  166. data/lib/eco/api/session/task.rb +0 -175
  167. data/lib/eco/api/usecases/default_case.rb +0 -19
  168. data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
  169. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -98
  170. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
  171. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
  172. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
  173. data/lib/eco/cli/config/default/filters.rb +0 -70
  174. data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -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
@@ -0,0 +1,127 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module Loaders
5
+ class Parser < Eco::API::Common::BaseLoader
6
+
7
+ class << self
8
+ attr_reader :active_when
9
+
10
+ # @param value [String, Symbol] the attribute or type to be parsed/serialized
11
+ # 1. when `String`: the internal name of the field/attribute this parser/serializer manages for.
12
+ # 2. when `Symbol`: the type of data this parser converts between `String` and the specific type.
13
+ # @return [String] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`)
14
+ def attribute(value = nil)
15
+ unless value
16
+ return @attribute || raise("You should specify the 'attribute' this parser/serializer, #{self.class}, is linked to")
17
+ end
18
+ name value
19
+ @attribute = value
20
+ end
21
+
22
+ # Some parsers require dependencies to do their job.
23
+ def dependencies(value = nil)
24
+ @dependencies ||= {}
25
+ return @dependencies unless value
26
+ @dependencies = value
27
+ end
28
+
29
+ # Define or get the `phase` that the `parser` kicks in.
30
+ # @param phase [Symbol] the phase when this parser should be active.
31
+ # Must be one of [`:internal`, `:final`]
32
+ def parsing_phase(phase = nil)
33
+ @parsing_phase ||= :internal
34
+ return @parsing_phase unless phase
35
+ @parsing_phase = phase
36
+ end
37
+
38
+ # Define or get the `phase` that the `serializer` kicks in.
39
+ # @param phase [Symbol] the phase when this serializer should be active.
40
+ # Must be one of [`:person,` `:final`, `:internal`]
41
+ def serializing_phase(phase = nil)
42
+ @serializing_phase ||= :person
43
+ return @serializing_phase unless phase
44
+ @serializing_phase = phase
45
+ end
46
+
47
+ # Helper to build the `active_when` condition.
48
+ def active_when_any(*attrs)
49
+ @active_when = Proc.new do |source_data|
50
+ keys = data_keys(source_data)
51
+ attrs.any? {|key| keys.include?(key)}
52
+ end
53
+ end
54
+
55
+ # Helper to build the `active_when` condition.
56
+ def active_when_all(*attrs)
57
+ @active_when = Proc.new do |source_data|
58
+ keys = data_keys(source_data)
59
+ attrs.all? {|key| keys.include?(key)}
60
+ end
61
+ end
62
+
63
+ # Helper to obtain the current internal named attributes of the data
64
+ # @param source_data [Array<String>, Hash] if `Array` those are already the `keys`, if `Hash` it gets the `keys`
65
+ # @return [Array<String>] `keys` of `source_data`
66
+ def data_keys(source_data)
67
+ case source_data
68
+ when Array
69
+ keys = source_data
70
+ when Hash
71
+ keys = source_data.keys
72
+ else
73
+ keys = []
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ def initialize(person_parser)
80
+ raise "Expected Eco::API::Common::People::PersonParser. Given #{policies.class}" unless person_parser.is_a?(Eco::API::Common::People::PersonParser)
81
+ person_parser.define_attribute(self.attribute, dependencies: self.class.dependencies) do |attr_parser|
82
+ _define_parser(attr_parser)
83
+ _define_serializer(attr_parser)
84
+ end
85
+ end
86
+
87
+ # @param data [Hash] all the person data at the specified `parsing_phase`:
88
+ # - when `:internal`: the parser will receive external types (i.e. String with '|' delimiters instead of an Array).
89
+ # - when `:final`: the parser will receive the typed values (i.e. Array instread of String with '|' delimiters).
90
+ # @param deps [Hash] the merged dependencies (default to the class object and when calling the parser).
91
+ def parser(data, deps)
92
+ raise "You should implement this method"
93
+ end
94
+
95
+ # @param data [Hash, Ecoportal::API::V1::Person] all the person data at the specified `serializing_phase`:
96
+ # - when `:internal`: it will receive a `Hash` with the **internal values** but the types already serialized to `String`.
97
+ # - when `:final`: it will receive a `Hash` with the **internal values** and **types**.
98
+ # - when `:person`: it will receive the `person` object.
99
+ # @param deps [Hash] the merged dependencies (default to the class object and when calling the parser).
100
+ def seralizer(data, deps)
101
+ raise "You should implement this method"
102
+ end
103
+
104
+ # @return [String, Symbol] the field/attribute or type this parser is linked to.
105
+ def attribute
106
+ self.class.attribute
107
+ end
108
+
109
+ private
110
+
111
+ def _define_parser(attr_parser)
112
+ if active_when = self.class.active_when
113
+ attr_parser.def_parser(self.class.parsing_phase, active_when: active_when, &self.method(:parser))
114
+ else
115
+ attr_parser.def_parser(self.class.parsing_phase, &self.method(:parser))
116
+ end
117
+ end
118
+
119
+ def _define_serializer(attr_parser)
120
+ attr_parser.def_serializer(self.class.serializing_phase, &self.method(:serializer))
121
+ end
122
+
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,25 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module Loaders
5
+ class Policy < Eco::API::Common::BaseLoader
6
+
7
+ def initialize(policies)
8
+ raise "Expected Eco::API::Policies. Given #{policies.class}" unless policies.is_a?(Eco::API::Policies)
9
+ policies.define(self.name, &self.method(:main))
10
+ end
11
+
12
+ # @param people [Eco::API::Organization::People] the people in the queue of the current `job`
13
+ # @param session [Eco::API::Session] the current session where the usecase kicks in.
14
+ # @param options [Hash] the options that modify the case behaviour or bring some dependencies.
15
+ # @param policy [Eco::API::Policies::Policy] the `policy` instance object.
16
+ # @param job [Eco::API::Session::Batch::Job] the `Batch::Job` that these `people` belong to the queue thereof.
17
+ def main(people, session, options, policy, job)
18
+ raise "You should implement this method"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module Loaders
5
+ class UseCase < Eco::API::Common::BaseLoader
6
+
7
+ class << self
8
+ # @return [Symbol] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`)
9
+ def type(value = nil)
10
+ unless value
11
+ return @type || raise("You should specify a type of case [:sync, :transform, :import, :other] for #{self.class}")
12
+ end
13
+ @type = value
14
+ end
15
+ end
16
+
17
+ def initialize(usecases)
18
+ raise "Expected Eco::API::UseCases. Given #{usecases.class}" unless usecases.is_a?(Eco::API::UseCases)
19
+ usecases.define(self.name, type: self.type, &self.method(:main))
20
+ end
21
+
22
+ # The parameters of this method will depend on the `type` of usecase.
23
+ # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
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 usecase [Eco::API::Policies::Policy] the `usecase` instance object.
28
+ def main(entries, people, session, options, usecase)
29
+ raise "You should implement this method"
30
+ end
31
+
32
+ def type
33
+ self.class.type
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -5,6 +5,8 @@ module Eco
5
5
 
6
6
  # Class to define a set of default attribute parsers
7
7
  class DefaultParsers < PersonParser
8
+ autoloads_children_of "Eco::API::Common::Loaders::Parser"
9
+ autoload_namespace "Eco::API::Common::People::DefaultParsers"
8
10
 
9
11
  def initialize(*args)
10
12
  super(*args)
@@ -24,16 +26,6 @@ module Eco
24
26
  end.compact.to_h
25
27
 
26
28
  SelectParser.new(self, select_hashes: select_hashes).process
27
- BooleanParser.new(self).process
28
- NumericParser.new(self).process
29
- DateParser.new(self).process
30
- MultiParser.new(self).process
31
-
32
- # ALWAYS PRESENT FIELDS
33
- SendInvitesParser.new(self).process
34
-
35
- # FORMAT PARSER
36
- CSVParser.new(self).process
37
29
  end
38
30
 
39
31
  end
@@ -48,4 +40,7 @@ require_relative 'default_parsers/numeric_parser'
48
40
  require_relative 'default_parsers/date_parser'
49
41
  require_relative 'default_parsers/multi_parser'
50
42
  require_relative 'default_parsers/send_invites_parser'
43
+ require_relative 'default_parsers/freemium_parser'
44
+ require_relative 'default_parsers/policy_groups_parser'
45
+ require_relative 'default_parsers/login_providers_parser'
51
46
  require_relative 'default_parsers/csv_parser'
@@ -1,28 +1,18 @@
1
- module Eco
2
- module API
3
- module Common
4
- module People
5
- class DefaultParsers
6
- class BooleanParser < People::BaseParser
1
+ class Eco::API::Common::People::DefaultParsers::BooleanParser < Eco::API::Common::Loaders::Parser
2
+ attribute :boolean
7
3
 
8
- def process
9
- @parsers.define_attribute(:boolean) do |parser|
10
- parser.def_parser do |value|
11
- value.is_a?(Array) ? value.map { |v| truthy(v) } : truthy(value)
12
- end.def_serializer do |value|
13
- value.to_s
14
- end
15
- end
16
- end
4
+ def parser(value, deps)
5
+ value.is_a?(Array) ? value.map { |v| truthy(v) } : truthy(value)
6
+ end
7
+
8
+ def serializer(value, deps)
9
+ value.to_s
10
+ end
17
11
 
18
- private
12
+ private
19
13
 
20
- def truthy (value)
21
- %w[true y yes x].include?(value.to_s.strip.downcase)
22
- end
23
- end
24
- end
25
- end
26
- end
14
+ def truthy (value)
15
+ %w[true y yes x].include?(value.to_s.strip.downcase)
27
16
  end
17
+
28
18
  end
@@ -1,41 +1,26 @@
1
- module Eco
2
- module API
3
- module Common
4
- module People
5
- class DefaultParsers
6
- class CSVParser < People::BaseParser
1
+ class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Loaders::Parser
2
+ attribute :csv
7
3
 
8
- def process
9
- @parsers.define_attribute(:csv, dependencies: @options) do |parser|
10
- parser.def_parser do |data, deps|
11
- arr_hash = []
12
- CSV.parse(data, headers: true, skip_blanks: true).reject do |row|
13
- values = row.to_hash.values
14
- values.all?(&:nil?) || values.map(&:to_s).all?(&:empty?)
15
- end.each do |row|
16
- row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
17
- value = row[attr]
18
- hash[attr] = value.to_s.empty?? nil : value
19
- end
20
- arr_hash.push(row_hash)
21
- end
22
- arr_hash
23
- end.def_serializer do |array_hash, deps|
24
- arr_rows = []
25
- unless array_hash.empty?
26
- header = array_hash.first.keys
27
- arr_rows = array_hash.map do |csv_row|
28
- CSV::Row.new(header, csv_row.values_at(*header))
29
- end
30
- end
31
- CSV::Table.new(arr_rows).to_csv
32
- end
33
- end
34
- end
4
+ def parser(data, deps)
5
+ Eco::CSV.parse(data, headers: true, skip_blanks: true).each_with_object([]) do |row, arr_hash|
6
+ row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
7
+ next if attr.to_s.strip.empty?
8
+ value = row[attr]
9
+ hash[attr.strip] = value.to_s.empty?? nil : value
10
+ end
11
+ arr_hash.push(row_hash)
12
+ end
13
+ end
35
14
 
36
- end
37
- end
15
+ def serializer(array_hash, deps)
16
+ arr_rows = []
17
+ unless array_hash.empty?
18
+ header = array_hash.first.keys
19
+ arr_rows = array_hash.map do |csv_row|
20
+ CSV::Row.new(header, csv_row.values_at(*header))
38
21
  end
39
22
  end
23
+ CSV::Table.new(arr_rows).to_csv
40
24
  end
25
+
41
26
  end
@@ -1,33 +1,22 @@
1
- module Eco
2
- module API
3
- module Common
4
- module People
5
- class DefaultParsers
6
- class DateParser < People::BaseParser
1
+ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::Loaders::Parser
2
+ attribute :date
7
3
 
8
- def process
9
- @parsers.define_attribute(:date) do |parser|
10
- parser.def_parser do |value|
11
- value.is_a?(Array) ? value.map { |v| parse_date(v) } : parse_date(value)
12
- end.def_serializer do |value|
13
- value.is_a?(Array) ? value.map { |d| d && d.strftime('%Y-%m-%d') } : value && value.strftime('%Y-%m-%d')
14
- end
15
- end
16
- end
4
+ def parser(value, deps)
5
+ value.is_a?(Array) ? value.map { |v| parse_date(v) } : parse_date(value)
6
+ end
17
7
 
18
- private
8
+ def serializer(value, deps)
9
+ value.is_a?(Array) ? value.map { |d| d && d.strftime('%Y-%m-%d') } : value && value.strftime('%Y-%m-%d')
10
+ end
19
11
 
20
- def parse_date(value)
21
- begin
22
- (value.to_s.empty?) ? nil : Date.parse(value)
23
- rescue
24
- nil
25
- end
26
- end
12
+ private
27
13
 
28
- end
29
- end
30
- end
14
+ def parse_date(value)
15
+ begin
16
+ (value.to_s.empty?) ? nil : Date.parse(value)
17
+ rescue
18
+ nil
31
19
  end
32
20
  end
21
+
33
22
  end