effective_resources 2.8.9 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a38e2952ba5fef52c6aa082b18ef2d9261c32dcd89f629fa548b22b4c5f70b6
4
- data.tar.gz: 0aebae2fb3691c17fcc6cbe84d3a153592cd0fd4c49aafdeadcf77d511bd5c30
3
+ metadata.gz: e271cc3c7cc6656818fa8584765872c44add6e05f45aebf71b21a2463d27975e
4
+ data.tar.gz: b96b045469f418016cbef1d000eec3ee3b82b260122eff4a6f160e689f55f0b1
5
5
  SHA512:
6
- metadata.gz: da673d1b40fbdf5c6ddf6322619c4cf8e1641b3aa28a81395de8080f5220d371a272f9cca5541eae8f8206c5020418d1562f1db3f22117c0513eb9fd2df0bc72
7
- data.tar.gz: b0167300f0a180b5f7bb4445aa70750b6a606a38633d9fcb4ba22ea68d5e290602cfc5b659638e4703bed29fb2df8863ce4a94cdc59def680fdeec1acfefdc0f
6
+ metadata.gz: b065909664f6d3dfd6cdb6589023dcd743b77feeccf2d98e74ef940780c5a48492681915437975aa7bd988251d768367d50b00f8198de841642af7728425eec7
7
+ data.tar.gz: 44e79e8885d98c26b5179955f60cc7b775efac0d7804712e4d5556b20df09fc00d6efad0f9db8e40a0e61c959fc355ec5cf7b7314dcec80aceb0f476932fd9a3
@@ -185,8 +185,10 @@ module Effective
185
185
  respond_to do |format|
186
186
  format.html { }
187
187
  format.js do
188
+ html_template = action if template_present?(action, format: :html)
188
189
  template = template_present?(action) ? action : 'member_action'
189
- render(template, formats: :js, locals: { action: action })
190
+
191
+ render(template, formats: :js, locals: { action: action, html_template: html_template })
190
192
  end
191
193
  end
192
194
 
@@ -103,9 +103,10 @@ module Effective
103
103
  flash[:danger] ||= danger
104
104
  end
105
105
 
106
- def template_present?(action)
106
+ def template_present?(action, format: nil)
107
+ format = Array(format).presence
107
108
  formats = [(request.format.symbol.to_s.sub('json', 'js').presence || 'html').to_sym]
108
- lookup_context.template_exists?(action, _prefixes, formats: formats)
109
+ lookup_context.template_exists?(action, _prefixes, formats: (format || formats))
109
110
  end
110
111
 
111
112
  end
@@ -189,13 +189,15 @@ module EffectiveResourcesHelper
189
189
  safe = atts.delete(:safe)
190
190
  atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
191
191
 
192
- if lookup_context.template_exists?(effective_resource.name, controller._prefixes, :partial)
193
- return render(effective_resource.name, atts)
192
+ partial = (action.present? ? action.to_s : effective_resource.name)
193
+
194
+ if lookup_context.template_exists?(partial, controller._prefixes, :partial)
195
+ return render(partial, atts)
194
196
  end
195
197
 
196
198
  effective_resource.view_paths.each do |view_path|
197
- if lookup_context.template_exists?(effective_resource.name, [view_path], :partial)
198
- return render(view_path + '/' + effective_resource.name, atts)
199
+ if lookup_context.template_exists?(partial, [view_path], :partial)
200
+ return render(view_path + '/' + partial, atts)
199
201
  end
200
202
  end
201
203
 
@@ -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
@@ -146,10 +146,16 @@ module ActsAsWizard
146
146
  has_completed_step?(required_steps.last)
147
147
  end
148
148
 
149
- def reset_wizard_steps!
149
+ def reset_all_wizard_steps!
150
150
  update!(wizard_steps: {})
151
151
  end
152
152
 
153
+ def complete_all_wizard_steps!
154
+ now = Time.zone.now
155
+ required_steps.each { |step| wizard_steps[step] ||= now }
156
+ save!
157
+ end
158
+
153
159
  def without_current_step(&block)
154
160
  existing = current_step
155
161
 
@@ -1,7 +1,12 @@
1
1
  <% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
2
2
  <% @resource = instance_variable_get('@' + resource.name) if resource.name %>
3
3
 
4
- EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource, action: action, safe: true) %>";
4
+ <% if html_template.present? %>
5
+ EffectiveForm.remote_form_payload = "<%= j(render_resource_partial(@resource, action: action)) %>";
6
+ <% else %>
7
+ EffectiveForm.remote_form_payload = "<%= j(render_resource_form(@resource, action: action, safe: true).presence || render_resource_partial(@resource)) %>";
8
+ <% end %>
9
+
5
10
  EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
6
11
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
7
12
 
@@ -46,10 +46,8 @@ module EffectiveResources
46
46
  app.config.to_prepare do
47
47
  if defined?(CanCan::Ability)
48
48
  CanCan::Ability.module_eval do
49
- CRUD_ACTIONS = [:index, :new, :create, :edit, :update, :show, :destroy]
50
-
51
49
  def crud
52
- CRUD_ACTIONS
50
+ [:index, :new, :create, :edit, :update, :show, :destroy]
53
51
  end
54
52
  end
55
53
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.8.9'.freeze
2
+ VERSION = '2.9.1'.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.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: 2023-08-03 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails