eco-helpers 3.0.4 → 3.0.6

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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +44 -4
  4. data/eco-helpers.gemspec +1 -1
  5. data/lib/eco/api/common/class_helpers.rb +24 -23
  6. data/lib/eco/api/common/class_meta_basics.rb +0 -2
  7. data/lib/eco/api/common/loaders/use_case.rb +1 -0
  8. data/lib/eco/api/common/people/entry_factory.rb +6 -4
  9. data/lib/eco/api/common/people/person_entry.rb +4 -6
  10. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +25 -12
  11. data/lib/eco/api/common/people/person_parser.rb +8 -0
  12. data/lib/eco/api/common/session/base_session.rb +1 -1
  13. data/lib/eco/api/common/session/environment.rb +7 -0
  14. data/lib/eco/api/common/session/file_manager.rb +15 -8
  15. data/lib/eco/api/common/session/logger/cache.rb +14 -10
  16. data/lib/eco/api/common/session/logger/log.rb +8 -7
  17. data/lib/eco/api/common/session/mailer.rb +22 -13
  18. data/lib/eco/api/common/session/s3_uploader.rb +29 -20
  19. data/lib/eco/api/microcases/people_search.rb +1 -1
  20. data/lib/eco/api/organization/login_providers.rb +11 -4
  21. data/lib/eco/api/organization/node_classifications.rb +3 -0
  22. data/lib/eco/api/organization/presets_factory.rb +37 -31
  23. data/lib/eco/api/organization/tag_tree.rb +14 -5
  24. data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +28 -18
  25. data/lib/eco/api/session/batch/errors.rb +38 -20
  26. data/lib/eco/api/session/batch/job.rb +252 -135
  27. data/lib/eco/api/session/batch/status.rb +55 -36
  28. data/lib/eco/api/session/batch.rb +2 -2
  29. data/lib/eco/api/session/config/base_config.rb +12 -11
  30. data/lib/eco/api/session/config/tagtree.rb +10 -14
  31. data/lib/eco/api/session/config/workflow.rb +15 -3
  32. data/lib/eco/api/session/config.rb +19 -26
  33. data/lib/eco/api/session.rb +13 -4
  34. data/lib/eco/api/usecases/cli.rb +4 -0
  35. data/lib/eco/api/usecases/default/locations/cli/codes_to_tags_cli.rb +18 -0
  36. data/lib/eco/api/usecases/default/locations/cli/csv_to_tree_cli.rb +12 -0
  37. data/lib/eco/api/usecases/default/locations/cli/tagtree_paths_cli.rb +12 -0
  38. data/lib/eco/api/usecases/default/locations/codes_to_tags_case.rb +32 -13
  39. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +15 -5
  40. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +6 -0
  41. data/lib/eco/api/usecases/default/locations/tagtree_paths_case.rb +51 -0
  42. data/lib/eco/api/usecases/default/locations.rb +1 -1
  43. data/lib/eco/api/usecases/default/people/amend/cli/reinvite_sync_cli.rb +8 -0
  44. data/lib/eco/api/usecases/default/people/amend/cli/reinvite_trans_cli.rb +11 -0
  45. data/lib/eco/api/usecases/default/people/amend/cli/restore_db_cli.rb +26 -0
  46. data/lib/eco/api/usecases/default/people/amend/reinvite_sync_case.rb +2 -0
  47. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_case.rb +2 -0
  48. data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +3 -0
  49. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +15 -5
  50. data/lib/eco/api/usecases/default/people/treat/cli/analyse_people_cli.rb +66 -0
  51. data/lib/eco/api/usecases/default/people/treat/cli/org_data_convert_cli.rb +35 -0
  52. data/lib/eco/api/usecases/default/people/treat/cli/supers_cyclic_identify_cli.rb +15 -0
  53. data/lib/eco/api/usecases/default/people/treat/cli/supers_hierachy_cli.rb +15 -0
  54. data/lib/eco/api/usecases/default/people/treat/org_data_convert_case.rb +11 -5
  55. data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +28 -7
  56. data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +32 -9
  57. data/lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb +2 -1
  58. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +2 -2
  59. data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +5 -0
  60. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
  61. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
  62. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
  63. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
  64. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
  65. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
  66. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +2 -0
  67. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +1 -0
  68. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
  69. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -2
  70. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
  71. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
  72. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
  73. data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
  74. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
  75. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
  76. data/lib/eco/api/usecases/use_case.rb +3 -1
  77. data/lib/eco/cli/config/use_cases.rb +4 -0
  78. data/lib/eco/cli/scripting/args_helpers.rb +3 -2
  79. data/lib/eco/cli/scripting/argument.rb +2 -2
  80. data/lib/eco/cli_default/input.rb +49 -45
  81. data/lib/eco/cli_default/input_filters.rb +32 -17
  82. data/lib/eco/cli_default/options.rb +8 -4
  83. data/lib/eco/cli_default/people.rb +1 -1
  84. data/lib/eco/cli_default/people_filters.rb +32 -24
  85. data/lib/eco/cli_default/usecases.rb +8 -121
  86. data/lib/eco/cli_default/workflow.rb +6 -4
  87. data/lib/eco/csv/split.rb +2 -0
  88. data/lib/eco/csv/table.rb +13 -0
  89. data/lib/eco/data/files/encoding.rb +15 -8
  90. data/lib/eco/data/files/helpers.rb +6 -2
  91. data/lib/eco/data/hashes/diff_result.rb +5 -0
  92. data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
  93. data/lib/eco/data/locations/node_diff.rb +4 -0
  94. data/lib/eco/data/locations/node_level.rb +6 -0
  95. data/lib/eco/language/auxiliar_logger.rb +2 -0
  96. data/lib/eco/version.rb +1 -1
  97. data/lib/eco-helpers.rb +1 -1
  98. metadata +15 -6
  99. data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
  100. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4768a5497ea319bbd31f09bceeb42c9d43567446b01c4e58894928ad6dec84c3
4
- data.tar.gz: 4179baf86c6f45f8424fa6690eecc0d1fc5be0daf4059c0af63050e70fcc8a3b
3
+ metadata.gz: 18d17b73673167619a4e704756a4e59f5d81d61a97e495721e100fe3e10d2374
4
+ data.tar.gz: a873e8e8970c5d67aa224ac226bec8194f81e2025bcd434b4f1005b8ddba21a3
5
5
  SHA512:
6
- metadata.gz: d45b4fa67247ac68ac53122759b934bc6c26d14e684774fb0e63184abfcf7799441e1e17384be726ada0d1a437228a5af152a589b9446fb582a1d4a5bbd140ad
7
- data.tar.gz: 4cce2123784bdd2730b0052338f52838979aa4ac3435e2a105f56124029e2a3192a481bd2ec694e172763cef24c383485243d06f87b25031dc358d565d858023
6
+ metadata.gz: 362fa919cbbdd98a7d69e99fa793f42a31fd790513d4d0e62db1e5838bf4937526fceb03139f394c069fd376d7a10c2cfcedf7207cda9377838b441022fa1a2f
7
+ data.tar.gz: 95064a493e111f68cf5da145f6322e9a30d1c7a2ce48c022b776109fc581ba7c1fd63dbb0a26dae7dcbd0c67086ec5ee0c7c507deae55cf45aa8ed73704ecb4c
data/.rubocop.yml CHANGED
@@ -98,3 +98,5 @@ Naming/MethodParameterName:
98
98
  AllowedNames: ['x', 'y', 'i', 'j', 'id', 'io', 'to']
99
99
  Naming/RescuedExceptionsVariableName:
100
100
  Enabled: false
101
+ Naming/BlockForwarding:
102
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,18 +2,58 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [3.0.4] - 2024-08-xx
5
+ ## [3.0.7] - 2024-08-xx
6
6
 
7
7
  ### Added
8
8
 
9
- - `Eco::Csv::Split` add `total_count` and `copy_count`
10
- - `Eco::API::Common::People::PersonParser`
11
- - added core attribute `brand_id`
9
+ ### Changed
10
+
11
+ ### Fixed
12
+
13
+ ## [3.0.6] - 2024-08-26
14
+
15
+ ### Added
12
16
 
13
17
  ### Changed
14
18
 
19
+ - `Eco::API::Microcases#people_search`
20
+ - Change to `silence: false` by default
21
+ - `Eco::Language::AuxiliarLogger#log`
22
+ - prevent call if `logger` object doesn't have method
23
+ - Various refactors
24
+ - Upgrade `ecoportal-api-v2` **gem**
25
+ - `Eco::API::UseCases::Cli`
26
+ - Made **inheritable** the class vars: `description`, `cli_name`, `callback`, and `options`
27
+ - Move case options to self-contained **cli** class
28
+ - `-restore-db`
29
+ - `-reinvite`, `-reinvite-from`
30
+ - `-codes-to-tags`
31
+ - `-tagtree-paths` (prev: `-create-tag-paths`)
32
+ - `-analyse-people`
33
+ - `-org-data-convert`
34
+ - `-identify-cyclic-supers`
35
+ - `-supers-hierarchy`
36
+
15
37
  ### Fixed
16
38
 
39
+ - `Eco::API::Common::People::PersonEntryAttributeMapper`
40
+ - method `#to_internal`, was missing to correcty return `attr`
41
+ - `Eco::Csv::Split`
42
+ - missing attr writers for `total_count` and `copy_count`
43
+ - CLI **suggestions**: when no suggestions / corrections, show still the unknown option.
44
+ - `Eco::API::Organization::TagTree`
45
+ - fix paths tracking
46
+ - `Eco::API::Organization::LoginProviders`
47
+ - identify `magic_link`
48
+
49
+ ## [3.0.4] - 2024-08-14
50
+
51
+ ### Added
52
+
53
+ - `Eco::Csv::Split` add `total_count` and `copy_count`
54
+ - `Eco::API::Common::People::PersonParser`
55
+ - added core attribute `brand_id`
56
+
17
57
  ## [3.0.3] - 2024-08-13
18
58
 
19
59
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency 'dotenv', '~> 3'
42
42
  spec.add_dependency 'ecoportal-api', '~> 0.10'
43
43
  spec.add_dependency 'ecoportal-api-graphql', '~> 0.4', '>= 0.4.1'
44
- spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.8'
44
+ spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.9'
45
45
  spec.add_dependency 'ed25519', '~> 1.2'
46
46
  spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
47
47
  spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
@@ -2,7 +2,6 @@ module Eco
2
2
  module API
3
3
  module Common
4
4
  module ClassHelpers
5
-
6
5
  # Creates a class and instance object methods with name `name` to resolve `klass` name
7
6
  def class_resolver(name, klass)
8
7
  define_singleton_method(name) { resolve_class(klass) }
@@ -15,18 +14,18 @@ module Eco
15
14
  @resolved ||= {}
16
15
  @resolved[klass] ||=
17
16
  case klass
18
- when Class
19
- klass
20
- when String
21
- begin
22
- Kernel.const_get(klass)
23
- rescue NameError => e
24
- raise if exception
25
- end
26
- when Symbol
27
- resolve_class(self.send(klass))
28
- else
29
- raise "Unknown class: #{klass}" if exception
17
+ when Class
18
+ klass
19
+ when String
20
+ begin
21
+ Kernel.const_get(klass)
22
+ rescue NameError
23
+ raise if exception
24
+ end
25
+ when Symbol
26
+ resolve_class(self.send(klass))
27
+ else
28
+ raise "Unknown class: #{klass}" if exception
30
29
  end
31
30
  end
32
31
 
@@ -34,9 +33,9 @@ module Eco
34
33
  # @param key [String, Symbol] to be normalized
35
34
  # @return [String] a correct constant name
36
35
  def to_constant(key)
37
- str_name = key.to_s.strip.split(/[\-\_ ]/i).compact.map do |str|
36
+ key.to_s.strip.split(/[\-\_ ]/i).compact.map do |str|
38
37
  str.slice(0).upcase + str.slice(1..-1).downcase
39
- end.join("")
38
+ end.join
40
39
  end
41
40
 
42
41
  # Helper to create an instance variable `name`
@@ -61,7 +60,7 @@ module Eco
61
60
  parent_space = parent_space ? resolve_class(parent_space) : self
62
61
  full_class_name = "#{parent_space}::#{class_name}"
63
62
 
64
- unless target_class = resolve_class(full_class_name, exception: false)
63
+ unless (target_class = resolve_class(full_class_name, exception: false))
65
64
  target_class = Class.new(inherits)
66
65
  parent_space.const_set class_name, target_class
67
66
  end
@@ -81,9 +80,9 @@ module Eco
81
80
  return [] if scope.empty?
82
81
  scope.select do |klass|
83
82
  klass < parent_class
84
- end.sort do |k1, k2|
85
- next -1 if k2 < k1
86
- next 1 if k1 < k2
83
+ end.sort do |k_1, k_2|
84
+ next -1 if k_2 < k_1
85
+ next 1 if k_1 < k_2
87
86
  0
88
87
  end.tap do |siblings|
89
88
  if direct
@@ -98,7 +97,7 @@ module Eco
98
97
  # @param direct [Boolean] it will only include direct child classes.
99
98
  # @return [Boolean] `true` if the current class has child classes, and `false` otherwise.
100
99
  def descendants?(parent_class: self, direct: false)
101
- descendants(parent_class: parent_class, direct: direct).length > 0
100
+ descendants(parent_class: parent_class, direct: direct).length.positive?
102
101
  end
103
102
 
104
103
  # Keeps track on class instance variables that should be inherited by child classes.
@@ -106,18 +105,20 @@ module Eco
106
105
  # - subclasses will inherit the value as is at that moment
107
106
  # - any change afterwards will be only on the specific class (in line with class instance variables)
108
107
  # - adapted from https://stackoverflow.com/a/10729812/4352306
109
- # TODO: this separates the logic of the method to the instance var. Think if would be possible to join them somehow.
108
+ # TODO: this separates the logic of the method to the instance var.
109
+ # Think if would be possible to join them somehow.
110
110
  def inheritable_class_vars(*vars)
111
111
  @inheritable_class_vars ||= [:inheritable_class_vars]
112
112
  @inheritable_class_vars += vars
113
113
  end
114
114
 
115
- # Builds the attr_reader and attr_writer of `attrs` and registers the associated instance variable as inheritable.
115
+ # Builds the attr_reader and attr_writer of `attrs` and registers
116
+ # the associated instance variable as inheritable.
116
117
  def inheritable_attrs(*attrs)
117
118
  attrs.each do |attr|
118
119
  class_eval %(
119
120
  class << self; attr_accessor :#{attr} end
120
- )
121
+ ), __FILE__, __LINE__ - 2
121
122
  end
122
123
  inheritable_class_vars(*attrs)
123
124
  end
@@ -2,14 +2,12 @@ module Eco
2
2
  module API
3
3
  module Common
4
4
  module ClassMetaBasics
5
-
6
5
  # Helps to define methods and keep track on them
7
6
  def define(name, &block)
8
7
  name = name.to_sym
9
8
  @helpers[name] = block
10
9
  define_method(name.to_sym, &block)
11
10
  end
12
-
13
11
  end
14
12
  end
15
13
  end
@@ -26,6 +26,7 @@ module Eco
26
26
  @cli = cli_class
27
27
  elsif cli_class.nil?
28
28
  return @cli if instance_variable_defined?(:@cli) && !@cli.nil?
29
+
29
30
  # try to see if it's namespaced after the use case it provisions cli integration
30
31
  begin
31
32
  try_class = [to_s, 'Cli'].join('::')
@@ -128,7 +128,7 @@ module Eco
128
128
  # Support for multiple file
129
129
  if file.is_a?(Array)
130
130
  return file.each_with_object([]) do |f, out|
131
- logger.info("Parsing file '#{f}'")
131
+ log(:info) { "Parsing file '#{f}'" }
132
132
  curr = to_array_of_hashes(**kargs.merge(file: f))
133
133
  out.concat(curr)
134
134
  end
@@ -141,7 +141,9 @@ module Eco
141
141
 
142
142
  case content
143
143
  when Hash
144
- logger.error("Input data as 'Hash' not supported. Expecting 'Enumerable' or 'String'")
144
+ log(:error) {
145
+ "Input data as 'Hash' not supported. Expecting 'Enumerable' or 'String'"
146
+ }
145
147
  exit(1)
