effective_resources 2.8.8 → 2.9.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: a583a70685ae3faf4811c49e750ae55c05aec5af0ed3f061662c80723575a2c9
4
- data.tar.gz: acb81962352988b990db0d8b95ba4430d02bfad1bf04946d5724753bf10454ad
3
+ metadata.gz: 10642ec990cb0ad6b2426415a997aead2f5d53bcdb8a932b3f276af5e9485af9
4
+ data.tar.gz: a971535ad4974d3931be497db3595f91e1baac7483f718e3197778e84674e525
5
5
  SHA512:
6
- metadata.gz: 60bb0ff5c80356b24770eb98d9787a9a975368edf7fa3be6c5cd700c7937e3fce7a6ad1a5d8cf8670184c0b5feeaf0dd98577989948b5292a7f3f4fe09c3ed97
7
- data.tar.gz: 1aa740c85b5a07a900e9cc68f97f38dfe0c57b1ca1fbfecf43f34a2b9be2aba8571e84d989a99957c319d33b437da061e56744999d49213d4a9dddf3795f30f4
6
+ metadata.gz: c8ee4692a6b49d21cfe3d591233f9991355cb1d4d3697d5317fceb7186eb9011db71edef3dc8b6ddedc8ba97d3d28b7c7cf80bf753c18a31b344c8cbc7393db1
7
+ data.tar.gz: 7cfa99b30169c1bb0bc316dafdc29bad35996b678affea7f21e9ab6fe469bdf4dd6a3fe013d028b8e8fb4cd4281aa809640477db683e3cb0d987bc40d62375b5
@@ -42,19 +42,32 @@ module EffectiveResourcesWizardHelper
42
42
  end
43
43
  end
44
44
 
45
- def render_wizard_resource(resource, as: nil, path: nil)
45
+ def render_wizard_resource_step(resource, step, as: nil, path: nil)
46
+ render_wizard_resource(resource, only: step, as: as, path: path)
47
+ end
48
+
49
+ def render_wizard_resource(resource, only: [], except: [], as: nil, path: nil)
46
50
  effective_resource = Effective::Resource.new(resource)
47
51
 
52
+ # Render path
48
53
  as ||= effective_resource.name
49
- path ||= effective_resource.view_file_path(nil)
54
+ path ||= effective_resource.wizard_file_path(resource)
50
55
  raise('expected a path') unless path.present?
51
56
 
52
57
  resource.render_path = path.to_s.chomp('/')
53
58
 
54
- resource.render_steps.map do |partial|
55
- resource.render_step = partial
59
+ # Render steps
60
+ only = Array(only)
61
+ except = Array(except)
62
+
63
+ steps = resource.render_steps
64
+ steps = (steps - except) if except.present?
65
+ steps = (steps & only) if only.present?
66
+
67
+ steps.map do |step|
68
+ resource.render_step = step
56
69
 
57
- render_if_exists("#{path}/#{partial}", as.to_sym => resource) || render('effective/acts_as_wizard/wizard_step', resource: resource, resource_path: path)
70
+ render_if_exists("#{path}/#{step}", as.to_sym => resource) || render('effective/acts_as_wizard/wizard_step', resource: resource, resource_path: path)
58
71
  end.join.html_safe
59
72
  end
60
73
 
@@ -89,7 +89,9 @@ module ActsAsPurchasableWizard
89
89
  raise('already has purchased submit fees') if fees.any?(&:purchased?)
90
90
 
91
91
  order = find_or_build_submit_order()
92
+ raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
92
93
  raise('already has purchased submit order') if order.purchased?
94
+ raise('unable to proceed with a voided submit order') if order.try(:voided?)
93
95
 
94
96
  true
95
97
  end
@@ -39,7 +39,7 @@ module ActsAsStatused
39
39
  const_set(:STATUSES, acts_as_statused_options[:statuses])
40
40
 
41
41
  before_validation do
42
- self.status ||= self.class.const_get(:STATUSES).first
42
+ self.status ||= all_statuses.first
43
43
 
44
44
  # Set an existing belongs_to automatically
45
45
  if respond_to?("#{status}_by") && send("#{status}_by").blank?
@@ -132,25 +132,51 @@ module ActsAsStatused
132
132
  end
133
133
 
134
134
  # unapproved!
135
- define_method("un#{sym}!") do
136
- self.status = nil if (status == sym.to_s)
135
+ define_method("un#{sym}!") do |atts = {}|
136
+ raise 'expected a Hash of passed attributes' unless atts.kind_of?(Hash)
137
137
 
138
- if respond_to?("#{sym}_at") && send("#{sym}_at").present?
139
- self.send("#{sym}_at=", nil)
140
- end
141
-
142
- if respond_to?("#{sym}_by") && send("#{sym}_by").present?
143
- self.send("#{sym}_by=", nil)
144
- end
138
+ self.try("#{sym}_at=", nil)
139
+ self.try("#{sym}_by=", nil)
140
+ self.try("#{sym}_by_id=", nil)
141
+ self.try("#{sym}_by_type=", nil)
145
142
 
146
143
  status_steps.delete(sym_at)
147
144
  status_steps.delete(sym_by_id)
148
145
  status_steps.delete(sym_by_type)
149
146
 
150
- true
147
+ if status == sym.to_s # I was just this status
148
+ assign_attributes(status: last_completed_status || all_statuses.first)
149
+ end
150
+
151
+ # Assign atts if present
152
+ assign_attributes(atts) if atts.present?
153
+
154
+ save!
151
155
  end
156
+ end
152
157
 
158
+ # Regular instance methods
159
+ # Sort of matches acts_as_wizard
160
+ def status_keys
161
+ self.class.const_get(:STATUSES)
153
162
  end
163
+
164
+ def all_statuses
165
+ status_keys
166
+ end
167
+
168
+ def completed_statuses
169
+ all_statuses.select { |status| has_completed_status?(status) }
170
+ end
171
+
172
+ def last_completed_status
173
+ all_statuses.reverse.find { |status| has_completed_status?(status) }
174
+ end
175
+
176
+ def has_completed_status?(status)
177
+ (errors.present? ? status_steps_was : status_steps)["#{status}_at".to_sym].present?
178
+ end
179
+
154
180
  end
155
181
 
156
182
  module ClassMethods
@@ -35,6 +35,15 @@ module Effective
35
35
  File.join(*[tenant_path, 'app/datatables', namespace, "effective_#{plural_name}_datatable.rb"].compact)
36
36
  end
37
37
 
38
+ # Wizards are kinda weird, we need some help for effective_memberships
39
+ def wizard_file_path(resource)
40
+ if resource.class.try(:effective_memberships_applicant?) || resource.class.try(:effective_memberships_applicant_review?)
41
+ File.join(*['effective', plural_name].compact)
42
+ else
43
+ view_file_path(nil)
44
+ end
45
+ end
46
+
38
47
  # Views
39
48
  def view_file(action = :index, partial: false)
40
49
  File.join(*[tenant_path, 'app/views', class_path, namespace, plural_name, "#{'_' if partial}#{action}.html.haml"].compact)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.8.8'.freeze
2
+ VERSION = '2.9.0'.freeze
3
3
  end
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: 2.8.8
4
+ version: 2.9.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: 2023-08-02 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails