eco-helpers 3.0.37 → 3.1.2

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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +132 -1
  4. data/lib/eco/api/common/loaders/base.rb +2 -2
  5. data/lib/eco/api/common/loaders/case_base.rb +2 -0
  6. data/lib/eco/api/common/loaders/config/block.rb +78 -0
  7. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +49 -6
  8. data/lib/eco/api/common/loaders/config.rb +3 -26
  9. data/lib/eco/api/common/loaders/error_handler.rb +2 -0
  10. data/lib/eco/api/common/loaders/parser.rb +1 -4
  11. data/lib/eco/api/common/people/entries.rb +23 -6
  12. data/lib/eco/api/common/people/entry_factory.rb +1 -1
  13. data/lib/eco/api/common/people/person_entry.rb +104 -27
  14. data/lib/eco/api/common/people/person_parser.rb +50 -16
  15. data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
  16. data/lib/eco/api/common/session/base_session.rb +75 -81
  17. data/lib/eco/api/common/session/environment.rb +70 -70
  18. data/lib/eco/api/common/session/file_manager.rb +132 -135
  19. data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
  20. data/lib/eco/api/common/session/helpers.rb +10 -15
  21. data/lib/eco/api/common/session/logger/cache.rb +94 -96
  22. data/lib/eco/api/common/session/logger/channels.rb +24 -32
  23. data/lib/eco/api/common/session/logger/log.rb +38 -46
  24. data/lib/eco/api/common/session/logger.rb +50 -54
  25. data/lib/eco/api/common/session/mailer/aws_provider.rb +64 -71
  26. data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
  27. data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
  28. data/lib/eco/api/common/session/mailer.rb +78 -83
  29. data/lib/eco/api/common/session/s3_uploader.rb +132 -138
  30. data/lib/eco/api/common/session/sftp.rb +202 -208
  31. data/lib/eco/api/common.rb +0 -3
  32. data/lib/eco/api/custom/mailer.rb +4 -2
  33. data/lib/eco/api/error/handlers.rb +1 -1
  34. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
  35. data/lib/eco/api/microcases/people/manage/search.rb +2 -2
  36. data/lib/eco/api/organization/people/similarity.rb +3 -3
  37. data/lib/eco/api/organization/people.rb +2 -2
  38. data/lib/eco/api/session/batch/base_policy.rb +42 -27
  39. data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
  40. data/lib/eco/api/session/batch/launcher.rb +16 -3
  41. data/lib/eco/api/session/config/api.rb +4 -3
  42. data/lib/eco/api/session/config/apis/one_off.rb +1 -1
  43. data/lib/eco/api/session/config/files.rb +13 -12
  44. data/lib/eco/api/session/config/workflow.rb +1 -373
  45. data/lib/eco/api/session/config.rb +45 -10
  46. data/lib/eco/api/session.rb +7 -9
  47. data/lib/eco/api/usecases/base_case/model.rb +6 -6
  48. data/lib/eco/api/usecases/base_case.rb +1 -1
  49. data/lib/eco/api/usecases/cli.rb +1 -1
  50. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +22 -13
  51. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
  52. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +6 -3
  53. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  54. data/lib/eco/api/usecases/lib/base/env.rb +21 -23
  55. data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
  56. data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
  57. data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
  58. data/lib/eco/api/usecases/lib/files.rb +1 -0
  59. data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
  60. data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
  61. data/lib/eco/api/usecases/lib/locations.rb +7 -0
  62. data/lib/eco/api/usecases/lib/people/base.rb +20 -0
  63. data/lib/eco/api/usecases/lib/people.rb +6 -0
  64. data/lib/eco/api/usecases/lib.rb +2 -0
  65. data/lib/eco/api/usecases/ooze_cases.rb +1 -1
  66. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
  67. data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +3 -3
  68. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -1
  69. data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +1 -1
  70. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +6 -2
  71. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +7 -6
  72. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +14 -4
  73. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +11 -8
  74. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
  75. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
  76. data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
  77. data/lib/eco/api/usecases/service/sftp.rb +7 -1
  78. data/lib/eco/api/usecases/use_case.rb +3 -2
  79. data/lib/eco/api/usecases/workflow.rb +5 -0
  80. data/lib/eco/api/usecases.rb +12 -5
  81. data/lib/eco/cli/scripting/args_helpers.rb +1 -9
  82. data/lib/eco/cli_default/options.rb +98 -68
  83. data/lib/eco/cli_default/workflow/end.rb +22 -0
  84. data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
  85. data/lib/eco/cli_default/workflow/load/data.rb +27 -0
  86. data/lib/eco/cli_default/workflow/load/input.rb +28 -0
  87. data/lib/eco/cli_default/workflow/load.rb +13 -0
  88. data/lib/eco/cli_default/workflow/options.rb +18 -0
  89. data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
  90. data/lib/eco/cli_default/workflow/report.rb +17 -0
  91. data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
  92. data/lib/eco/cli_default/workflow/usecases.rb +23 -0
  93. data/lib/eco/cli_default/workflow.rb +24 -180
  94. data/lib/eco/data/count_trace.rb +51 -0
  95. data/lib/eco/data/files/content.rb +39 -0
  96. data/lib/eco/data/files/directory.rb +78 -45
  97. data/lib/eco/data/files/encoding.rb +12 -21
  98. data/lib/eco/data/files/file_pattern.rb +15 -8
  99. data/lib/eco/data/files/folder.rb +196 -0
  100. data/lib/eco/data/files/relative_path.rb +54 -0
  101. data/lib/eco/data/files/timestamp.rb +18 -0
  102. data/lib/eco/data/files.rb +46 -5
  103. data/lib/eco/data/fuzzy_match.rb +1 -1
  104. data/lib/eco/data/hashes/array_diff.rb +11 -5
  105. data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
  106. data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
  107. data/lib/eco/data/mapper.rb +8 -1
  108. data/lib/eco/data.rb +1 -0
  109. data/lib/eco/language/auxiliar_logger.rb +6 -11
  110. data/lib/eco/language/delegation/delegating_missing.rb +1 -1
  111. data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
  112. data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
  113. data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
  114. data/lib/eco/language/klass/auto_loader.rb +129 -0
  115. data/lib/eco/language/klass/builder.rb +6 -6
  116. data/lib/eco/language/klass/const.rb +19 -0
  117. data/lib/eco/language/klass/helpers_built.rb +3 -1
  118. data/lib/eco/language/klass/hierarchy.rb +5 -1
  119. data/lib/eco/language/klass/naming.rb +5 -2
  120. data/lib/eco/language/klass/resolver.rb +21 -6
  121. data/lib/eco/language/klass/uid.rb +12 -0
  122. data/lib/eco/language/klass/when_inherited.rb +30 -6
  123. data/lib/eco/language/klass.rb +5 -2
  124. data/lib/eco/language/methods/access_modifier.rb +23 -0
  125. data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
  126. data/lib/eco/language/methods.rb +1 -0
  127. data/lib/eco/language/models/hierarchy.rb +41 -0
  128. data/lib/eco/language/models/workflow.rb +385 -0
  129. data/lib/eco/language/models.rb +2 -1
  130. data/lib/eco/version.rb +1 -1
  131. metadata +31 -7
  132. data/lib/eco/api/common/class_auto_loader.rb +0 -114
  133. data/lib/eco/api/common/class_helpers.rb +0 -9
  134. data/lib/eco/api/common/class_hierarchy.rb +0 -45
  135. data/lib/eco/data/files/helpers.rb +0 -152
  136. data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -6,6 +6,16 @@ module Eco
6
6
  DEBUG = false
7
7
  include Eco::Language::AuxiliarLogger
8
8
 
9
+ BOOLEAN_ATTRS = %w[
10
+ freemium accept_eula archived
11
+ ].freeze
12
+ MULTI_ATTRS = %w[
13
+ policy_group_ids filter_tags login_provider_ids starred_ids
14
+ ].freeze
15
+ NUMERIC_ATTRS = %w[
16
+ subordinates
17
+ ].freeze
18
+
9
19
  # This class is meant to provide a common interface to access entries of source data that come in
10
20
  # different formats.
11
21
  # @note
@@ -287,7 +297,9 @@ module Eco
287
297
  person.add_details(@person_parser.schema) if !person.details || !person.details.schema_id
288
298
  scoped_attrs = @emap.details_attrs(@final_entry) - into_a(exclude)
289
299
 
290
- @final_entry.slice(*scoped_attrs).each do |attr, value|
300
+ @final_entry.slice(
301
+ *scoped_attrs
302
+ ).each do |attr, value|
291
303
  set_part(person.details, attr, value)
292
304
  end
293
305
  end
@@ -327,16 +339,22 @@ module Eco
327
339
  # @param mapped_entry [Hash] that with **internal** names but **external** values and types.
328
340
  # @return [Hash] with **external** names, values and types.
329
341
  def _external_serializing(mapped_entry)
330
- target_attrs = @emap.all_model_attrs | @emap.aliased_attrs
342
+ target_attrs =
343
+ @emap.all_model_attrs |
344
+ @emap.aliased_attrs
331
345
  rest_keys = mapped_entry.keys - target_attrs
332
346
  target_attrs -= ['send_invites']
347
+
333
348
  external_entry = target_attrs.each_with_object({}) do |attr, hash|
334
349
  next if hash.key?(ext_attr = @emap.to_external(attr))
335
350
 
336
351
  hash[ext_attr] = mapped_entry[attr]
337
352
  end
338
353
 
339
- merge_missing_attrs(external_entry, mapped_entry.slice(*rest_keys))
354
+ merge_missing_attrs(
355
+ external_entry,
356
+ mapped_entry.slice(*rest_keys)
357
+ )
340
358
  end
341
359
 
342
360
  # Parsing helper that aliases attribute names (from internal to external names)
@@ -348,7 +366,9 @@ module Eco
348
366
  hash[attr] = external_entry[@emap.to_external(attr)]
349
367
  end
350
368
 
351
- external_entry.slice(*@emap.direct_attrs).merge(mapped_hash)
369
+ external_entry.slice(
370
+ *@emap.direct_attrs
371
+ ).merge(mapped_hash)
352
372
  end
353
373
 
354
374
  # Serializing helper that **serializes values** that have a parser/serializer defined.
@@ -364,7 +384,10 @@ module Eco
364
384
  model_attrs = @person_parser.all_model_attrs - ['send_invites']
365
385
  aux_hash = mapped_hash.slice(*model_attrs)
366
386
 
367
- merge_missing_attrs(aux_hash, mapped_hash)
387
+ merge_missing_attrs(
388
+ aux_hash,
389
+ mapped_hash
390
+ )
368
391
  end
369
392
 
370
393
  # Parsing helper that just **parses the values** that have a parser/serializer defined.
@@ -372,7 +395,9 @@ module Eco
372
395
  # @param mapped_entry [Hash] the entry with the _internal attribute_ names but the _external values_.
373
396
  # @return [Hash] the `internal entry` with the **internal** attributes names and values.
374
397
  def _internal_parsing(mapped_entry)
375
- mapped_entry.merge(_parse_values(mapped_entry, :internal))
398
+ mapped_entry.merge(
399
+ _parse_values(mapped_entry, :internal)
400
+ )
376
401
  end
377
402
 
378
403
  # Serializing helper that just creates the _internal entry_ out of a _parsed entry_ (serializes the type).
@@ -382,18 +407,37 @@ module Eco
382
407
  final_entry = final_entry.merge(
383
408
  _serialize_values(final_entry, :final)
384
409
  )
385
- core_account = @person_parser.target_attrs_account + @person_parser.target_attrs_core
410
+ core_account =
411
+ @person_parser.target_attrs_account +
412
+ @person_parser.target_attrs_core
386
413
 
387
414
  core_account_hash = core_account.reduce({}) do |hash, attr|
388
- hash.merge(hash_attr(attr, _serialize_type(attr, final_entry[attr])))
415
+ hash.merge(
416
+ hash_attr(
417
+ attr,
418
+ _serialize_type(attr, final_entry[attr])
419
+ )
420
+ )
389
421
  end
390
422
 