146
148
  when String
147
149
  deps = {check_headers: true} if kargs[:check_headers]
@@ -221,12 +223,12 @@ module Eco
221
223
  private
222
224
 
223
225
  def abort(message)
224
- logger.error(message)
226
+ log(:error) { message }
225
227
  exit(1)
226
228
  end
227
229
 
228
230
  def fatal(msg)
229
- logger.fatal(msg)
231
+ log(:fatal) { msg }
230
232
  raise msg
231
233
  end
232
234
  end
@@ -4,6 +4,7 @@ module Eco
4
4
  module People
5
5
  class PersonEntry
6
6
  DEBUG = false
7
+ include Eco::Language::AuxiliarLogger
7
8
 
8
9
  # This class is meant to provide a common interface to access entries of source data that come in
9
10
  # different formats.
@@ -217,7 +218,8 @@ module Eco
217
218
  set_part(person, attr, value)
218
219
  rescue StandardError => e
219
220
  raise unless attr == "email"
220
- logger.error("#{e} - setting blank email instead.")
221
+
222
+ log(:error) { "#{e} - setting blank email instead." }
221
223
  set_part(person, attr, nil)
222
224
  end
223
225
  end
@@ -515,12 +517,8 @@ module Eco
515
517
  end
516
518
 
517
519
  # LOGGER
518
- def logger
519
- @logger || ::Logger.new(IO::NULL)
520
- end
521
-
522
520
  def fatal(msg)
523
- logger.fatal(msg)
521
+ log(:fatal) { msg }
524
522
  raise msg
525
523
  end
526
524
 
@@ -2,8 +2,12 @@ module Eco
2
2
  module API
3
3
  module Common
4
4
  module People
5
- # @attr_reader direct_attrs [Array<String>] only those internal attributes present in the person entry that do **not** have an internal/external name mapping.
5
+ # @attr_reader direct_attrs [Array<String>] only those
6
+ # internal attributes present in the person entry that
7
+ # do **not** have an internal/external name mapping.
6
8
  class PersonEntryAttributeMapper
9
+ include Eco::Language::AuxiliarLogger
10
+
7
11
  DEBUG = false
8
12
  @@cached_warnings = {} # rubocop:disable Style/ClassVars
9
13
 
@@ -11,7 +15,8 @@ module Eco
11
15
 
12
16
  # Helper class tied to `PersonEntry` that allows to track which attributes of a person entry are present
13
17
  # and how they should be mapped between internal and external names if applicable.
14
- # This class is meant to help in providing a common interface to access entries of source data that come in different formats.
18
+ # This class is meant to help in providing a common interface to access entries of source
19
+ # data that come in different formats.
15
20
  # @note
16
21
  # - if `data` is a `Person` object, its behaviour is `serialise`.
17
22
  # - if `data` is **not** a `Person` object, it does a `parse`.
@@ -116,13 +121,15 @@ module Eco
116
121
  # 2. if it doesn't exist, returns `nil`.
117
122
  # @note
118
123
  # 1. the **scope of attributes** is based on all the attributes recognized by the person parser.
119
- # 2. the attributes recognized by the person parser are those of of the `Person` model (where details attributes depend on the `schema`).
124
+ # 2. the attributes recognized by the person parser are those of of the `Person` model
125
+ # (where details attributes depend on the `schema`).
120
126
  # @param value [String, Array<String>] value(s) to be translated into internal names.
121
127
  # @return [String, nil, Array<String] the internal name(s) of `value`.
122
128
  def to_internal(value)
123
129
  # TODO: check PersonEntry#to_internal and #to_external in init_attr_trackers
124
130
  # => when attr_map is avoided, it doesn't work as it should
125
131
  return value unless @attr_map
132
+
126
133
  attr = value
127
134
  case value
128
135
  when Array
@@ -136,19 +143,21 @@ module Eco
136
143
  unless cached_warning("external", "spaces", value)
137
144
  msg = "The external person field name '#{value}' contains "
138
145
  msg << "additional spaces in the reference file"
139
- logger.warn(msg)
146
+ log(:warn) { msg }
140
147
  end
