eco-helpers 3.0.37 → 3.1.1

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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +116 -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 +39 -7
  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 +49 -55
  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 +89 -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 +63 -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 +1 -1
  36. data/lib/eco/api/organization/people/similarity.rb +3 -3
  37. data/lib/eco/api/session/batch/base_policy.rb +42 -27
  38. data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
  39. data/lib/eco/api/session/batch/launcher.rb +16 -3
  40. data/lib/eco/api/session/config/api.rb +4 -3
  41. data/lib/eco/api/session/config/apis/one_off.rb +1 -1
  42. data/lib/eco/api/session/config/files.rb +13 -12
  43. data/lib/eco/api/session/config/workflow.rb +1 -373
  44. data/lib/eco/api/session/config.rb +30 -9
  45. data/lib/eco/api/usecases/base_case/model.rb +6 -6
  46. data/lib/eco/api/usecases/base_case.rb +1 -1
  47. data/lib/eco/api/usecases/cli.rb +1 -1
  48. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +8 -9
  49. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
  50. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  51. data/lib/eco/api/usecases/lib/base/env.rb +21 -23
  52. data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
  53. data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
  54. data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
  55. data/lib/eco/api/usecases/lib/files.rb +1 -0
  56. data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
  57. data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
  58. data/lib/eco/api/usecases/lib/locations.rb +7 -0
  59. data/lib/eco/api/usecases/lib/people/base.rb +20 -0
  60. data/lib/eco/api/usecases/lib/people.rb +6 -0
  61. data/lib/eco/api/usecases/lib.rb +2 -0
  62. data/lib/eco/api/usecases/ooze_cases.rb +1 -1
  63. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +1 -0
  64. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +1 -0
  65. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
  66. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
  67. data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
  68. data/lib/eco/api/usecases/service/sftp.rb +7 -1
  69. data/lib/eco/api/usecases/use_case.rb +3 -2
  70. data/lib/eco/api/usecases/workflow.rb +5 -0
  71. data/lib/eco/api/usecases.rb +12 -5
  72. data/lib/eco/cli/scripting/args_helpers.rb +1 -9
  73. data/lib/eco/cli_default/options.rb +98 -68
  74. data/lib/eco/cli_default/workflow/end.rb +22 -0
  75. data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
  76. data/lib/eco/cli_default/workflow/load/data.rb +27 -0
  77. data/lib/eco/cli_default/workflow/load/input.rb +28 -0
  78. data/lib/eco/cli_default/workflow/load.rb +13 -0
  79. data/lib/eco/cli_default/workflow/options.rb +10 -0
  80. data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
  81. data/lib/eco/cli_default/workflow/report.rb +17 -0
  82. data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
  83. data/lib/eco/cli_default/workflow/usecases.rb +23 -0
  84. data/lib/eco/cli_default/workflow.rb +24 -180
  85. data/lib/eco/data/count_trace.rb +51 -0
  86. data/lib/eco/data/files/content.rb +39 -0
  87. data/lib/eco/data/files/directory.rb +78 -45
  88. data/lib/eco/data/files/encoding.rb +12 -21
  89. data/lib/eco/data/files/file_pattern.rb +15 -8
  90. data/lib/eco/data/files/folder.rb +196 -0
  91. data/lib/eco/data/files/relative_path.rb +54 -0
  92. data/lib/eco/data/files/timestamp.rb +18 -0
  93. data/lib/eco/data/files.rb +46 -5
  94. data/lib/eco/data/fuzzy_match.rb +1 -1
  95. data/lib/eco/data/hashes/array_diff.rb +11 -5
  96. data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
  97. data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
  98. data/lib/eco/data/mapper.rb +5 -1
  99. data/lib/eco/data.rb +1 -0
  100. data/lib/eco/language/delegation/delegating_missing.rb +1 -1
  101. data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
  102. data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
  103. data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
  104. data/lib/eco/language/klass/auto_loader.rb +129 -0
  105. data/lib/eco/language/klass/builder.rb +6 -6
  106. data/lib/eco/language/klass/const.rb +19 -0
  107. data/lib/eco/language/klass/helpers_built.rb +3 -1
  108. data/lib/eco/language/klass/hierarchy.rb +5 -1
  109. data/lib/eco/language/klass/naming.rb +5 -2
  110. data/lib/eco/language/klass/resolver.rb +21 -6
  111. data/lib/eco/language/klass/uid.rb +12 -0
  112. data/lib/eco/language/klass/when_inherited.rb +30 -6
  113. data/lib/eco/language/klass.rb +5 -2
  114. data/lib/eco/language/methods/access_modifier.rb +23 -0
  115. data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
  116. data/lib/eco/language/methods.rb +1 -0
  117. data/lib/eco/language/models/hierarchy.rb +41 -0
  118. data/lib/eco/language/models/workflow.rb +385 -0
  119. data/lib/eco/language/models.rb +2 -1
  120. data/lib/eco/version.rb +1 -1
  121. metadata +31 -7
  122. data/lib/eco/api/common/class_auto_loader.rb +0 -114
  123. data/lib/eco/api/common/class_helpers.rb +0 -9
  124. data/lib/eco/api/common/class_hierarchy.rb +0 -45
  125. data/lib/eco/data/files/helpers.rb +0 -152
  126. data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -2,23 +2,23 @@ module Eco::Language::Klass
2
2
  module Builder
3
3
  include Resolver
4
4
  include Naming
5
+ include Uid
5
6
 
6
7
  # If the class for `name` exists, it returns it. Otherwise it generates it.
7
8
  # @param name [String, Symbol] the name of the new class
8
9
  # @param inherits [Class] the parent class to _inherit_ from
9
- # @param parent_space [String] parent namespace of the generated class, if not given: `self`
10
+ # @param namespace [Class, String] an existing `constant` (class or module) the new class will be namespaced on
10
11
  # @yield [child_class] configure the new class
11
12
  # @yieldparam child_class [Class] the new class
12
13
  # @return [Class] the new generated class
13
- def new_class(name, inherits:, parent_space: nil)
14
- name = name.to_sym.freeze
14
+ def new_class(name = "Child#{uid}", inherits: self, namespace: inherits)
15
+ name = name.to_s.to_sym.freeze
15
16
  class_name = to_constant(name)
16
- parent_space = parent_space ? resolve_class(parent_space) : self
17
- full_class_name = "#{parent_space}::#{class_name}"
17
+ full_class_name = "#{namespace}::#{class_name}"
18
18
 
19
19
  unless (target_class = resolve_class(full_class_name, exception: false))
20
20
  target_class = Class.new(inherits)
21
- parent_space.const_set class_name, target_class
21
+ Kernel.const_get(namespace.to_s).const_set class_name, target_class
22
22
  end
23
23
 
24
24
  target_class.tap do |klass|
@@ -0,0 +1,19 @@
1
+ module Eco::Language::Klass
2
+ module Const
3
+ def redef_without_warning(sym, value)
4
+ self.class.send(:remove_const, sym) if self.class.const_defined?(sym)
5
+ self.class.const_set(sym, value)
6
+ end
7
+
8
+ def if_const(sym, at: self) # rubocop:disable Naming/MethodParameterName
9
+ value = nil
10
+ value = at.const_get(sym) if at.const_defined?(sym)
11
+
12
+ value.tap do
13
+ next if value.nil?
14
+
15
+ yield(value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,9 @@
1
1
  module Eco::Language::Klass
2
2
  module HelpersBuilt
3
- include Resolver
3
+ include Uid
4
+ include Const
4
5
  include Naming
6
+ include Resolver
5
7
  include Builder
6
8
  include Hierarchy
7
9
  include InheritableClassVars
@@ -1,6 +1,7 @@
1
1
  module Eco::Language::Klass
2
2
  module Hierarchy
3
3
  # Finds all child classes of the current class.
4
+ # @note in native `ruby`, you might want `#subclasses` method.
4
5
  # @param parent_class [Class] the parent class we want to find children of.
5
6
  # @param direct [Boolean] it will only include direct child classes.
6
7
  # @param scope [nil, Array] to only look for descendants among the ones in `scope`.
@@ -28,7 +29,10 @@ module Eco::Language::Klass
28
29
  # @param direct [Boolean] it will only include direct child classes.
29
30
  # @return [Boolean] `true` if the current class has child classes, and `false` otherwise.
30
31
  def descendants?(parent_class: self, direct: false)
31
- descendants(parent_class: parent_class, direct: direct).length.positive?
32
+ descendants(
33
+ parent_class: parent_class,
34
+ direct: direct
35
+ ).length.positive?
32
36
  end
33
37
  end
34
38
  end
@@ -1,11 +1,14 @@
1
1
  module Eco::Language::Klass
2
2
  module Naming
3
3
  # Helper to normalize `key` into a correct `ruby` **constant name**
4
+ # @note it removes namespace syntax `::`
4
5
  # @param key [String, Symbol] to be normalized
5
6
  # @return [String] a correct constant name
6
7
  def to_constant(key)
7
- key.to_s.strip.split(/[\-\_ ]/i).compact.map do |str|
8
- str.slice(0).upcase + str.slice(1..-1).downcase
8
+ key.to_s.strip.split('::').compact.map do |str|
9
+ str.slice(0).upcase + str[1..]&.downcase
10
+ end.join.split(/[\-\_ :]+/i).compact.map do |str|
11
+ str.slice(0).upcase + str[1..]&.downcase
9
12
  end.join
10
13
  end
11
14
 
@@ -1,15 +1,23 @@
1
1
  module Eco::Language::Klass
2
2
  module Resolver
3
- # Creates a class and instance object methods with name `name` to resolve `klass` name
3
+ # Creates a class and instance object methods with name `name`
4
+ # to resolve `klass` name
5
+ # @note the method is defined at instance and class level.
4
6
  def class_resolver(name, klass)
5
7
  define_singleton_method(name) { resolve_class(klass) }
6
- define_method(name) { self.class.resolve_class(klass) }
8
+ define_method(name) { self.class.resolve_class(klass) }
7
9
  end
8
10
 
11
+ # Class resolver
9
12
  # With given a `klass` name it resolves to an actual `Class`
10
- # @return [Class] the class that was being searched by name `klass`.
11
- def resolve_class(klass, exception: true)
12
- @resolved ||= {}
13
+ # @note it caches the resolved `klass`es
14
+ # @raise [Exception] when could not resolve if `exception` is `true`
15
+ # @param klass [Class, String, Symbol] the class to resolve
16
+ # @param source_class [Class] when the reference to `klass` belongs to a different inheritance chain.
17
+ # @param exception [Boolean] if it should raise exception when could not resolve
18
+ # @return [Class] he class that was being searched by name `klass`.
19
+ def resolve_class(klass, source_class: self, exception: true)
20
+ @resolved ||= {}
13
21
  @resolved[klass] ||=
14
22
  case klass
15
23
  when Class
@@ -21,7 +29,14 @@ module Eco::Language::Klass
21
29
  raise if exception
22
30
  end
23
31
  when Symbol
24
- resolve_class(send(klass))
32
+ source_class.resolve_class(source_class.send(klass))
33
+ when Hash
34
+ referrer, referred = klass.first
35
+ resolve_class(
36
+ referred,
37
+ source_class: referrer,
38
+ exception: exception
39
+ )
25
40
  else
26
41
  raise "Unknown class: #{klass}" if exception
27
42
  end
@@ -0,0 +1,12 @@
1
+ require 'securerandom'
2
+
3
+ module Eco::Language::Klass
4
+ module Uid
5
+ # Generates random ids in hexadecimal to use in class name generation.
6
+ # @param len [Integeter] length of the `uid`
7
+ # @return [String] a random unique id of length `len`
8
+ def uid(len = 8)
9
+ SecureRandom.hex(len/2)
10
+ end
11
+ end
12
+ end
@@ -1,15 +1,39 @@
1
1
  module Eco::Language::Klass
2
2
  module WhenInherited
3
- def inherited(subclass)
4
- super
3
+ class << self
4
+ def included(base)
5
+ super
5
6
 
6
- subclass.instance_exec(&when_inherited)
7
+ base.extend InheritableClassVars
8
+ base.extend ClassMethods
9
+
10
+ base.inheritable_class_vars :when_inherited
11
+ end
7
12
  end
8
13
 
9
- def when_inherited(&block)
10
- return @when_inherited unless block_given?
14
+ module ClassMethods
15
+ def inherited(subclass)
16
+ super
17
+
18
+ when_inherited.each_value do |block|
19
+ block.call(subclass)
20
+ end
21
+ end
22
+
23
+ def when_inherited(section = nil, *keys, &block)
24
+ key = [section || :general, *keys]
25
+ @when_inherited ||= {}
26
+
27
+ return @when_inherited unless block_given?
28
+
29
+ if @when_inherited.key?(key)
30
+ msg = "Warn: redefining inheritance on #{key} (#{self})"
31
+ puts msg
32
+ end
11
33
 
12
- @when_inherited = block
34
+ @when_inherited[key] = block
35
+ @when_inherited
36
+ end
13
37
  end
14
38
  end
15
39
  end
@@ -5,10 +5,13 @@ module Eco
5
5
  end
6
6
  end
7
7
 
8
- require_relative 'klass/resolver'
8
+ require_relative 'klass/uid'
9
+ require_relative 'klass/const'
9
10
  require_relative 'klass/naming'
11
+ require_relative 'klass/resolver'
10
12
  require_relative 'klass/builder'
11
13
  require_relative 'klass/hierarchy'
12
- require_relative 'klass/when_inherited'
13
14
  require_relative 'klass/inheritable_class_vars'
14
15
  require_relative 'klass/helpers_built'
16
+ require_relative 'klass/when_inherited'
17
+ require_relative 'klass/auto_loader'
@@ -0,0 +1,23 @@
1
+ module Eco::Language::Methods
2
+ # Helpers to scope change from private to public, etc.
3
+ module AccessModifier
4
+ class << self
5
+ def included(base)
6
+ super
7
+
8
+ base.extend ClassMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def make_public(*args, base: self)
14
+ base.public(*args)
15
+ end
16
+
17
+ # Makes **public** in `base` all those **private** methods of `from`.
18
+ def make_public_all(base = self, from: base, inherited: false)
19
+ base.send(:public, *from.private_instance_methods(inherited: inherited))
20
+ end
21
+ end
22
+ end
23
+ end
@@ -12,7 +12,12 @@ module Eco::Language::Methods
12
12
  module ClassMethods
13
13
  private
14
14
 
15
- def unless_instance_method(base = self, name:, include_private: true, inherited: true)
15
+ def unless_instance_method(
16
+ base = self,
17
+ name:,
18
+ include_private: true,
19
+ inherited: true
20
+ )
16
21
  return false if instance_method?(base, name: name, include_private: include_private, inherited: inherited)
17
22
 
18
23
  yield if block_given?
@@ -6,5 +6,6 @@ module Eco
6
6
  end
7
7
 
8
8
  require_relative 'methods/instance_method_helpers'
9
+ require_relative 'methods/access_modifier'
9
10
  require_relative 'methods/call_detector'
10
11
  require_relative 'methods/dsl_able'
@@ -0,0 +1,41 @@
1
+ module Eco::Language::Models
2
+ # Helpers for dynammic generation of classes based on a hierarchical model
3
+ # @note you might want to use it in combination
4
+ # with `Eco::Language::Klass::HelpersBuilt`
5
+ # @attr_reader model [Hash, nil] the `model` of the current `class`
6
+ module Hierarchy
7
+ attr_reader :model
8
+
9
+ # @param value [Hash, Enumerable, String, Symbol, nil] unparsed model to be assigned to the `class`
10
+ def model=(value)
11
+ @model = parse_model(value)
12
+ end
13
+
14
+ # @return [Array<String>] the `keys` of the current class' `model`
15
+ def model_attrs
16
+ model&.keys || []
17
+ end
18
+
19
+ # Thanks to this step the format on the declaration of the model is flexible
20
+ # @param model [Hash, Enumerable, String, Symbol, nil]
21
+ # @return [Hash, nil] where keys are `Symbol` s
22
+ def parse_model(model)
23
+ case model
24
+ when String
25
+ parse_model(model.to_sym)
26
+ when Symbol
27
+ {model => nil}
28
+ when Hash
29
+ model.transform_keys(&:to_sym)
30
+ when Enumerable
31
+ model.each_with_object({}) do |sub, hash|
32
+ hash.merge!(parse_model(sub))
33
+ end
34
+ when NilClass
35
+ nil
36
+ else
37
+ raise "Incorrect model declaration, allowed String, Symbol, Hash and Enumerable. Given: #{model.class}"
38
+ end
39
+ end
40
+ end
41
+ end