effective_resources 1.14.0 → 1.16.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: f21136f9833dbd9036cad7cb495972fef7601e9a53aa0a531f316fc270d898bb
4
- data.tar.gz: 043bcdba74212c6c195539bd4a6991acf44be982660885a2d33f8908ebef572b
3
+ metadata.gz: 5e7d7a9ee482e38794221a01b428e01de652eb23b63c2b926eda018c47ae057c
4
+ data.tar.gz: 5a920c11ce61cf201a20b1a7b2fb946846d1f034ad4e9acb91253b6d0a8f6ce5
5
5
  SHA512:
6
- metadata.gz: afbfc06d0319bfd759a924dea4bc8e8b47c0d772d88f2bddb6925bf926032b97553d9049ac97f398e7a48515c0154d2db4268eb8c7b55e43c87f99dd146c9cad
7
- data.tar.gz: e71929d4829aa0624ff5314a8e87cb9f4369c0ce20b7e1be55f5da57af243a5c3e4d0fc3de91356883c49ce9064260d2ede78d238b8a9e209628369f2f1eeb77
6
+ metadata.gz: 99d01c855370aa34ad51bc3bde24a11d6b57080616312b4ed8e9c066601ec7fb5275117327780a94f9d85ad81e9a9486c49be29dfcb429f4654b3cac64ce67cc
7
+ data.tar.gz: 3fcd18e60abdb8f8da2208a92c6547718611ad70f0018c7a43af831173da3ee44cdc1c5a3a6f033c54d6fe97d67c749b8ccfb01f8b52e46893b132b6a6a5aada
@@ -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,6 +43,9 @@ 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
50
  config.mailer_sender = '"Info" <info@example.com>'
48
51
 
@@ -5,7 +5,7 @@ module EffectiveGem
5
5
 
6
6
  EXCLUDED_GETTERS = [
7
7
  :config, :setup, :send_email, :parent_mailer_class,
8
- :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin
8
+ :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject
9
9
  ]
10
10
 
11
11
  included do
@@ -72,6 +72,10 @@ module EffectiveGem
72
72
  config[:mailer_admin].presence || EffectiveResources.mailer_admin
73
73
  end
74
74
 
75
+ def mailer_subject
76
+ config[:mailer_subject].presence || EffectiveResources.mailer_subject
77
+ end
78
+
75
79
  def send_email(email, *args)
76
80
  raise('gem does not respond to mailer_class') unless respond_to?(:mailer_class)
77
81
  raise('expected args to be an Array') unless args.kind_of?(Array)
@@ -57,11 +57,9 @@ module EffectiveResources
57
57
  # Register the acts_as_archived routes concern
58
58
  # resources :things, concerns: :acts_as_archived
59
59
  initializer 'effective_resources.routes_concern' do |app|
60
- ActionDispatch::Routing::Mapper.include(ActsAsArchived::RoutesConcern)
61
-
62
- # Doesn't seem to work with the on_load in rails 6.0
63
- #ActiveSupport.on_load :action_controller_base do
64
- #end
60
+ app.config.to_prepare do
61
+ ActionDispatch::Routing::Mapper.include(ActsAsArchived::RoutesConcern)
62
+ end
65
63
  end
66
64
 
67
65
  # Register the flash_messages concern so that it can be called in ActionController
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.14.0'.freeze
2
+ VERSION = '1.16.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
 
@@ -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.14.0
4
+ version: 1.16.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-03-03 00:00:00.000000000 Z
11
+ date: 2022-03-12 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