effective_resources 1.12.3 → 1.14.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: 47e241da2411f181fa4a176db6791e1416b861f38061c9186fdf595df78767e2
4
- data.tar.gz: 76dc05f7974a967a14c608161e9c57e90eb66a962f32ca923b4913bd1f4f15bb
3
+ metadata.gz: f21136f9833dbd9036cad7cb495972fef7601e9a53aa0a531f316fc270d898bb
4
+ data.tar.gz: 043bcdba74212c6c195539bd4a6991acf44be982660885a2d33f8908ebef572b
5
5
  SHA512:
6
- metadata.gz: 6dc99f690d6f2aa26bfa240df5d9b5887ff4811ecf834178269934c5ef35cdd195180cc137302a2d31dee371ca5d012077f8d0113d146410d76fc9f6b06d2723
7
- data.tar.gz: aebfd8aff7b492dbf304ae5be5b3c63d6432754b2272c4c77a0aff64e1685add92fa70dadc385589c56e0b55dfc430156a18a9945bdb22fa73488ec970bbba10
6
+ metadata.gz: afbfc06d0319bfd759a924dea4bc8e8b47c0d772d88f2bddb6925bf926032b97553d9049ac97f398e7a48515c0154d2db4268eb8c7b55e43c87f99dd146c9cad
7
+ data.tar.gz: e71929d4829aa0624ff5314a8e87cb9f4369c0ce20b7e1be55f5da57af243a5c3e4d0fc3de91356883c49ce9064260d2ede78d238b8a9e209628369f2f1eeb77
@@ -24,10 +24,13 @@ module Effective
24
24
  def update
25
25
  Rails.logger.info 'Processed by Effective::WizardController#update'
26
26
 
27
+ action = (commit_action[:action] == :save ? :update : commit_action[:action])
28
+ EffectiveResources.authorize!(self, action, resource)
29
+
27
30
  resource.assign_attributes(send(resource_params_method_name))
28
31
  assign_current_step
29
32
 
30
- save_wizard_resource(resource)
33
+ save_wizard_resource(resource, action)
31
34
  end
32
35
 
33
36
  end
@@ -4,12 +4,17 @@ module Effective
4
4
 
5
5
  def save_wizard_resource(resource, action = nil, options = {})
6
6
  was_new_record = resource.new_record?
7
- action ||= resource.respond_to?("#{step}!") ? step : :save
7
+
8
+ if action.blank? || action == :update
9
+ action = resource.respond_to?("#{step}!") ? step : :save
10
+ end
8
11
 
9
12
  if save_resource(resource, action)
10
13
  flash[:success] ||= options.delete(:success) || resource_flash(:success, resource, action)
11
14
 
12
15
  @skip_to ||= skip_to_step(resource)
16
+
17
+ @redirect_to ||= resource_redirect_path(resource, action) if specific_redirect_path?(action)
13
18
  @redirect_to ||= resource_wizard_path(resource, @skip_to) if was_new_record
14
19
 
15
20
  if @redirect_to
@@ -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
  #
@@ -44,8 +44,8 @@ EffectiveResources.setup do |config|
44
44
  # config.mailer_layout = 'effective_mailer_layout'
45
45
 
46
46
  # Default From
47
- config.mailer_sender = "no-reply@example.com"
47
+ config.mailer_sender = '"Info" <info@example.com>'
48
48
 
49
49
  # Send Admin correspondence To
50
- config.mailer_admin = "admin@example.com"
50
+ config.mailer_admin = '"Admin" <admin@example.com>'
51
51
  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
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,33 @@ 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
+
44
75
  def send_email(email, *args)
45
76
  raise('gem does not respond to mailer_class') unless respond_to?(:mailer_class)
46
77
  raise('expected args to be an Array') unless args.kind_of?(Array)
47
78
 
48
- mailer_class.send(email, *args).send(EffectiveResources.deliver_method)
79
+ mailer_class.send(email, *args).send(deliver_method)
49
80
  end
50
81
 
51
82
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.12.3'.freeze
2
+ VERSION = '1.14.0'.freeze
3
3
  end
@@ -34,7 +34,9 @@ module EffectiveResources
34
34
  (['Save', 'Continue', 'Add New'] & Array(config.default_submits)).inject({}) { |h, v| h[v] = true; h }
35
35
  end
36
36
 
37
- # Email
37
+ # Mailer Settings
38
+ # These serve as the default mailer settings for all effective_* gems
39
+ # They can be overriden on a per-gem basis.
38
40
  def self.deliver_method
39
41
  return config[:deliver_method] if config[:deliver_method].present?
40
42
 
@@ -109,7 +111,6 @@ module EffectiveResources
109
111
  end
110
112
  end
111
113
 
112
-
113
114
  def self.advance_date(date, business_days: 1, holidays: [:ca, :observed])
114
115
  raise('business_days must be an integer <= 365') unless business_days.kind_of?(Integer) && business_days <= 365
115
116
 
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.3
4
+ version: 1.14.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-04 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails