Class: Eco::API::Common::Loaders::Workflow::Mailer
- Inherits:
-
Eco::API::Common::Loaders::Workflow
- Object
- Config
- Eco::API::Common::Loaders::Workflow
- Eco::API::Common::Loaders::Workflow::Mailer
- Defined in:
- lib/eco/api/common/loaders/config/workflow/mailer.rb
Direct Known Subclasses
Constant Summary collapse
- ORG =
'your organization'.freeze
- TRACE_COUNT =
3- EP_EMAIL =
/@.*?ecoportal\.co(!:m|\.nz)$/- ALT_TO =
%w[ [email protected] [email protected] ].freeze
Class Attribute Summary collapse
-
.error ⇒ Object
Returns the value of attribute error.
Class Method Summary collapse
- .active_enviro_desc ⇒ Object
- .alternative_emails(io) ⇒ Object
-
.base_subject ⇒ Object
@todo: add whether it is a dry-run and if we are on certain enviro.
- .env_based_mailer!(io) ⇒ Object
- .error? ⇒ Boolean
- .error_message ⇒ Object
- .errors_n_warnings(io) ⇒ Object
- .general_messages(io) ⇒ Object
- .host(io) ⇒ Object
- .live?(io) ⇒ Boolean
- .log_err_n_warn(io) ⇒ Object
- .maybe_error_pages_or_tree_updates?(io) ⇒ Boolean
- .notify?(io) ⇒ Boolean
- .org_name ⇒ Object
- .trace_count ⇒ Object
Methods inherited from Eco::API::Common::Loaders::Workflow
Class Attribute Details
.error ⇒ Object
Returns the value of attribute error.
41 42 43 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 41 def error @error end |
Class Method Details
.active_enviro_desc ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 89 def active_enviro_desc space_desc = config.active_enviro_space.to_s.strip space_desc = '' if space_desc == 'default' space_desc = " - space: '#{space_desc}'" unless space_desc.empty? "#{active_enviro}#{space_desc}" end |
.alternative_emails(io) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 65 def alternative_emails(io) email_to = io.session.config.mailer.to email_to = [email_to].flatten.compact alt_emails = email_to.grep(EP_EMAIL) alt_emails = ALT_TO if alt_emails.empty? alt_emails end |
.base_subject ⇒ Object
@todo: add whether it is a dry-run and if we are on certain enviro.
- The target env could probably be added as a :general message.
85 86 87 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 85 def base_subject "#{org_name} (#{active_enviro_desc}) at #{Time.now.iso8601}" end |
.env_based_mailer!(io) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 57 def env_based_mailer!(io) return if live?(io) || !io.session.config.dry_run? # redirect mailing to eP Staff when not in `live` env. # or when in `dry-run` io.session.config.mailer.to = alternative_emails(io) end |
.error? ⇒ Boolean
97 98 99 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 97 def error? !!error end |
.error_message ⇒ Object
124 125 126 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 124 def error&.(trace_count: 3) end |
.errors_n_warnings(io) ⇒ Object
113 114 115 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 113 def errors_n_warnings(io) [, log_err_n_warn(io)].join("\n") end |
.general_messages(io) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 106 def (io) gen_msg = io.logger.cache.logs(level: i[general]) return if gen_msg.empty? "GENERAL MESSAGES:\n#{gen_msg.join}\n" end |
.host(io) ⇒ Object
Note:
this initiates a connection to the API (undesired)
79 80 81 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 79 def host(io) io.session.api.client.host end |
.live?(io) ⇒ Boolean
74 75 76 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 74 def live?(io) host(io).downcase.start_with?('live.') end |
.log_err_n_warn(io) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 117 def log_err_n_warn(io) warn_errors = io.logger.cache.logs(level: i[error warn]) return if warn_errors.empty? "ALL WARNINGS & ERRORS:\n#{warn_errors.join}\n" end |
.maybe_error_pages_or_tree_updates?(io) ⇒ Boolean
Note:
at some stage, tree cases should have their own case type
102 103 104 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 102 def maybe_error_pages_or_tree_updates?(io) some_other_case?(io) && error? end |
.notify?(io) ⇒ Boolean
47 48 49 50 51 52 53 54 55 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 47 def notify?(io) return false if io..dig(:workflow, :no_email) return false unless io.session.mailer? return true if io..dig(:workflow, :notify) return false if io.session.config.dry_run? return false unless io.session.config.run_mode_remote? true end |
.org_name ⇒ Object
43 44 45 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 43 def org_name self::ORG end |
.trace_count ⇒ Object
128 129 130 |
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 128 def trace_count self::TRACE_COUNT end |