bima-shark-sdk 2.4.2 → 2.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a940bf61424a49baa7f04791ca42ba61bb145a97
4
- data.tar.gz: 734da4e58e55397a983e31ac9e53aa372e664a7b
3
+ metadata.gz: 36a6d2d392e0c48fdde77f944eb0e758439fd5e4
4
+ data.tar.gz: bc0e578ff45dbf92cf2ec2f4594d2957129c3b4e
5
5
  SHA512:
6
- metadata.gz: 7c1ade4eaefb81ae08c8e799d29bd6caf4b4ff1f355df7f4382c9bd0cddb3dcc0b3b0022fb4c68ffeb6d3278a95cca50a04b3076002ff1d1e5a5e9688881b36a
7
- data.tar.gz: 12186155c320e2254eed1d4e4dcfe47ac31b2f540e5d5470d15472c3b333d9915fc75347795762be86438c7d556e004d85d2f02235bd89d5913e32f62709d763
6
+ metadata.gz: 41efb8f03436ad58fe4cec3d189440748260f2dfb1354ef1a4510f520a9573c302450297da88d7f8861b5221e0891726415c83b8892b18094e72007323c328fc
7
+ data.tar.gz: fbe011415cd0ae7f7511bf4a2e46ab8e9787ef68b4f224a90c40af4fe0d8503fe6eace1e8d0c68497df1ce12b3865dfd2727e8687804474a33753432f047920e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Changelog
2
2
 
3
+ #### 2.4.3
4
+ - allow `Shark::MailingService::Mailer#mail` to use separate layouts
5
+ - rename `Shark::MailingService::Mailers::BaseMailer` to `Shark::MailingService::Mailer`
6
+
3
7
  #### 2.4.2
4
8
  - [fix] don't swallow connection errors
5
9
 
@@ -7,8 +7,8 @@ require 'shark/version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'bima-shark-sdk'
9
9
  spec.version = Shark::VERSION
10
- spec.authors = ['Huy Dinh', 'Johannes Schmeißer', 'Joergen Dahlke']
11
- spec.email = ['bima-team@infopark.de']
10
+ spec.authors = ['bima-team@justrelate.com']
11
+ spec.email = ['bima-team@justrelate.com']
12
12
 
13
13
  spec.summary = ''
14
14
  spec.description = ''
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shark
4
+ module MailingService
5
+ class Mailer
6
+ class << self
7
+ attr_writer :layout, :template_root
8
+
9
+ def layout
10
+ @layout || MailingService.config.default_layout
11
+ end
12
+
13
+ def method_missing(method, *args, &block)
14
+ return super unless respond_to?(method)
15
+
16
+ instance = new(
17
+ layout: layout,
18
+ template_name: method.to_s,
19
+ template_path: File.join(template_root.to_s, name.underscore)
20
+ )
21
+ instance.send(method, *args)
22
+ instance
23
+ end
24
+
25
+ def template_root
26
+ @template_root || MailingService.config.default_template_root
27
+ end
28
+
29
+ protected
30
+
31
+ def respond_to_missing?(method, include_private = false)
32
+ known_methods = if include_private
33
+ instance_methods(false)
34
+ else
35
+ public_instance_methods(false)
36
+ end
37
+ known_methods.include?(method)
38
+ end
39
+ end
40
+
41
+ attr_reader :layout, :template_name, :template_path
42
+
43
+ def initialize(layout:, template_path:, template_name:)
44
+ @layout = layout
45
+ @template_name = template_name
46
+ @template_path = template_path
47
+ end
48
+
49
+ def deliver
50
+ @mail.save
51
+ end
52
+ alias deliver_now deliver
53
+
54
+ protected
55
+
56
+ def body(format, locals = {})
57
+ renderer.render(template_name, format, locals)
58
+ end
59
+
60
+ def attribute_with_default(attributes, attribute)
61
+ return attributes[attribute] if attributes.key?(attribute)
62
+
63
+ I18n.t!("#{self.class.name.underscore}.#{template_name}.#{attribute}")
64
+ rescue StandardError
65
+ nil
66
+ end
67
+
68
+ def mail(attributes)
69
+ locals = attributes[:locals] || {}
70
+ mail_attributes = {
71
+ layout: attributes[:layout] || layout,
72
+ reply_to: attributes[:reply_to],
73
+ recipient: attributes[:to],
74
+ subject: attribute_with_default(attributes, :subject),
75
+ header: attribute_with_default(attributes, :header),
76
+ sub_header: attribute_with_default(attributes, :sub_header),
77
+ html_body: body(:html, locals),
78
+ text_body: body(:text, locals),
79
+ attachments: attributes[:attachments] || {}
80
+ }
81
+ %i[from header_image reply_to unsubscribe_url].each do |key|
82
+ value = attributes[key]
83
+ mail_attributes[key] = value if value.present?
84
+ end
85
+
86
+ @mail = Shark::MailingService::Mail.new(mail_attributes)
87
+ end
88
+
89
+ def renderer
90
+ @renderer ||= Renderers::ErbRenderer.new(template_path)
91
+ end
92
+ end
93
+
94
+ module Mailers
95
+ BaseMailer = MailingService::Mailer
96
+ end
97
+ end
98
+ end
99
+
100
+
@@ -10,7 +10,7 @@ module Shark
10
10
  require 'shark/mailing_service/configuration'
11
11
  require 'shark/mailing_service/renderers/context'
12
12
  require 'shark/mailing_service/renderers/erb_renderer'
13
- require 'shark/mailing_service/mailers/base_mailer'
13
+ require 'shark/mailing_service/mailer'
14
14
 
15
15
  yield(config)
16
16
  end
data/lib/shark/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shark
4
- VERSION = '2.4.2'
4
+ VERSION = '2.4.3'
5
5
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bima-shark-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
- - Huy Dinh
8
- - Johannes Schmeißer
9
- - Joergen Dahlke
7
+ - bima-team@justrelate.com
10
8
  autorequire:
11
9
  bindir: exe
12
10
  cert_chain: []
13
- date: 2022-10-12 00:00:00.000000000 Z
11
+ date: 2023-01-13 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: activesupport
@@ -168,7 +166,7 @@ dependencies:
168
166
  version: '2.3'
169
167
  description: ''
170
168
  email:
171
- - bima-team@infopark.de
169
+ - bima-team@justrelate.com
172
170
  executables: []
173
171
  extensions: []
174
172
  extra_rdoc_files: []
@@ -222,7 +220,7 @@ files:
222
220
  - lib/shark/mailing_service/base.rb
223
221
  - lib/shark/mailing_service/configuration.rb
224
222
  - lib/shark/mailing_service/mail.rb
225
- - lib/shark/mailing_service/mailers/base_mailer.rb
223
+ - lib/shark/mailing_service/mailer.rb
226
224
  - lib/shark/mailing_service/renderers/context.rb
227
225
  - lib/shark/mailing_service/renderers/erb_renderer.rb
228
226
  - lib/shark/membership.rb
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shark
4
- module MailingService
5
- module Mailers
6
- class BaseMailer
7
- class << self
8
- attr_writer :layout, :template_root
9
-
10
- def layout
11
- @layout || MailingService.config.default_layout
12
- end
13
-
14
- def method_missing(method, *args, &block)
15
- return super unless respond_to?(method)
16
-
17
- instance = new(
18
- layout: layout,
19
- template_name: method.to_s,
20
- template_path: File.join(template_root.to_s, name.underscore)
21
- )
22
- instance.send(method, *args)
23
- instance
24
- end
25
-
26
- def template_root
27
- @template_root || MailingService.config.default_template_root
28
- end
29
-
30
- protected
31
-
32
- def respond_to_missing?(method, include_private = false)
33
- known_methods = if include_private
34
- instance_methods(false)
35
- else
36
- public_instance_methods(false)
37
- end
38
- known_methods.include?(method)
39
- end
40
- end
41
-
42
- attr_reader :layout, :template_name, :template_path
43
-
44
- def initialize(layout:, template_path:, template_name:)
45
- @layout = layout
46
- @template_name = template_name
47
- @template_path = template_path
48
- end
49
-
50
- def deliver
51
- @mail.save
52
- end
53
- alias deliver_now deliver
54
-
55
- protected
56
-
57
- def body(format, locals = {})
58
- renderer.render(template_name, format, locals)
59
- end
60
-
61
- def attribute_with_default(attributes, attribute)
62
- return attributes[attribute] if attributes.key?(attribute)
63
-
64
- I18n.t!("#{self.class.name.underscore}.#{template_name}.#{attribute}")
65
- rescue StandardError
66
- nil
67
- end
68
-
69
- def mail(attributes)
70
- locals = attributes[:locals] || {}
71
- mail_attributes = {
72
- layout: layout,
73
- reply_to: attributes[:reply_to],
74
- recipient: attributes[:to],
75
- subject: attribute_with_default(attributes, :subject),
76
- header: attribute_with_default(attributes, :header),
77
- sub_header: attribute_with_default(attributes, :sub_header),
78
- html_body: body(:html, locals),
79
- text_body: body(:text, locals),
80
- attachments: attributes[:attachments] || {}
81
- }
82
- %i[from header_image reply_to unsubscribe_url].each do |key|
83
- value = attributes[key]
84
- mail_attributes[key] = value if value.present?
85
- end
86
-
87
- @mail = Shark::MailingService::Mail.new(mail_attributes)
88
- end
89
-
90
- def renderer
91
- @renderer ||= Renderers::ErbRenderer.new(template_path)
92
- end
93
- end
94
- end
95
- end
96
- end