effective_resources 2.8.9 → 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: 6a38e2952ba5fef52c6aa082b18ef2d9261c32dcd89f629fa548b22b4c5f70b6
4
- data.tar.gz: 0aebae2fb3691c17fcc6cbe84d3a153592cd0fd4c49aafdeadcf77d511bd5c30
3
+ metadata.gz: 10642ec990cb0ad6b2426415a997aead2f5d53bcdb8a932b3f276af5e9485af9
4
+ data.tar.gz: a971535ad4974d3931be497db3595f91e1baac7483f718e3197778e84674e525
5
5
  SHA512:
6
- metadata.gz: da673d1b40fbdf5c6ddf6322619c4cf8e1641b3aa28a81395de8080f5220d371a272f9cca5541eae8f8206c5020418d1562f1db3f22117c0513eb9fd2df0bc72
7
- data.tar.gz: b0167300f0a180b5f7bb4445aa70750b6a606a38633d9fcb4ba22ea68d5e290602cfc5b659638e4703bed29fb2df8863ce4a94cdc59def680fdeec1acfefdc0f
6
+ metadata.gz: c8ee4692a6b49d21cfe3d591233f9991355cb1d4d3697d5317fceb7186eb9011db71edef3dc8b6ddedc8ba97d3d28b7c7cf80bf753c18a31b344c8cbc7393db1
7
+ data.tar.gz: 7cfa99b30169c1bb0bc316dafdc29bad35996b678affea7f21e9ab6fe469bdf4dd6a3fe013d028b8e8fb4cd4281aa809640477db683e3cb0d987bc40d62375b5
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.8.9'.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.9
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-03 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