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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 949959ec22add3fc3f7e78ed155c66a95b8c1d6757eb90ca40bf74918f379170
4
- data.tar.gz: 80be5ed4e76e97460857f6c3a9f5afe23b735519e9f4fb2d1822817f84b794d3
3
+ metadata.gz: 4b81231f7cbb64973d578ac889c8510db4f5db5b9458468c34a56144916d731d
4
+ data.tar.gz: eb56be6c8c704c7b4b85ac2acdf0fd567ab6322e1257e6ac1442076eebb0aa77
5
5
  SHA512:
6
- metadata.gz: 730da2f221461b9700eafaef73985e603b0edb0fd2bc89a532c6640d07200462e5fde05048c176dc5caace42114639d4101daf71fbd197356610c86423b45812
7
- data.tar.gz: 26eb938cb1967430ee26e8eb0b82a7a1ed9b777ae38087ec0e47ec0b90af0d99a5cecf5ee8b36ccd9353a8ae1f408d342d565b6b1ab645d3e40141f8dae4e458
6
+ metadata.gz: be7da006d5532c0c66f7130b44da3d0058927f73f9b861dd833fc79c0229f2a710be49d40e0ff4345048c2f6147702f158ec8b5994e8334f8663ea0c41f7d374
7
+ data.tar.gz: 0aa4345fbaef61362f428cb70d6a2a4719755fba8e9bf2f6436eeddc7eeacf872f79bbbf4e459ac8d7df64cbad129ff2e7c58f4c1d572ecfa4c0340a14825436
data/.rubocop.yml CHANGED
@@ -33,6 +33,7 @@ Style/BlockDelimiters:
33
33
  Style/HashSyntax:
34
34
  EnforcedShorthandSyntax: either
35
35
  EnforcedStyle: no_mixed_keys
36
+
36
37
  Style/ArgumentsForwarding:
37
38
  UseAnonymousForwarding: false
38
39
  Style/ClassAndModuleChildren:
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [3.0.37] - 2025-04-xx
5
+ ## [3.1.2] - 2025-04-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,121 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [3.1.1] - 2025-04-30
14
+
15
+ This release mostly aims a **refactoring** on _**Files Handling**_.
16
+
17
+ - There are different helper libraries in this regard. The client scripts, end up re-defining its own input/output file handling.
18
+ - While it is challenging to keep a unique access point that shows up to be functional to all the client scrits/usecases, some tidy up on time should be attempted with the aim of gathering some functions that can further simply code on the client scrits, while keeping internal consistency in the gem itself.
19
+
20
+ It also sets the basics for having **multiple workflows** to choose among. This aims to have different workflows (depending the case we deal with).
21
+
22
+ This release also aims to be able to run automated tests against test environment. Where notifications are sent.
23
+
24
+ ### Added
25
+
26
+ - **Option** `-notify` (to force email to be sent)
27
+ - This skips safeguard of `dry-run` and non remote runs (it notifies anyway).
28
+ - **`Eco::Language::Klass`**:
29
+ - **Added** `Eco::Language::Klass::Uid` generator.
30
+ - **Added** `Eco::Language::Klass::Const` helpers (`redef_without_warning`).
31
+ - **Added** `Eco::API::UseCases::Lib::Files::InputFile` (for **standardization**)
32
+ - This aims to address proliferation of cases that try to define it.
33
+ - And unify code under one single lib.
34
+ - **Added** `Eco::API::UseCases::Lib::People::Base`
35
+ - Some cases need to lookup people.
36
+ - `Eco::Data::Files::Folder`:
37
+ - **Added** method `#ensure_file_path!`
38
+ - **Added** method `#archive_file`
39
+ - **Added** function `#clear_folder`
40
+ - **Safe-guard**: files matching `PRESERVED_FILES` regexp patterns will be excluded. For example, it could be that the folder was the root `.`, or it could be a gitignored folder with scripts.
41
+ - for `#folder_files`:
42
+ - **Added** named argument `newer_than`
43
+ - **Added** `newer_than` argument to `#clear_folder` and `#csv_files`
44
+ - It **logs** whether it found files and which ones (these logs are with the **relative** path to the working folder).
45
+ - `Eco::Data::Files::RelativePath`:
46
+ - To mask the absolute path of the file, and make it relative to the working directory.
47
+ - **Added** `Eco::Language::Methods::AccessModifier`
48
+ - To help in moving private methods to be public in some service classes that reuse modules where methods are defined as private.
49
+ - `Eco::API::Session::Config#locations_mapper`
50
+ - **Added**: ability to specify case sensitive & order of column mappings.
51
+ - `Eco::Language::Klass::Resolver#resolve_class`
52
+ - **Added** named argument `source_class:`, provided that look ups are performed in that space.
53
+ - `Eco::Language::Klass::Const`
54
+ - **Added** `if_const`
55
+ - `Eco::API::Session::Config#locations_mapper`
56
+ - **Added** argument to specify the `maps_file`
57
+ - **Improved** provided that it is **caching** _based on arguments_
58
+ - **Added** `Eco::Data::Mapper#empty?`
59
+ - **Added** `Eco::Data::CountTrace`
60
+ - Helpful to track how many times a value has been found.
61
+ - **Added** `Eco::API::UseCases::Lib::Locations` with module helpers:
62
+ - `Base` (i.e. `#tagtree`)
63
+ - `Mapping` (i.e. `#to_location` / `#to_tag`)
64
+ - `Eco::API::Common::Loaders::Config::Block` (moved from `Loaders::Config`)
65
+ - **Added** methods:
66
+ - `#config_apply!`
67
+ - `#config_copy`
68
+ - `Eco::Language::Models::Workflow`
69
+ - **moved** most logic from `Session::Config::Workflow`, provided we can build different workflows.
70
+ - **added** workflow builder: `Eco::API::UseCases::Workflow`
71
+ - **simplified** `Eco::API::Session::Config::Workflow` via **inheritance**.
72
+ - `Eco::API::Common::Session::Mailer::ProviderBase`
73
+ - **Fetch** `ENV` vars `MAILER_FROM` and `MAILER_TO`
74
+
75
+ ### Changed
76
+
77
+ - **Changed** `Eco::API::Session::Batch::Launcher#launch_batch`
78
+ - It **won't** use the `batch/job` endpoint, unless `MIN_JOB_SIZE` is reached.
79
+ - **Refactored** `Eco::API::UseCases::Service::Sftp`
80
+ - Making public methods of `Eco::API::UseCases::Lib::Files::Sftp` by rather using `Eco::Language::Methods::AccessModifier`
81
+ - `Eco::API::UseCases::Lib::Files::Sftp` method `sftp_archive_file!`
82
+ - **Changed** named argument `folder:` to `subfolder:`
83
+ - **Moved** class **auto loader** to **Language** namespace
84
+ - `Eco::API:Common::Loaders::Base`
85
+ - Redefined `#options` as per `Loaders::Parser` definition
86
+ - **Decoupled** `Eco::Data::Files::Helpers` into:
87
+ - **`Eco::Data::Files::Folder`**
88
+ - `#folder_files`: argument `pattern` that comes as a `Symbol` is now interpreted as the file **extension** that should be matched in `folder`.
89
+ - **`Eco::Data::Files::Content`** (instance methods)
90
+ - **`Eco::Data::Files::Timestamp`**
91
+ - **Renamed** constant `DEFAULT_TIMESTAMP_PATTERN` to `DEFAULT_TIMESTAMP`
92
+ - **Made Explicit** _`included`_ logic on `Data::Files` itself
93
+ - **Removed** `Files::Helpers` module completely.
94
+ - _Files helpers_ **changes**
95
+ - **Removed** `#file_exists?` and `#dir_exists?` in favor of **native** `ruby`.
96
+ - **Removed** (unused methods)`#file_basename`, `#file_fullpath` and `#file_name` in favor of **native** `ruby`.
97
+ - **Moved** `#script_subfolder` to be class method for `Files::Directory`
98
+ - **Changed** method name `#has_bom?` to `bom?` (`Eco::Data::Files::Encoding`)
99
+ - **Removed** `Eco::Data::Files::Directory.create` in favour of **native** `ruby`
100
+ - This adds requirement onto **`fileutils`** (for `FileUtils.mkdir_p`)
101
+ - **Changed** `Eco::Data::Files::Directory#create` to rather use **native** `ruby` when ensuring folder to exist. It now **returns** `Boolean` instead.
102
+ - **Renamed** `exists?` to `Eco::Data::Files::Directory#exist?`
103
+ - **Refactored** `Eco::API::UseCases::Lib::Files::FilePattern`
104
+ - renamed and decoupled some functions to better reflect their role.
105
+ - regex patterns comming from consts that are strings, would get converted to `Regexp`
106
+ - **Moved** class **ClassHierarchy** to `Eco::Language::Models` namespace
107
+ - **Removed** class **`ClassHelpers`**
108
+ - **Moved** to `Eco::Language::Klass::HelpersBuilt`
109
+ - `Eco::Language::Klass::Naming#to_constant`: included case where a full namespace is provided
110
+ - `Eco::Language::Class::Builder`
111
+ - **Changed** parameter name from `parent_space` to `namespace`
112
+ - `Eco::API::Session::Config#locations_mapper`
113
+ - When no file specified, it will return `nil`
114
+ - `Eco::API::Common::Loaders::Config`
115
+ - **Decoupled** `Block` and **added** parameter `section` to be able to have multiple configurations.
116
+ - `@config_block` is now **inheritable**
117
+ - `Eco::Language::Klass::WhenInherited`
118
+ - Allows to define multiple blocks to be called on inheritance.
119
+ - It now passes the `subclass` to the called block.
120
+ - `Eco::CliDefault::Workflow` split/decoupled into module workflow configurations (one per stage).
121
+
122
+ ### Fixed
123
+
124
+ - `Eco::API::UseCases::Lib::Base::Env`
125
+ - Call to `super` shouldn't carry the arguments for `session` and `options`
126
+ - `one_off?` to be cli based
127
+
13
128
  ## [3.0.37] - 2025-04-15
