effective_resources 1.12.4 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78a62dc6fc911b14bbf9972a75a5a4efcb8c1be89f049c67698a8eef4d3c4c65
4
- data.tar.gz: 236d6cd2e737b360d0678ca861804f7a07f841b88bf6180befef3f55e2a5194d
3
+ metadata.gz: 4196a26392312c2343b4ae31d4580a7c8b84a8f37d8e74c77e17d34016314b9c
4
+ data.tar.gz: 93d48690d2be56b1f5068bf815055de47446599b82aaf4444e52583208f368b3
5
5
  SHA512:
6
- metadata.gz: 0f3030caa00296cc2aa2af8c33eeaf77ad6a7b3a08bd601a563c422e605f75f0d8ce8070f5c389c2267aca25d62fba94f391404ca8d6b2de9ce8182f0ce005cb
7
- data.tar.gz: 0ceda0d79b3f8a0c9783c997c3ca40b05e00e046f4f22917560bf983b021a4b963fe7d8fc37ffcd8e996e671bdc67a9b31d0390a2fa6b074f221a7c3a17d500d
6
+ metadata.gz: b25bc7b63e988fe7198cdd2e5b44d79cbee612fb18839b088feb7e3c53c6b00a8c27ac76f0de796278f147e93b27d64f374cae0c00e1419350146243cfc4f9ae
7
+ data.tar.gz: 159c99e620737423d67963b28feefa1bda55dfd645a25835892bded90a4d616dd52e659913f3f97f246c6274a5ad5cae615c33d43c795c576a8fe6465235487a
@@ -0,0 +1,52 @@
1
+ # Includes some shared mailer methods for effective_* gem mailers
2
+
3
+ module EffectiveMailer
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ default from: -> { mailer_settings.mailer_sender }
8
+ layout -> { mailer_settings.mailer_layout }
9
+ end
10
+
11
+ protected
12
+
13
+ def mailer_admin
14
+ mailer_settings.mailer_admin
15
+ end
16
+
17
+ def subject_for(action, subject, resource, opts = {})
18
+ mailer_subject = mailer_settings.mailer_subject
19
+
20
+ if mailer_subject.respond_to?(:call)
21
+ subject = self.instance_exec(action, subject, resource, opts, &mailer_subject)
22
+ end
23
+
24
+ subject
25
+ end
26
+
27
+ def headers_for(resource, opts = {})
28
+ (resource.respond_to?(:log_changes_datatable) ? opts.merge(log: resource) : opts)
29
+ end
30
+
31
+ private
32
+
33
+ # This returns the top level gem, EffectiveOrders or EffectiveResources
34
+ def mailer_settings
35
+ name = self.class.name.sub('::', '').sub('Mailer', '')
36
+
37
+ # If this is in a gem mailer like Effective::OrdersMailer we use constantize
38
+ # Otherwise this could be included in an ApplicationMailer, so we defer to EffectiveResources
39
+ klass = if name.start_with?('Effective')
40
+ name.constantize
41
+ else
42
+ name.safe_constantize || EffectiveResources
43
+ end
44
+
45
+ raise('expected mailer settings to respond to mailer_subject') unless klass.respond_to?(:mailer_subject)
46
+ raise('expected mailer settings to respond to mailer_sender') unless klass.respond_to?(:mailer_sender)
47
+ raise('expected mailer settings to respond to mailer_layout') unless klass.respond_to?(:mailer_layout)
48
+
49
+ klass
50
+ end
51
+
52
+ end
@@ -30,7 +30,7 @@ EffectiveResources.setup do |config|
30
30
  # Supported values: 'Save', 'Continue', and 'Add New'
31
31
  config.default_submits = ['Save', 'Continue', 'Add New']
32
32
 
33
- # Email Settings
33
+ # Mailer Settings
34
34
  #
35
35
  # The default mailer settings for all effective gems
36
36
  #
@@ -43,9 +43,12 @@ EffectiveResources.setup do |config|
43
43
  # Default layout
44
44
  # config.mailer_layout = 'effective_mailer_layout'
45
45
 
46
+ # Customize the Subject
47
+ # config.mailer_subject = Proc.new { |action, subject, resource, opts = {}| subject }
48
+
46
49
  # Default From
47
- config.mailer_sender = "no-reply@example.com"
50
+ config.mailer_sender = '"Info" <info@example.com>'
48
51
 
49
52
  # Send Admin correspondence To
50
- config.mailer_admin = "admin@example.com"
53
+ config.mailer_admin = '"Admin" <admin@example.com>'
51
54
  end
@@ -3,13 +3,24 @@
3
3
  module EffectiveGem
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ EXCLUDED_GETTERS = [
7
+ :config, :setup, :send_email, :parent_mailer_class,
8
+ :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject
9
+ ]
10
+
6
11
  included do
7
12
  raise("expected self.config_keys method") unless respond_to?(:config_keys)
8
13
 
9
- config_keys.each do |key|
14
+ # Define getters
15
+ (config_keys - EXCLUDED_GETTERS).each do |key|
10
16
  self.singleton_class.define_method(key) { config()[key] }
17
+ end
18
+
19
+ # Define setters
20
+ config_keys.each do |key|
11
21
  self.singleton_class.define_method("#{key}=") { |value| config()[key] = value }
12
22
  end
23
+
13
24
  end
14
25
 
15
26
  module ClassMethods
@@ -39,13 +50,37 @@ module EffectiveGem
39
50
  true
40
51
  end
41
52
 
42
- # This is included into every gem
43
- # The gem may not have a mailer or use effective email templates
53
+ # Mailer Settings
54
+ # These methods are intended to flow through to the default EffectiveResources settings
55
+ def parent_mailer_class
56
+ config[:parent_mailer].presence&.constantize || EffectiveResources.parent_mailer_class
57
+ end
58
+
59
+ def deliver_method
60
+ config[:deliver_method].presence || EffectiveResources.deliver_method
61
+ end
62
+
63
+ def mailer_layout
64
+ config[:mailer_layout].presence || EffectiveResources.mailer_layout
65
+ end
66
+
67
+ def mailer_sender
68
+ config[:mailer_sender].presence || EffectiveResources.mailer_sender
69
+ end
70
+
71
+ def mailer_admin
72
+ config[:mailer_admin].presence || EffectiveResources.mailer_admin
73
+ end
74
+
75
+ def mailer_subject
76
+ config[:mailer_subject].presence || EffectiveResources.mailer_subject
77
+ end
78
+
44
79
  def send_email(email, *args)
45
80
  raise('gem does not respond to mailer_class') unless respond_to?(:mailer_class)
46
81
  raise('expected args to be an Array') unless args.kind_of?(Array)
47
82
 
48
- mailer_class.send(email, *args).send(EffectiveResources.deliver_method)
83
+ mailer_class.send(email, *args).send(deliver_method)
49
84
  end
50
85
 
51
86
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.12.4'.freeze
2
+ VERSION = '1.15.0'.freeze
3
3
  end
@@ -3,11 +3,12 @@ require 'effective_resources/version'
3
3
  require 'effective_resources/effective_gem'
4
4
 
5
5
  module EffectiveResources
6
+ MAILER_SUBJECT_PROC = Proc.new { |action, subject, resource, opts = {}| subject }
6
7
 
7
8
  def self.config_keys
8
9
  [
9
10
  :authorization_method, :default_submits,
10
- :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :parent_mailer
11
+ :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject
11
12
  ]
12
13
  end
13
14
 
@@ -34,7 +35,9 @@ module EffectiveResources
34
35
  (['Save', 'Continue', 'Add New'] & Array(config.default_submits)).inject({}) { |h, v| h[v] = true; h }
35
36
  end
36
37
 
37
- # Email
38
+ # Mailer Settings
39
+ # These serve as the default mailer settings for all effective_* gems
40
+ # They can be overriden on a per-gem basis.
38
41
  def self.deliver_method
39
42
  return config[:deliver_method] if config[:deliver_method].present?
40
43
 
@@ -42,10 +45,19 @@ module EffectiveResources
42
45
  (rails.respond_to?(:active_job) && rails.active_job.queue_adapter) ? :deliver_later : :deliver_now
43
46
  end
44
47
 
48
+ def self.parent_mailer_class
49
+ return config[:parent_mailer].constantize if config[:parent_mailer].present?
50
+ '::ApplicationMailer'.safe_constantize || 'ActionMailer::Base'.constantize
51
+ end
52
+
45
53
  def self.mailer_layout
46
54
  config[:mailer_layout] || 'effective_mailer_layout'
47
55
  end
48
56
 
57
+ def self.mailer_subject
58
+ config[:mailer_subject] || MAILER_SUBJECT_PROC
59
+ end
60
+
49
61
  def self.mailer_sender
50
62
  config[:mailer_sender] || raise('effective resources mailer_sender missing. Add it to config/initializers/effective_resources.rb')
51
63
  end
@@ -54,11 +66,6 @@ module EffectiveResources
54
66
  config[:mailer_admin] || raise('effective resources mailer_admin missing. Add it to config/initializers/effective_resources.rb')
55
67
  end
56
68
 
57
- def self.parent_mailer_class
58
- return config[:parent_mailer].constantize if config[:parent_mailer].present?
59
- '::ApplicationMailer'.safe_constantize || 'ActionMailer::Base'.constantize
60
- end
61
-
62
69
  # Utilities
63
70
 
64
71
  # This looks up the best class give the name
@@ -109,7 +116,6 @@ module EffectiveResources
109
116
  end
110
117
  end
111
118
 
112
-
113
119
  def self.advance_date(date, business_days: 1, holidays: [:ca, :observed])
114
120
  raise('business_days must be an integer <= 365') unless business_days.kind_of?(Integer) && business_days <= 365
115
121
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.4
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-28 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -152,6 +152,7 @@ files:
152
152
  - app/helpers/effective_resources_helper.rb
153
153
  - app/helpers/effective_resources_private_helper.rb
154
154
  - app/helpers/effective_resources_wizard_helper.rb
155
+ - app/mailers/concerns/effective_mailer.rb
155
156
  - app/models/concerns/acts_as_archived.rb
156
157
  - app/models/concerns/acts_as_email_form.rb
157
158
  - app/models/concerns/acts_as_purchasable_wizard.rb