Class: Eco::API::Common::Loaders::Workflow::Mailer

Inherits:
Eco::API::Common::Loaders::Workflow show all
Defined in:
lib/eco/api/common/loaders/config/workflow/mailer.rb

Direct Known Subclasses

Eco::API::Custom::Mailer

Constant Summary collapse

ORG =
'your organization'.freeze
TRACE_COUNT =
3
ALT_TO =
%w[
  oscar@ecoportal.co.nz
  travis@ecoportal.co.nz
].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Eco::API::Common::Loaders::Workflow

workflow

Class Attribute Details

.errorObject

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_descObject



79
80
81
82
83
84
85
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 79

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

.base_subjectObject

@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.


75
76
77
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 75

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
end

.error?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 87

def error?
  !!error
end

.error_messageObject



114
115
116
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 114

def error_message
  error&.patch_full_message(trace_count: 3)
end

.errors_n_warnings(io) ⇒ Object



103
104
105
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 103

def errors_n_warnings(io)
  [error_message, log_err_n_warn(io)].join("\n")
end

.general_messages(io) ⇒ Object



96
97
98
99
100
101
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 96

def general_messages(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



69
70
71
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 69

def host(io)
  io.session.api.client.host
end

.live?(io) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 65

def live?(io)
  host(io).downcase.start_with?('live.')
end

.log_err_n_warn(io) ⇒ Object



107
108
109
110
111
112
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 107

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

Returns:

  • (Boolean)


92
93
94
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 92

def maybe_error_pages_or_tree_updates?(io)
  some_other_case?(io) && error?
end

.notify?(io) ⇒ Boolean

Returns:

  • (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.options.dig(:workflow, :no_email)
  return false unless io.session.mailer?
  return true  if     io.options.dig(:workflow, :notify)
  return false if     io.session.config.dry_run?
  return false if     io.session.config.run_mode_remote?

  true
end

.org_nameObject



43
44
45
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 43

def org_name
  self::ORG
end

.trace_countObject



118
119
120
# File 'lib/eco/api/common/loaders/config/workflow/mailer.rb', line 118

def trace_count
  self::TRACE_COUNT
end