14
129
 
15
130
  ### Fixed
@@ -3,7 +3,7 @@ module Eco
3
3
  module Common
4
4
  module Loaders
5
5
  class Base
6
- extend Eco::API::Common::ClassHelpers
6
+ extend Eco::Language::Klass::HelpersBuilt
7
7
  include Eco::Language::AuxiliarLogger
8
8
 
9
9
  class << self
@@ -54,7 +54,7 @@ module Eco
54
54
  end
55
55
 
56
56
  def options
57
- @options ||= {}
57
+ @options ||= ASSETS.cli.options
58
58
  end
59
59
 
60
60
  def config
@@ -28,6 +28,8 @@ module Eco
28
28
  end
29
29
  end
30
30
 
31
+ # Instance Methods
32
+
31
33
  def name
32
34
  self.class.name
33
35
  end
@@ -0,0 +1,78 @@
1
+ class Eco::API::Common::Loaders::Config
2
+ module Block
3
+ class << self
4
+ def included(base)
5
+ super
6
+
7
+ base.extend ClassMethods
8
+ base.extend Eco::Language::Klass::InheritableClassVars
9
+
10
+ base.inheritable_class_vars :config_block
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ # To create samples of configurations
16
+ def config_block(section = nil, *keys, &block)
17
+ section ||= :general
18
+ key = [section, *keys]
19
+ @config_block ||= {}
20
+
21
+ return @config_block[key] unless block_given?
22
+
23
+ unless @config_block[key].nil?
24
+ msg = "Reconfiguring config_block (#{key}) on #{self}"
25
+ session.log(:warn) { msg }
26
+ end
27
+
28
+ @config_block[key] = block
29
+ end
30
+
31
+ # Applies the configuration to the target `on`.
32
+ def config_apply!(*key, on: self, all: false) # rubocop:disable Naming/MethodParameterName
33
+ if all
34
+ @config_block ||= {}
35
+
36
+ @config_block.each_key do |k|
37
+ config_apply!(*k, on: on)
38
+ end
39
+ else
40
+ on.instance_exec(&config_block(*key))
41
+ end
42
+
43
+ self
44
+ rescue LocalJumpError => err
45
+ puts "Missing config block for key '#{key}': #{err}"
46
+ raise
47
+ end
48
+
49
+ def config_copy(*key, to:, all: false)
50
+ @config_block ||= {}
51
+
52
+ if all
53
+ @config_block.dup.each do |keys, block|
54
+ to.config_block(*keys, &block)
55
+ end
56
+ else
57
+ to.config_block(*key, &config_block(*key))
58
+ end
59
+
60
+ self
61
+ end
62
+
63
+ private
64
+
65
+ def config(...)
66
+ ASSETS.config(...)
67
+ end
68
+
69
+ def cli
70
+ ASSETS.cli
71
+ end
72
+
73
+ def active_enviro
74
+ config.active_enviro
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,9 +1,14 @@
1
1
  class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::Workflow
2
- ORG = 'your organization'.freeze
2
+ ORG = 'your organization'.freeze
3
3
  TRACE_COUNT = 3
4
+ ALT_TO = %w[
5
+ oscar@ecoportal.co.nz
6
+ travis@ecoportal.co.nz
7
+ ].freeze
4
8
 
5
9
  inheritable_class_vars :config_block
6
10
 
11
+ # @todo different emailing, depending on case type and/or preference
7
12
  config_block do
8
13
  #puts "running from class #{self}"
9
14
  exception do |err, io|
@@ -12,11 +17,10 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
12
17
  workflow.run(:close, io: io)
13
18
  end
14
19
 
15
- after(:close) do |_wf, io|
16
- next if options.dig(:workflow, :no_email)
17
- next unless session.mailer?
18
- next if session.config.dry_run?
19
- next unless session.config.run_mode_remote?
20
+ after(:close) do
21
+ env_based_mailer!(io)
22
+
23
+ next unless notify?(io)
20
24
 
21
25
  # temporary contingency: maybe_error_or_tree_updates?
22
26
  next unless some_update_case?(io) || maybe_error_pages_or_tree_updates?(io)
@@ -25,7 +29,7 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
25
29
  subject = "#{subject} & Errors" if session.job_groups.errors?
26
30
  subject = "#{subject} - Exception!" if error?
27
31
 
28
- body = general_messages(io) || ''
32
+ body = general_messages || ''
29
33
  body << "\n#{session.summary}" unless session.job_groups.empty? && error?
30
34
  body << "\n#{errors_n_warnings(io)}"
31
35
 
@@ -40,6 +44,34 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
40
44
  self::ORG
41
45
  end
42
46
 
47
+ def notify?(io)
48
+ return false if io.options.dig(:workflow, :no_email)
49
+ return false unless io.session.mailer?
50
+ return true if io.options.dig(:workflow, :notify)
51
+ return false if io.session.config.dry_run?
52
+ return false if io.session.config.run_mode_remote?
53
+
54
+ true
55
+ end
56
+
57
+ def env_based_mailer!(io)
58
+ return if live?(io) || !io.session.config.dry_run?
59
+
60
+ # redirect mailing to eP Staff when not in `live` env.
61
+ # or when in `dry-run`
62
+ io.session.config.mailer.to = alternative_emails
63
+ end
64
+
65
+ def live?(io)
66
+ host(io).downcase.start_with?('live.')
67
+ end
68
+
69
+ def host(io)
70
+ io.session.api.client.host
71
+ end
72
+
73
+ # @todo: add whether it is a dry-run and if we are on certain enviro.
74
+ # - The target env could probably be added as a :general message.
43
75
  def base_subject
44
76
  "#{org_name} (#{active_enviro_desc}) at #{Time.now.iso8601}"
45
77
  end
@@ -1,33 +1,10 @@
1
+ require_relative 'config/block'
2
+
1
3
  class Eco::API::Common::Loaders::Config
4
+ include Block
2
5
  include Eco::Language::Delegation::DelegatingMissingOnClass
3
6
 
4
7
  delegating_missing_on_class_to :config
5
-
6
- class << self
7
- # To create samples of configurations
8
- def config_block(&block)
9
- return @config_block unless block_given?
10
-
11
- unless @config_block.nil?
12
- msg = "Reconfiguring config_block on #{self}"
13
- session.log(:warn) { msg }
14
- end
15
-
16
- @config_block = block
17
- end
18
-
19
- def config(...)
20
- ASSETS.config(...)
21
- end
22
-
23
- def cli
24
- ASSETS.cli
25
- end
26
-
27
- def active_enviro
28
- config.active_enviro
29
- end
30
- end
31
8
  end
32
9
 
33
10
  require_relative 'config/cli'
@@ -18,6 +18,8 @@ module Eco
18
18
 
19
19
  inheritable_class_vars :error
20
20
 
21
+ # Instance Methods
22
+
21
23
  def initialize(handlers) # rubocop:disable Lint/MissingSuper
22
24
  msg = "Expected Eco::API::Policies. Given #{handlers.class}"
23
25
  raise msg unless handlers.is_a?(Eco::API::Error::Handlers)
@@ -18,6 +18,7 @@ module Eco
18
18
 
19
19
  match = input_attrs & attrs
20
20
  miss = attrs - match
21
+
21
22
  return [] if miss.empty?
22
23
  return attrs if match.empty?
23
24
  return miss if type == :all
@@ -154,10 +155,6 @@ module Eco
154
155
 
155
156
  private
156
157
 
157
- def options
158
- ASSETS.cli.options
159
- end
160
-
161
158
  def _define_parser(attr_parser)
162
159
  if (active_when = self.class.active_when)
163
160
  attr_parser.def_parser(
@@ -40,7 +40,9 @@ module Eco
40
40
 
41
41
  def candidates_summary
42
42
  lines = ["The following entries have the same '#{property}':"]
43
- lines.concat(identify_candidates(with_index: true)).join("\n ")
43
+ lines.concat(
44
+ identify_candidates(with_index: true)
45
+ ).join("\n ")
44
46
  end
45
47
  end
46
48
 
@@ -129,7 +131,13 @@ module Eco
129
131
  id = attr_value(object, 'id')
130
132
  external_id = attr_value(object, 'external_id')
131
133
  email = attr_value(object, 'email')
132
- entry(id: id, external_id: external_id, email: email, strict: strict)
134
+
135
+ entry(
136
+ id: id,
137
+ external_id: external_id,
138
+ email: email,
139
+ strict: strict
140
+ )
133
141
  end
134
142
  # @!endgroup
135
143
 
@@ -150,6 +158,7 @@ module Eco
150
158
  discarded = list.map do |person|
151
159
  find(person)
152
160
  end.compact
161
+
153
162
  newFrom to_a - discarded
154
163
  end
155
164
 
@@ -159,11 +168,14 @@ module Eco
159
168
  # @param parsing_phase [Symbol] data as per specific parsing stage.
160
169
  def export(filename, parsing_phase: :internal)
161
170
  header = each_with_object([]) do |entry, hds|
162
- hds.push(*entry.entry(parsing_phase).keys).uniq!
171
+ hds.push(
172
+ *entry.entry(parsing_phase).keys
173
+ ).uniq!
163
174
  end
164
175
 
165
176
  CSV.open(filename, 'w') do |csv|
166
177
  csv << header
178
+
167
179
  each do |entry|
168
180
  csv << entry.entry(parsing_phase).values_at(*header)
169
181
  end
@@ -194,14 +206,18 @@ module Eco
194
206
  private
195
207
 
196
208
  def entry_by_email(email, prevent_multiple_match: false)
197
- return nil unless email
209
+ return unless email
198
210
 
199
211
  candidates = @by_email[email] || []
200
212
  return candidates.first if candidates.length == 1
201
213
 
202
214
  if prevent_multiple_match && !candidates.empty?
203
215
  msg = 'Multiple search results match the criteria.'
204
- raise MultipleSearchResults.new(msg, candidates: candidates, property: 'email')
216
+ raise MultipleSearchResults.new(
217
+ msg,
218
+ candidates: candidates,
219
+ property: 'email'
220
+ )
205
221
  end
206
222
 
207
223
  @by_external_id[email]&.first
@@ -209,10 +225,11 @@ module Eco
209
225
 
210
226
  def init_caches
211
227
  return if @caches_init
228
+
212
229
  @by_id = no_nil_key(to_h)
213
230
  @by_external_id = no_nil_key(to_h('external_id'))
214
231
  @by_email = no_nil_key(to_h('email'))
215
- @caches_init = true
232
+ @caches_init = true
216
233
  end
217
234
 
218
235
  def no_nil_key(hash)
@@ -250,7 +250,7 @@ module Eco
250
250
  fatal msg unless @person_parser.defined?(format)
251
251
 
252
252
  run = true
253
- if self.class.file_exists?(file)
253
+ if File.exist?(file)
254
254
  prompt_user(
255
255
  'Do you want to overwrite it? (Y/n):',
256
256
  explanation: "The file '#{file}' already exists.",