effective_resources 1.13.0 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/mailers/concerns/effective_mailer.rb +52 -0
- data/app/models/effective/resources/controller.rb +0 -2
- data/config/effective_resources.rb +5 -2
- data/lib/effective_resources/effective_gem.rb +16 -1
- data/lib/effective_resources/version.rb +1 -1
- data/lib/effective_resources.rb +11 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37818a2db37ab767ea5c415519b0674ba87cc5a998978730a7851df8fddeae1d
|
4
|
+
data.tar.gz: 89f53d6a3238db076a5c9b212ce306109954c1cea374f763b755b7b8ee565e5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceb3fdb52931639ebb8ba24454dd103daa45dccc674d2d1dadb1a31d1e89da7f28f9a107a5db6e8dc38e2c688970366b3d36c9e189c78d7b5cca45555468e577
|
7
|
+
data.tar.gz: 1cea14061c7f0cc2bda9f56efd57f9be8b6018af50cdc72e8759d4ae80a120e5fcfceefea4da0908f95d3fc4161c4bf87d5472c69c93099ebd10137a5d5cb7b7
|
@@ -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
|
@@ -47,7 +47,6 @@ module Effective
|
|
47
47
|
action_name = action.to_s.titleize
|
48
48
|
|
49
49
|
if action == :destroy
|
50
|
-
next if buttons.values.find { |v| v[:action] == :archive }.present?
|
51
50
|
buttons['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
52
51
|
else
|
53
52
|
buttons[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" }
|
@@ -101,7 +100,6 @@ module Effective
|
|
101
100
|
action_name = action.to_s.titleize
|
102
101
|
|
103
102
|
if action == :destroy
|
104
|
-
next if actions.find { |_, v| v[:action] == :archive }.present?
|
105
103
|
actions['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
106
104
|
else
|
107
105
|
actions[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" }
|
@@ -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 = "
|
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
|
-
|
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
|
@@ -61,6 +72,10 @@ module EffectiveGem
|
|
61
72
|
config[:mailer_admin].presence || EffectiveResources.mailer_admin
|
62
73
|
end
|
63
74
|
|
75
|
+
def mailer_subject
|
76
|
+
config[:mailer_subject].presence || EffectiveResources.mailer_subject
|
77
|
+
end
|
78
|
+
|
64
79
|
def send_email(email, *args)
|
65
80
|
raise('gem does not respond to mailer_class') unless respond_to?(:mailer_class)
|
66
81
|
raise('expected args to be an Array') unless args.kind_of?(Array)
|
data/lib/effective_resources.rb
CHANGED
@@ -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, :
|
11
|
+
:parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject
|
11
12
|
]
|
12
13
|
end
|
13
14
|
|
@@ -44,10 +45,19 @@ module EffectiveResources
|
|
44
45
|
(rails.respond_to?(:active_job) && rails.active_job.queue_adapter) ? :deliver_later : :deliver_now
|
45
46
|
end
|
46
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
|
+
|
47
53
|
def self.mailer_layout
|
48
54
|
config[:mailer_layout] || 'effective_mailer_layout'
|
49
55
|
end
|
50
56
|
|
57
|
+
def self.mailer_subject
|
58
|
+
config[:mailer_subject] || MAILER_SUBJECT_PROC
|
59
|
+
end
|
60
|
+
|
51
61
|
def self.mailer_sender
|
52
62
|
config[:mailer_sender] || raise('effective resources mailer_sender missing. Add it to config/initializers/effective_resources.rb')
|
53
63
|
end
|
@@ -56,11 +66,6 @@ module EffectiveResources
|
|
56
66
|
config[:mailer_admin] || raise('effective resources mailer_admin missing. Add it to config/initializers/effective_resources.rb')
|
57
67
|
end
|
58
68
|
|
59
|
-
def self.parent_mailer_class
|
60
|
-
return config[:parent_mailer].constantize if config[:parent_mailer].present?
|
61
|
-
'::ApplicationMailer'.safe_constantize || 'ActionMailer::Base'.constantize
|
62
|
-
end
|
63
|
-
|
64
69
|
# Utilities
|
65
70
|
|
66
71
|
# This looks up the best class give the name
|
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.
|
4
|
+
version: 1.15.1
|
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-03-
|
11
|
+
date: 2022-03-08 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
|