148
+
141
149
  attr = @attr_map.to_internal(value.strip)
142
150
  elsif [value, value.strip, value.strip.downcase].any? {|val| @attr_map.internal?(val)}
143
151
  unless cached_warning("external", "reversed", value)
144
152
  msg = "The mapper [external, internal] attribute names "
145
153
  msg << "may be declared reversedly for EXTERNAL attribute: '#{value}'"
146
- logger.info(msg)
154
+ log(:info) { msg }
147
155
  end
148
156
  end
149
157
  end
150
158
 
151
- return nil unless @person_parser.all_model_attrs.include?(attr)
159
+ return unless @person_parser.all_model_attrs.include?(attr)
160
+ attr
152
161
  end
153
162
 
154
163
  # Serializing helper also used to do a reverse mapping when parsing:
@@ -160,11 +169,13 @@ module Eco
160
169
  # 2. if it doesn't exist, returns `nil`.
161
170
  # @note
162
171
  # 1. the **scope of attributes** is based on all the attributes defined in the current entry.
163
- # 2. the attributes recognized by the person parser are those of of the `Person` model (where details attributes depend on the `schema`).
172
+ # 2. the attributes recognized by the person parser are those of of the `Person` model
173
+ # (where details attributes depend on the `schema`).
164
174
  # @param value [String, Array<String>] value(s) to be translated or aliased into external ones.
165
175
  # @return [String, nil, Array<String] the external name(s) of `value`.
166
176
  def to_external(value)
167
177
  return value unless @attr_map
178
+
168
179
  attr = value
169
180
  case value
170
181
  when Array
@@ -178,7 +189,7 @@ module Eco
178
189
  unless cached_warning("internal", "spaces", value)
179
190
  msg = "The internal person field name '#{value}' contains "
180
191
  msg << "additional spaces in the reference file"
181
- logger.warn(msg)
192
+ log(:warn) { msg }
182
193
  end
183
194
  attr = @attr_map.to_external(value.strip)
184
195
  elsif [value, value.strip, value.strip.downcase].any? {|val| @attr_map.external?(val)}
@@ -186,12 +197,12 @@ module Eco
186
197
  msg = "The mapper [external, internal] attribute names "
187
198
  msg << "may be declared reversedly for "
188
199
  msg << "INTERNAL attribute: '#{value}'"
189
- logger.info(msg)
200
+ log(:info) { msg }
190
201
  end
191
202
  end
192
203
  end
193
204
 
194
- return nil unless !@external_entry || attributes(@external_entry).include?(attr)
205
+ return unless !@external_entry || attributes(@external_entry).include?(attr)
195
206
  attr
196
207
  end
197
208
 
@@ -200,12 +211,14 @@ module Eco
200
211
  # Whether the maps include this `attr` as mapped to itself
201
212
  def self_mapped_attr?(attr)
202
213
  return false unless @attr_map
214
+
203
215
  @attr_map.self_mapped?(attr)
204
216
  end
205
217
 
206
218
  # Whether the maps include this `attr` as mapped from to some other or itself
207
219
  def external_attr?(attr)
208
220
  return false unless @attr_map
221
+
209
222
  @attr_map.external?(attr)
210
223
  end
211
224
 
@@ -357,7 +370,7 @@ module Eco
357
370
  end
358
371
 
359
372
  def cached_warning(*args)
360
- unless exists = !!@@cached_warnings.dig(*args)
373
+ unless (exists = !!@@cached_warnings.dig(*args)) # rubocop:disable Style/DoubleNegation
361
374
  args.reduce(@@cached_warnings) do |cache, level|
362
375
  cache[level] = {} unless cache.key?(level)
363
376
  cache[level]
@@ -367,7 +380,7 @@ module Eco
367
380
  end
368
381
 
369
382
  def fatal(msg)
370
- logger.fatal(msg)
383
+ log(:fatal) { msg }
371
384
  raise msg
372
385
  end
373
386
 
@@ -53,6 +53,7 @@ module Eco
53
53
  def initialize(schema: nil)
54
54
  msg = "Constructor needs a PersonSchema. Given: #{schema.class}"
55
55
  raise msg if schema && !schema.is_a?(Ecoportal::API::V1::PersonSchema)
56
+
56
57
  @details_attrs = []
57
58
  @parsers = {}
58
59
  @patch_version = 0
@@ -103,6 +104,7 @@ module Eco
103
104
  # All the internal name attributes, including _core_, _account_ and _details_.
104
105
  def all_attrs(include_defined_parsers: false)
105
106
  return all_model_attrs | defined_model_attrs if include_defined_parsers
107
+
106
108
  all_model_attrs
107
109
  end
108
110
 
@@ -114,6 +116,7 @@ module Eco
114
116
  # if `source_attrs` is not `nil`. All the _core attributes_, otherwise.
115
117
  def target_attrs_core(source_attrs = nil)
116
118
  return CORE_ATTRS unless source_attrs
119
+
117
120
  scoped_attrs(source_attrs, CORE_ATTRS)
118
121
  end
119
122
 
@@ -125,6 +128,7 @@ module Eco
125
128
  # if `source_attrs` is not `nil`. All the _details attributes_, otherwise.
126
129
  def target_attrs_details(source_attrs = nil)
127
130
  return @details_attrs unless source_attrs
131
+
128
132
  scoped_attrs(source_attrs, @details_attrs)
129
133
  end
130
134
 
@@ -136,6 +140,7 @@ module Eco
136
140
  # All the _account attributes_, otherwise.
137
141
  def target_attrs_account(source_attrs = nil)
138
142
  return ACCOUNT_ATTRS unless source_attrs
143
+
139
144
  scoped_attrs(source_attrs, ACCOUNT_ATTRS)
140
145
  end
141
146
 
@@ -213,6 +218,7 @@ module Eco
213
218
  # @return [Eco::API::Common::People::PersonParser] the current object (to ease chainig).
214
219
  def merge(parser)
215
220
  return self unless parser
221
+
216
222
  msg = "Expected a PersonParser object. Given #{parser.class}"
217
223
  raise msg unless parser.is_a?(PersonParser)
218
224
 
@@ -237,10 +243,12 @@ module Eco
237
243
  msg << "not match any type: #{@details_attrs}"
238
244
  raise msg
239
245
  end
246
+
240
247
  Eco::API::Common::People::PersonAttributeParser.new(attr, dependencies: dependencies).tap do |parser|
241
248
  @parsers[attr] = parser
242
249
  definition.call(parser)
243
250
  end
251
+
244
252
  patched!
245
253
  self
246
254
  end
@@ -74,7 +74,7 @@ module Eco
74
74
 
75
75
  # TODO: paremeter for the exception
76
76
  def fatal(msg)
77
- logger.fatal(msg)
77
+ log(:fatal) { msg }
78
78
  raise msg
79
79
  end
80
80
  end
@@ -59,6 +59,13 @@ module Eco
59
59
  def api?(version:)
60
60
  config.apis.active_api.version_available?(version)
61
61
  end
62
+
63
+ # Shortcut to logger.
64
+ def log(level, &block)
65
+ return unless logger.respond_to?(:level)
66
+
67
+ logger&.send(level, &block)
68
+ end
62
69
  end
63
70
  end
64
71
  end
@@ -4,6 +4,7 @@ module Eco
4
4
  module Session
5
5
  class FileManager
6
6
  include Eco::Data::Files
7
+ include Eco::Language::AuxiliarLogger
7
8
 
8
9
  attr_reader :dir, :dir_path
9
10
  attr_accessor :timestamp_pattern
@@ -20,11 +21,13 @@ module Eco
20
21
  @dir = Eco::Data::Files::Directory.new(value)
21
22
  @dir_path = @dir.create
22
23
  rescue StandardError => err
23
- logger.error("could not create or make any sense of directory '#{value}': #{err}")
24
+ log(:error) {
25
+ "could not create or make any sense of directory '#{value}': #{err}"
26
+ }
24
27
  end
25
28
 
26
29
  def logger
27
- @enviro&.logger || ::Logger.new(IO::NULL)
30
+ @enviro&.logger || super
28
31
  end
29
32
 
30
33
  ##### FILE #####
@@ -40,11 +43,13 @@ module Eco
40
43
  file = dir.file(filename, should_exist: true)
41
44
 
42
45
  unless file
43
- logger.error("Can't read from file '#{filename}' because it does not exist.")
46
+ log(:error) {
47
+ "Can't read from file '#{filename}' because it does not exist."
48
+ }
44
49
  return nil
45
50
  end
46
51
 
47
- logger.debug("Reading from file '#{file}'")
52
+ log(:debug) { "Reading from file '#{file}'" }
48
53
  mode ? File.read(file, mode: mode) : File.read(file)
49
54
  end
50
55
 
@@ -52,7 +57,9 @@ module Eco
52
57
  file = dir.file(filename, should_exist: true)
53
58
 
54
59
  unless file
55
- logger.error("Can't read from file '#{filename}' because it does not exist.")
60
+ log(:error) {
61
+ "Can't read from file '#{filename}' because it does not exist."
62
+ }
56
63
  return nil
57
64
  end
58
65
 
@@ -77,7 +84,7 @@ module Eco
77
84
  FileManager.file_fullpath(file)
78
85
  )
79
86
 
80
- logger.debug("Writting to file '#{file}'")
87
+ log(:debug) { "Writting to file '#{file}'" }
81
88
 
82
89
  mode = mode == :binary ? 'wb' : 'w'
83
90
 
@@ -103,7 +110,7 @@ module Eco
103
110
  FileManager.file_fullpath(file)
104
111
  )
105
112
 
106
- logger.debug("Writting to file '#{file}'")
113
+ log(:debug) { "Writting to file '#{file}'" }
107
114
 
108
115
  mode = mode == :binary ? 'wb' : 'w'
109
116
  File.open(file, mode) { |fd| fd << content }
@@ -114,7 +121,7 @@ module Eco
114
121
  def append(content, filename, mode: :string)
115
122
  file = dir.file(filename)
116
123
 
117
- logger.debug("Appending to file '#{file}'")
124
+ log(:debug) { "Appending to file '#{file}'" }
118
125
 
119
126
  mode = mode == :binary ? 'ab' : 'a'
120
127
  File.open(file, mode) { |fd| fd << "#{content}\n" }
@@ -4,7 +4,7 @@ module Eco
4
4
  module Session
5
5
  class Logger
6
6
  class Cache
7
- LEVELS = ["UNKNOWN", "FATAL", "ERROR", "WARN", "INFO", "DEBUG"]
7
+ LEVELS = %w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
8
8
 
9
9
  def initialize
10
10
  reset
@@ -44,10 +44,11 @@ module Eco
44
44
  private
45
45
 
46
46
  def where(start_time, end_time)
47
- tstart = to_datetime(start_time)
48
- tend = to_datetime(end_time)
49
- condition = Proc.new do |log|
47
+ tstart = to_datetime(start_time)
48
+ tend = to_datetime(end_time)
49
+ condition = proc do |log|
50
50
  next true unless tstart || tend
51
+
51
52
  log.after?(tstart) && log.before?(tend)
52
53
  end
53
54
 
@@ -61,7 +62,9 @@ module Eco
61
62
 
62
63
  def to_levels(value)
63
64
  levels = [value].flatten.map {|v| to_level(v)}.compact
64
- levels = levels.empty?? LEVELS : levels
65
+ return levels unless levels.empty?
66
+
67
+ LEVELS
65
68
  end
66
69
 
67
70
  def to_level(value)
@@ -71,18 +74,19 @@ module Eco
71
74
  end
72
75
 
73
76
  def valid_level!(str)
74
- return true if !str
75
- unless LEVELS.any? {|lev| str == lev}
76
- raise "Unknown level #{str}. Should be one of #{LEVELS}"
77
- end
77
+ return true unless str
78
+ return true if LEVELS.any? {|lev| str == lev}
79
+
80
+ msg = "Unknown level #{str}. Should be one of #{LEVELS}"
81
+ raise ArgumentError, msg
78
82
  end
79
83
 
80
84
  def nil_or_upcase(value)
81
85
  value = value.to_s.upcase if value
82
86
  return yield(value) if block_given?
87
+
83
88
  value
84
89
  end
85
-
86
90
  end
87
91
  end
88
92
  end