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
@@ -1,43 +1,35 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger
6
- module Channels
7
- CHANNELS = %i[general].freeze
1
+ class Eco::API::Common::Session::Logger
2
+ module Channels
3
+ CHANNELS = %i[general].freeze
8
4
 
9
- class << self
10
- def included(base)
11
- super
5
+ class << self
6
+ def included(base)
7
+ super
12
8
 
13
- base.extend ClassMethods
14
- end
15
- end
16
-
17
- module ClassMethods
18
- def channels!(&def_block)
19
- str = 'Block with channel implementation expected. None given.'
20
- raise ArgumentError, str unless block_given?
21
-
22
- channels.each do |channel|
23
- meth = channel.to_s.downcase.to_sym
9
+ base.extend ClassMethods
10
+ end
11
+ end
24
12
 
25
- define_method(meth) do |msg = nil, &block|
26
- # `block` instead of `&block`
27
- instance_exec(meth, msg, block, &def_block)
28
- end
29
- end
30
- end
13
+ module ClassMethods
14
+ def channels!(&def_block)
15
+ str = 'Block with channel implementation expected. None given.'
16
+ raise ArgumentError, str unless block_given?
31
17
 
32
- private
18
+ channels.each do |channel|
19
+ meth = channel.to_s.downcase.to_sym
33
20
 
34
- def channels
35
- self::CHANNELS
36
- end
37
- end
21
+ define_method(meth) do |msg = nil, &block|
22
+ # `block` instead of `&block`
23
+ instance_exec(meth, msg, block, &def_block)
38
24
  end
39
25
  end
40
26
  end
27
+
28
+ private
29
+
30
+ def channels
31
+ self::CHANNELS
32
+ end
41
33
  end
42
34
  end
43
35
  end
@@ -1,49 +1,41 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger
6
- class Log
7
- attr_accessor :level, :datetime, :message, :formatted
8
-
9
- def initialize(level, datetime, message, formatted)
10
- @level = level
11
- @datetime = datetime
12
- @message = message
13
- @formatted = formatted
14
- end
15
-
16
- def to_s
17
- formatted
18
- end
19
-
20
- def <=>(other)
21
- datetime <=> other.datetime
22
- end
23
-
24
- def before?(value)
25
- return true unless value
26
-
27
- datetime <= to_datetime(value)
28
- end
29
-
30
- def after?(value)
31
- return true unless value
32
-
33
- datetime >= to_datetime(value)
34
- end
35
-
36
- private
37
-
38
- def to_datetime(value)
39
- return value if value.is_a?(Time)
40
- return unless value
41
-
42
- Time.parse(value)
43
- end
44
- end
45
- end
46
- end
1
+ class Eco::API::Common::Session::Logger
2
+ class Log
3
+ attr_accessor :level, :datetime, :message, :formatted
4
+
5
+ def initialize(level, datetime, message, formatted)
6
+ @level = level
7
+ @datetime = datetime
8
+ @message = message
9
+ @formatted = formatted
10
+ end
11
+
12
+ def to_s
13
+ formatted
14
+ end
15
+
16
+ def <=>(other)
17
+ datetime <=> other.datetime
18
+ end
19
+
20
+ def before?(value)
21
+ return true unless value
22
+
23
+ datetime <= to_datetime(value)
24
+ end
25
+
26
+ def after?(value)
27
+ return true unless value
28
+
29
+ datetime >= to_datetime(value)
30
+ end
31
+
32
+ private
33
+
34
+ def to_datetime(value)
35
+ return value if value.is_a?(Time)
36
+ return unless value
37
+
38
+ Time.parse(value)
47
39
  end
48
40
  end
49
41
  end
@@ -1,74 +1,70 @@
1
- module Eco
2
- module API
3
- module Common
4
- module Session
5
- class Logger < Eco::Language::BasicLogger
6
- TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze
7
-
8
- require_relative 'logger/channels'
9
- include Channels
10
-
11
- channels! do |channel, message = nil, block|
12
- format_proc(console: true) do |severity, datetime, msg, formatted_msg|
13
- cache.add(severity, datetime, msg, formatted_msg)
14
- end.call(channel, Time.now, 'prog_name', message || block.call)
15
- end
1
+ module Eco::API::Common::Session
2
+ class Logger < Eco::Language::BasicLogger
3
+ TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze
16
4
 
17
- attr_reader :cache
5
+ require_relative 'logger/channels'
6
+ include Channels
18
7
 
19
- def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
20
- super(**kargs)
8
+ channels! do |channel, message = nil, block|
9
+ format_proc(console: true) do |severity, datetime, msg, formatted_msg|
10
+ cache.add(severity, datetime, msg, formatted_msg)
11
+ end.call(channel, Time.now, 'prog_name', message || block.call)
12
+ end
21
13
 
22
- msg = "Required Environment object (enviro:). Given: #{enviro.class}"
23
- raise ArgumentError, msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
14
+ attr_reader :cache
24
15
 
25
- @enviro = enviro
26
- @cache = Logger::Cache.new
16
+ def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
17
+ super(**kargs)
27
18
 
28
- if (log_file = fetch_log_file(log_file))
29
- loggers[:file] = ::Logger.new(log_file).tap do |logger|
30
- logger.formatter = format_proc(console: false) do |severity, datetime, msg, formatted_msg|
31
- cache.add(severity, datetime, msg, formatted_msg)
32
- end
19
+ msg = "Required Environment object (enviro:). Given: #{enviro.class}"
20
+ raise ArgumentError, msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
33
21
 
34
- logger.level = file_level
35
- end
36
- end
22
+ @enviro = enviro
23
+ @cache = Eco::API::Common::Session::Logger::Cache.new
37
24
 
38
- if_config(:timestamp_console) { |value| self.timestamp = value }
39
- if_config(:console_level) { |value| self.level = value }
40
- if_config(:file_level) { |value| self.file_level = value }
25
+ if (log_file = fetch_log_file(log_file))
26
+ loggers[:file] = ::Logger.new(log_file).tap do |logger|
27
+ logger.formatter = format_proc(
28
+ console: false
29
+ ) do |severity, datetime, msg, formatted_msg|
30
+ cache.add(severity, datetime, msg, formatted_msg)
41
31
  end
42
32
 
43
- def file_level=(value)
44
- loggers[:file]&.level = value
45
- end
33
+ logger.level = file_level
34
+ end
35
+ end
46
36
 
47
- private
37
+ if_config(:timestamp_console) { |value| self.timestamp = value }
38
+ if_config(:console_level) { |value| self.level = value }
39
+ if_config(:file_level) { |value| self.file_level = value }
40
+ end
48
41
 
49
- def config(attr)
50
- return unless (cnf = @enviro&.config&.logger)
42
+ def file_level=(value)
43
+ loggers[:file]&.level = value
44
+ end
51
45
 
52
- cnf.send(attr) if cnf.respond_to?(attr)
53
- end
46
+ private
54
47
 
55
- def if_config(attr)
56
- return if (value = config(attr)).nil?
48
+ def config(attr)
49
+ return unless (cnf = @enviro&.config&.logger)
57
50
 
58
- yield(value) if block_given?
59
- value
60
- end
51
+ cnf.send(attr) if cnf.respond_to?(attr)
52
+ end
61
53
 
62
- def fetch_log_file(log_file)
63
- if log_file ||= config(:file)
64
- log_file = @enviro.file_manager.dir.file(log_file) if @enviro
65
- FileManager.create_directory(log_file, includes_file: true)
66
- end
54
+ def if_config(attr)
55
+ return if (value = config(attr)).nil?
67
56
 
68
- log_file
69
- end
70
- end
57
+ yield(value) if block_given?
58
+ value
59
+ end
60
+
61
+ def fetch_log_file(log_file)
62
+ if log_file ||= config(:file)
63
+ log_file = @enviro.file_manager.dir.file(log_file) if @enviro
64
+ FileUtils.mkdir_p(File.dirname(log_file))
71
65
  end
66
+
67
+ log_file
72
68
  end
73
69
  end
74
70
  end
@@ -1,84 +1,76 @@
1
1
  # rubocop:disable Naming/MethodParameterName
2
- module Eco
3
- module API
4
- module Common
5
- module Session
6
- class Mailer
7
- class AwsProvider < ProviderBase
8
- def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil)
9
- ses.send_email(
10
- destination: fetch_destination(to: to, cc: cc, bcc: bcc),
11
- source: fetch_from,
12
- message: {
13
- subject: {
14
- charset: 'UTF-8',
15
- data: subject
16
- },
17
- body: {
18
- # NOTE: (html) will let you send html instead
19
- # you can use both at once if you like
20
- text: {
21
- charset: 'UTF-8',
22
- data: body
23
- }
24
- }
25
- }
26
- )
27
- end
2
+ class Eco::API::Common::Session::Mailer
3
+ class AwsProvider < ProviderBase
4
+ def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil)
5
+ ses.send_email(
6
+ destination: fetch_destination(to: to, cc: cc, bcc: bcc),
7
+ source: fetch_from,
8
+ message: {
9
+ subject: {
10
+ charset: 'UTF-8',
11
+ data: subject
12
+ },
13
+ body: {
14
+ # NOTE: (html) will let you send html instead
15
+ # you can use both at once if you like
16
+ text: {
17
+ charset: 'UTF-8',
18
+ data: body
19
+ }
20
+ }
21
+ }
22
+ )
23
+ end
28
24
 
29
- # @return [Boolean] whether or not the mailer is configured for usage.
30
- def configured?
31
- fetch_access_key_id && fetch_secret_access_key && fetch_region
32
- end
25
+ # @return [Boolean] whether or not the mailer is configured for usage.
26
+ def configured?
27
+ fetch_access_key_id && fetch_secret_access_key && fetch_region
28
+ end
33
29
 
34
- private
30
+ private
35
31
 
36
- def credentials
37
- @credentials ||= {
38
- id: 'AWS_ACCESS_KEY_ID',
39
- key: 'AWS_SECRET_ACCESS_KEY'
40
- }
41
- end
32
+ def credentials
33
+ @credentials ||= super.merge({
34
+ id: 'AWS_ACCESS_KEY_ID',
35
+ key: 'AWS_SECRET_ACCESS_KEY'
36
+ })
37
+ end
42
38
 
43
- def ses
44
- require 'aws-sdk-ses'
45
- @ses ||= Aws::SES::Client.new(
46
- access_key_id: fetch_access_key_id,
47
- secret_access_key: fetch_secret_access_key,
48
- region: fetch_region
49
- )
50
- rescue StandardError => err
51
- log(:error) {
52
- "Trying to send an email with wrong email configuration: #{err}"
53
- }
54
- end
39
+ def ses
40
+ require 'aws-sdk-ses'
41
+ @ses ||= Aws::SES::Client.new(
42
+ access_key_id: fetch_access_key_id,
43
+ secret_access_key: fetch_secret_access_key,
44
+ region: fetch_region
45
+ )
46
+ rescue StandardError => err
47
+ log(:error) {
48
+ "Trying to send an email with wrong email configuration: #{err}"
49
+ }
50
+ end
55
51
 
56
- def fetch_destination(to: nil, cc: nil, bcc: nil)
57
- {
58
- to_addresses: [fetch_to(to)].flatten.compact.uniq
59
- }.tap do |dest|
60
- cc = [cc].flatten.compact.uniq
61
- bcc = [bcc].flatten.compact.uniq
52
+ def fetch_destination(to: nil, cc: nil, bcc: nil)
53
+ {
54
+ to_addresses: [fetch_to(to)].flatten.compact.uniq
55
+ }.tap do |dest|
56
+ cc = [cc].flatten.compact.uniq
57
+ bcc = [bcc].flatten.compact.uniq
62
58
 
63
- dest.merge!(cc_addresses: cc) unless cc.empty?
64
- dest.merge!(bcc_addresses: bcc) unless bcc.empty?
65
- end
66
- end
59
+ dest.merge!(cc_addresses: cc) unless cc.empty?
60
+ dest.merge!(bcc_addresses: bcc) unless bcc.empty?
61
+ end
62
+ end
67
63
 
68
- def fetch_region
69
- config.mailer.region || ENV['AWS_REGION']
70
- end
64
+ def fetch_region
65
+ config.mailer.region || ENV['AWS_REGION']
66
+ end
71
67
 
72
- def fetch_server
73
- config.mailer.server
74
- end
68
+ def fetch_server
69
+ config.mailer.server
70
+ end
75
71
 
76
- def fetch_message_id_domain
77
- config.mailer.message_id_domain
78
- end
79
- end
80
- end
81
- end
72
+ def fetch_message_id_domain
73
+ config.mailer.message_id_domain
82
74
  end
83
75
  end
84
76
  end
@@ -1,63 +1,58 @@
1
1
  # rubocop:disable Naming/MethodParameterName
2
- module Eco
3
- module API
4
- module Common
5
- module Session
6
- class Mailer
7
- class ProviderBase
8
- class << self
9
- def to_desc(to: nil, cc: nil, bcc: nil)
10
- cc_to = [cc].flatten.compact.uniq
11
- bcc_to = [bcc].flatten.compact.uniq
12
-
13
- { to_addresses: [to].flatten.compact.uniq }.tap do |dest|
14
- dest.merge!(cc_addresses: cc_to) unless cc_to.empty?
15
- dest.merge!(bcc_addresses: bcc_to) unless bcc_to.empty?
16
- end
17
- end
18
- end
2
+ class Eco::API::Common::Session::Mailer
3
+ class ProviderBase
4
+ class << self
5
+ def to_desc(to: nil, cc: nil, bcc: nil)
6
+ cc_to = [cc].flatten.compact.uniq
7
+ bcc_to = [bcc].flatten.compact.uniq
8
+
9
+ { to_addresses: [to].flatten.compact.uniq }.tap do |dest|
10
+ dest.merge!(cc_addresses: cc_to) unless cc_to.empty?
11
+ dest.merge!(bcc_addresses: bcc_to) unless bcc_to.empty?
12
+ end
13
+ end
14
+ end
19
15
 
20
- include Eco::Language::AuxiliarLogger
16
+ include Eco::Language::AuxiliarLogger
21
17
 
22
- attr_reader :config
18
+ attr_reader :config
23
19
 
24
- def initialize(config, logger:)
25
- @config = config
26
- @logger = logger
27
- end
20
+ def initialize(config, logger:)
21
+ @config = config
22
+ @logger = logger
23
+ end
28
24
 
29
- def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil) # rubocop:disable Lint/UnusedMethodArgument
30
- raise 'You must implement this method'
31
- end
25
+ def send_mail(subject:, body:, to: nil, cc: nil, bcc: nil) # rubocop:disable Lint/UnusedMethodArgument
26
+ raise 'You must implement this method'
27
+ end
32
28
 
33
- def fetch_to(value = nil)
34
- value || config.mailer.to
35
- end
29
+ def fetch_to(value = nil)
30
+ value || config.mailer.to || env_credential(:to)
31
+ end
36
32
 
37
- private
33
+ private
38
34
 
39
- def credentials
40
- raise 'You must implement this method'
41
- end
35
+ def credentials
36
+ {
37
+ to: 'MAILER_TO',
38
+ from: 'MAILER_FROM'
39
+ }
40
+ end
42
41
 
43
- def fetch_from(value = nil)
44
- value || config.mailer.from
45
- end
42
+ def fetch_from(value = nil)
43
+ value || config.mailer.from || env_credential(:from)
44
+ end
46
45
 
47
- def fetch_access_key_id
48
- env_mail(:id) || config.mailer.access_key_id
49
- end
46
+ def fetch_access_key_id
47
+ env_credential(:id) || config.mailer.access_key_id
48
+ end
50
49
 
51
- def fetch_secret_access_key
52
- env_mail(:key) || config.mailer.secret_access_key
53
- end
50
+ def fetch_secret_access_key
51
+ env_credential(:key) || config.mailer.secret_access_key
52
+ end
54
53
 
55
- def env_mail(prop)
56
- ENV[credentials[prop]]
57
- end
58
- end
59
- end
60
- end
54
+ def env_credential(prop)
55
+ ENV[credentials[prop]]
61
56
  end
62
57
  end
63
58
  end