391
423
  details_hash = @person_parser.target_attrs_details.reduce({}) do |hash, attr|
392
- hash.merge(hash_attr(attr, _serialize_type(attr, final_entry[attr], schema: @person_parser.schema)))
424
+ hash.merge(
425
+ hash_attr(
426
+ attr,
427
+ _serialize_type(
428
+ attr,
429
+ final_entry[attr],
430
+ schema: @person_parser.schema
431
+ )
432
+ )
433
+ )
393
434
  end
394
435
 
395
436
  merging(core_account_hash, details_hash) do |internal_entry|
396
- merge_missing_attrs(internal_entry, final_entry)
437
+ merge_missing_attrs(
438
+ internal_entry,
439
+ final_entry
440
+ )
397
441
  end
398
442
  end
399
443
 
@@ -403,19 +447,31 @@ module Eco
403
447
  # but the **external** types.
404
448
  # @return [Hash] the `parsed entry` with the **internal** final attributes names, values and types.
405
449
  def _final_parsing(internal_entry)
406
- core_account_attrs = @emap.account_attrs(internal_entry) + @emap.core_attrs(internal_entry)
407
- core_account_hash = internal_entry.slice(*core_account_attrs).each_with_object({}) do |(attr, value), hash|
450
+ core_account_attrs =
451
+ @emap.account_attrs(internal_entry) +
452
+ @emap.core_attrs(internal_entry)
453
+ core_account_hash = internal_entry.slice(
454
+ *core_account_attrs
455
+ ).each_with_object({}) do |(attr, value), hash|
408
456
  hash[attr] = _parse_type(attr, value)
409
457
  end
410
458
 
411
459
  details_attrs = @emap.details_attrs(internal_entry)
412
- details_hash = internal_entry.slice(*details_attrs).each_with_object({}) do |(attr, value), hash|
460
+ details_hash = internal_entry.slice(
461
+ *details_attrs
462
+ ).each_with_object({}) do |(attr, value), hash|
413
463
  hash[attr] = _parse_type(attr, value, schema: @person_parser.schema)
414
464
  end
415
465
 
416
466
  merging(core_account_hash, details_hash) do |final_entry|
417
- final_entry = merge_missing_attrs(final_entry, internal_entry)
418
- final_entry.merge(_parse_values(final_entry, :final))
467
+ final_entry = merge_missing_attrs(
468
+ final_entry,
469
+ internal_entry
470
+ )
471
+
472
+ final_entry.merge(
473
+ _parse_values(final_entry, :final)
474
+ )
419
475
  end
420
476
  end
421
477
 
@@ -429,15 +485,30 @@ module Eco
429
485
  # @return [Hash] the `parsed entry` with the **internal** attributes names and internal typed values.
430
486
  def _final_serializing(person)
431
487
  core_hash = @person_parser.target_attrs_core.reduce({}) do |hash, attr|
432
- hash.merge(hash_attr(attr, get_part(person, attr)))
488
+ hash.merge(
489
+ hash_attr(
490
+ attr,
491
+ get_part(person, attr)
492
+ )
493
+ )
433
494
  end
434
495
 
435
496
  account_hash = @person_parser.target_attrs_account.reduce({}) do |hash, attr|
436
- hash.merge(hash_attr(attr, get_part(person.account, attr)))
497
+ hash.merge(
498
+ hash_attr(
499
+ attr,
500
+ get_part(person.account, attr)
501
+ )
502
+ )
437
503
  end
438
504
 
439
505
  details_hash = @person_parser.target_attrs_details.reduce({}) do |hash, attr|
440
- hash.merge(hash_attr(attr, get_part(person.details, attr)))
506
+ hash.merge(
507
+ hash_attr(
508
+ attr,
509
+ get_part(person.details, attr)
510
+ )
511
+ )
441
512
  end
442
513
 
443
514
  merging(core_hash, account_hash, details_hash) do |final_entry|
@@ -458,7 +529,9 @@ module Eco
458
529
  ).each_with_object({}) do |attr, hash|
459
530
  data = entry.is_a?(Hash)? entry.merge(hash) : entry
460
531
  serial_attr = @person_parser.serialize(attr, data, phase, deps: @deps[attr] || {})
461
- hash.merge!(hash_attr(attr, serial_attr))
532
+ hash.merge!(
533
+ hash_attr(attr, serial_attr)
534
+ )
462
535
  end
463
536
  end
464
537
 
@@ -468,7 +541,9 @@ module Eco
468
541
  phase
469
542
  ).each_with_object({}) do |attr, hash|
470
543
  parsed_attr = @person_parser.parse(attr, entry.merge(hash), phase)
471
- hash.merge!(hash_attr(attr, parsed_attr))
544
+ hash.merge!(
545
+ hash_attr(attr, parsed_attr)
546
+ )
472
547
  end
473
548
  end
474
549
 
@@ -489,11 +564,11 @@ module Eco
489
564
  end
490
565
 
491
566
  value
492
- elsif %w[policy_group_ids filter_tags login_provider_ids starred_ids].include?(attr)
567
+ elsif MULTI_ATTRS.include?(attr)
493
568
  @person_parser.serialize(:multiple, value)
494
- elsif %w[freemium accept_eula archived].include?(attr)
569
+ elsif BOOLEAN_ATTRS.include?(attr)
495
570
  @person_parser.serialize(:boolean, value)
496
- elsif ['subordinates'].include?(attr)
571
+ elsif NUMERIC_ATTRS.include?(attr)
497
572
  @person_parser.serialize(:number, value)
498
573
  else
499
574
  value
@@ -523,13 +598,13 @@ module Eco
523
598
  elsif attr == 'email'
524
599
  value = value.strip.downcase if value
525
600
  value
526
- elsif %w[policy_group_ids filter_tags login_provider_ids starred_ids].include?(attr)
601
+ elsif MULTI_ATTRS.include?(attr)
527
602
  value = @person_parser.parse(:multiple, value)
528
603
  value = value.compact.map(&:upcase) if attr == 'filter_tags'
529
604
  value
530
- elsif %w[freemium accept_eula archived].include?(attr)
605
+ elsif BOOLEAN_ATTRS.include?(attr)
531
606
  @person_parser.parse(:boolean, value)
532
- elsif ['subordinates'].include?(attr)
607
+ elsif NUMERIC_ATTRS.include?(attr)
533
608
  @person_parser.parse(:number, value)
534
609
  else
535
610
  value
@@ -552,7 +627,9 @@ module Eco
552
627
  # Adds to `dest_entry` the `keys` it misses from `source_entry`
553
628
  def merge_missing_attrs(dest_entry, source_entry)
554
629
  keys_rest = source_entry.keys - dest_entry.keys
555
- dest_entry.merge(source_entry.slice(*keys_rest))
630
+ dest_entry.merge(
631
+ source_entry.slice(*keys_rest)
632
+ )
556
633
  end
557
634
 
558
635
  def into_a(value)
@@ -11,7 +11,7 @@ module Eco
11
11
  # @attr_reader all_model_attrs [Array<String>] all the internal
12
12
  # name attributes, including _core_, _account_ and _details_.
13
13
  class PersonParser
14
- extend Eco::API::Common::ClassAutoLoader
14
+ extend Eco::Language::Klass::AutoLoader
15
15
  autoloads_children_of 'Eco::API::Common::Loaders::Parser'
16
16
  autoload_namespace_ignore 'Eco::API'
17
17
 
@@ -61,12 +61,14 @@ module Eco
61
61
  @patch_version = 0
62
62
 
63
63
  if schema
64
- @schema = Ecoportal::API::Internal::PersonSchema.new(JSON.parse(schema.doc.to_json))
64
+ @schema = Ecoportal::API::Internal::PersonSchema.new(
65
+ JSON.parse(schema.doc.to_json)
66
+ )
65
67
  @details_attrs = @schema&.fields&.map(&:alt_id)
66
68
  end
67
69
 
68
70
  @all_model_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
69
- self.class.autoload_children(self)
71
+ self.class.autoload_children!(self)
70
72
  end
71
73
 
72
74
  def patched!
@@ -74,7 +76,9 @@ module Eco
74
76
  end
75
77
 
76
78
  def new(schema: nil)
77
- self.class.new(schema: schema || self.schema).merge(self)
79
+ self.class.new(
80
+ schema: schema || self.schema
81
+ ).merge(self)
78
82
  end
79
83
 
80
84
  # @!group selection options of all select attributes
@@ -90,6 +94,7 @@ module Eco
90
94
  raise msg unless fld.options&.any?
91
95
 
92
96
  options_hash = fld.options.to_h { |v| [v.downcase.strip, v] }
97
+
93
98
  [fld.alt_id, options_hash]
94
99
  end
95
100
  end
@@ -100,7 +105,9 @@ module Eco
100
105
 
101
106
  # @return [Array<Eco::API::Common::Loaders::Parser::RequiredAttrs>]
102
107
  def required_attrs
103
- @parsers.values_at(*all_attrs(include_defined_parsers: true)).compact.map(&:required_attrs).compact
108
+ @parsers.values_at(*all_attrs(
109
+ include_defined_parsers: true
110
+ )).compact.map(&:required_attrs).compact
104
111
  end
105
112
 
106
113
  # All the internal name attributes, including _core_, _account_ and _details_.
@@ -165,8 +172,9 @@ module Eco
165
172
  # - the list is sorted according `CORE_ATTRS` + `ACCOUNT_ATTRS` + schema attrs
166
173
  # @return [Array<String>] list of all attribute defined parsers in the model.
167
174
  def defined_model_attrs
168
- defined = @parsers.keys
169
- defined = (all_model_attrs | defined) & defined
175
+ defined = @parsers.keys
176
+ defined = (all_model_attrs | defined) & defined
177
+
170
178
  defined - symbol_keys
171
179
  end
172
180
 
@@ -247,7 +255,10 @@ module Eco
247
255
  raise msg
248
256
  end
249
257
 
250
- Eco::API::Common::People::PersonAttributeParser.new(attr, dependencies: dependencies).tap do |parser|
258
+ Eco::API::Common::People::PersonAttributeParser.new(
259
+ attr,
260
+ dependencies: dependencies
261
+ ).tap do |parser|
251
262
  @parsers[attr] = parser
252
263
  definition.call(parser)
253
264
  end
@@ -277,8 +288,13 @@ module Eco
277
288
  msg = "There is no parser for attribute '#{attr}'"
278
289
  raise msg unless self.defined?(attr)
279
290
 
280
- @parsers[attr].parse(source, phase, dependencies: deps) do |_dkey, dval|
291
+ @parsers[attr].parse(
292
+ source,
293
+ phase,
294
+ dependencies: deps
295
+ ) do |_dkey, dval|
281
296
  next dval unless dval.is_a?(Proc)
297
+
282
298
  dval.call(self)
283
299
  end
284
300
  end
@@ -297,8 +313,13 @@ module Eco
297
313
  msg = "There is no parser for attribute '#{attr}'"
298
314
  raise msg unless self.defined?(attr)
299
315
 
300
- @parsers[attr].serialize(object, phase, dependencies: deps) do |_dkey, dval|
316
+ @parsers[attr].serialize(
317
+ object,
318
+ phase,
319
+ dependencies: deps
320
+ ) do |_dkey, dval|
301
321
  next dval unless dval.is_a?(Proc)
322
+
302
323
  dval.call(self)
303
324
  end
304
325
  end
@@ -308,7 +329,7 @@ module Eco
308
329
 
309
330
  # @return [Hash] attr-parser pairs with all the defined type and attribute parsers/serializers.
310
331
  def to_h
311
- self.class.autoload_children(self)
332
+ self.class.autoload_children!(self)
312
333
  @parsers
313
334
  end
314
335
 
@@ -323,23 +344,36 @@ module Eco
323
344
  end
324
345
 
325
346
  def attr_to_str(attr)
326
- attr.is_a?(Symbol)? ":#{attr}" : attr.to_s
347
+ return attr.to_s unless attr.is_a?(Symbol)
348
+
349
+ ":#{attr}"
327
350
  end
328
351
 
329
352
  def valid?(attr)
330
- valid_attr?(attr) || valid_type?(attr) || valid_format?(attr)
353
+ return true if valid_attr?(attr)
354
+ return true if valid_type?(attr)
355
+ return true if valid_format?(attr)
356
+
357
+ false
331
358
  end
332
359
 
333
360
  def valid_attr?(attr)
334
- attr.is_a?(String) && (!@schema || @all_model_attrs.include?(attr))
361
+ return false unless attr.is_a?(String)
362
+ return true unless @schema
363
+
364
+ @all_model_attrs.include?(attr)
335
365
  end
336
366
 
337
367
  def valid_type?(attr)
338
- attr.is_a?(Symbol) && TYPE.include?(attr)
368
+ return false unless attr.is_a?(Symbol)
369
+
370
+ TYPE.include?(attr)
339
371
  end
340
372
 
341
373
  def valid_format?(attr)
342
- attr.is_a?(Symbol) && FORMAT.include?(attr)
374
+ return false unless attr.is_a?(Symbol)
375
+
376
+ FORMAT.include?(attr)
343
377
  end
344
378
  end
345
379
  end
@@ -23,8 +23,6 @@ module Eco
23
23
  return [] unless values.is_a?(Enumerable)
24
24
  roam = proc do |tree|
25
25
  [].tap do |out|
26
- sub_outs = tree.empty?? [] : tree.map {|sup, subtree| roam.call(subtree)}
27
-
28
26
  tree.each do |sup, subtree|
29
27
  sout = subtree.empty?? [] : roam.call(subtree)
30
28
  supervisors_first ? sout.unshift(sup) : sout.push(sup)
@@ -46,12 +44,15 @@ module Eco
46
44
 
47
45
  identify = proc do |top_sup, offspring, chain = [top_sup]|
48
46
  next [] if offspring.empty?
47
+
49
48
  offspring.each_with_object([]) do |(sup, subordinates), set|
50
49
  break set unless set.empty?
50
+
51
51
  if top_sup.supervisor_id == sup.id
52
52
  set.concat(chain, [sup])
53
53
  else
54
- set = identify.call(top_sup, subordinates, chain | [sup])
54
+ set.clear
55
+ set.push identify.call(top_sup, subordinates, chain | [sup])
55
56
  end
56
57
  end
57
58
  end
@@ -74,7 +75,7 @@ module Eco
74
75
  end
75
76
 
76
77
  def print_tree(tree, lev: 0)
77
- puts tree_to_str(tree)
78
+ puts tree_to_str(tree, lev: lev)
78
79
  end
79
80
 
80
81
  # Generates a `Hash` tree structure, where:
@@ -86,13 +87,16 @@ module Eco
86
87
  # @return [Hash] the tree structure
87
88
  def supervisors_tree(values) # rubocop:disable Metrics/AbcSize
88
89
  raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
90
+
89
91
  return {} unless values.is_a?(Enumerable)
92
+
90
93
  idx = get_super_indexes(values)
91
94
 
92
95
  processed = []
93
96
  subtree = proc do |entry, level, toptree|
94
97
  if processed.include?(entry)
95
98
  next {} unless toptree.key?(entry) && level.positive?
99
+
96
100
  # needs to be moved as a child
97
101
  subnodes = toptree.delete(entry)
98
102
  processed.delete(entry)
@@ -101,7 +105,8 @@ module Eco
101
105
  subnodes ||= {}.tap do |tree|
102
106
  subs = idx[:subordinates].call(entry)
103
107
  processed.push(entry)
104
- next nil unless subs && !subs.empty?
108
+ next unless subs && !subs.empty?
109
+
105
110
  subs.each do |sub|
106
111
  sub_tree = subtree.call(sub, level + 1, toptree)
107
112
  tree.merge!(sub_tree)
@@ -112,7 +117,7 @@ module Eco
112
117
  end
113
118
 
114
119
  {}.tap do |tree|
115
- idx[:by_sup].keys.each do |sup_id|
120
+ idx[:by_sup].each_key do |sup_id|
116
121
  if (sup = idx[:supers][sup_id])
117
122
  tree.merge!(subtree.call(sup, 0, tree))
118
123
  else
@@ -128,6 +133,7 @@ module Eco
128
133
 
129
134
  def get_super_indexes(values) # rubocop:disable Metrics/AbcSize
130
135
  raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
136
+
131
137
  {}.tap do |indexes|
132
138
  indexes[:by_id] = values.map do |e|
133
139
  e.id && [e.id, e]
@@ -1,84 +1,78 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class BaseSession
6
- attr_writer :session, :config
7
- attr_reader :environment
8
- alias_method :enviro, :environment
9
-
10
- include Session::Helpers
11
- include Eco::Language::AuxiliarLogger
12
-
13
- def initialize(env)
14
- msg = "Expected object Eco::API::Common::Session::Environment. Given: #{env.class}"
15
- raise msg unless env.is_a?(Environment)
16
-
17
- self.environment = env
18
- end
19
-
20
- def session
21
- enviro.session
22
- end
23
-
24
- def environment=(value)
25
- @environment = nil
26
- @environment = value if value.is_a?(Environment)
27
- end
28
- alias_method :enviro=, :environment=
29
-
30
- def config
31
- enviro.config
32
- end
33
-
34
- def api(version: nil)
35
- enviro.api(version: version)
36
- end
37
-
38
- def api?(version: nil)
39
- enviro.api?(version: version)
40
- end
41
-
42
- def file_manager
43
- enviro.file_manager
44
- end
45
- alias_method :fm, :file_manager
46
-
47
- def mailer
48
- enviro.mailer
49
- end
50
-
51
- def mailer?
52
- enviro.mailer?
53
- end
54
-
55
- def sftp
56
- enviro.sftp
57
- end
58
-
59
- def sftp?
60
- enviro.sftp?
61
- end
62
-
63
- def s3uploader
64
- enviro.s3uploader
65
- end
66
-
67
- def s3uploader?
68
- enviro.s3uploader?
69
- end
70
-
71
- def logger
72
- enviro.logger
73
- end
74
-
75
- # TODO: paremeter for the exception
76
- def fatal(msg)
77
- log(:fatal) { msg }
78
- raise msg
79
- end
80
- end
81
- end
1
+ module Eco::API::Common::Session
2
+ class BaseSession
3
+ attr_writer :session, :config
4
+ attr_reader :environment
5
+ alias_method :enviro, :environment
6
+
7
+ include Eco::API::Common::Session::Helpers
8
+ include Eco::Language::AuxiliarLogger
9
+
10
+ def initialize(env)
11
+ msg = "Expected object Eco::API::Common::Session::Environment. Given: #{env.class}"
12
+ raise msg unless env.is_a?(Environment)
13
+
14
+ self.environment = env
15
+ end
16
+
17
+ def session
18
+ enviro.session
19
+ end
20
+
21
+ def environment=(value)
22
+ @environment = nil
23
+ @environment = value if value.is_a?(Environment)
24
+ end
25
+ alias_method :enviro=, :environment=
26
+
27
+ def config
28
+ enviro.config
29
+ end
30
+
31
+ def api(version: nil)
32
+ enviro.api(version: version)
33
+ end
34
+
35
+ def api?(version: nil)
36
+ enviro.api?(version: version)
37
+ end
38
+
39
+ def file_manager
40
+ enviro.file_manager
41
+ end
42
+ alias_method :fm, :file_manager
43
+
44
+ def mailer
45
+ enviro.mailer
46
+ end
47
+
48
+ def mailer?
49
+ enviro.mailer?
50
+ end
51
+
52
+ def sftp
53
+ enviro.sftp
54
+ end
55
+
56
+ def sftp?
57
+ enviro.sftp?
58
+ end
59
+
60
+ def s3uploader
61
+ enviro.s3uploader
62
+ end
63
+
64
+ def s3uploader?
65
+ enviro.s3uploader?
66
+ end
67
+
68
+ def logger
69
+ enviro.logger
70
+ end
71
+
72
+ # TODO: paremeter for the exception
73
+ def fatal(msg)
74
+ log(:fatal) { msg }
75
+ raise msg
82
76
  end
83
77
  end
84
78
  end