effective_resources 0.8.18 → 0.8.19

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
  SHA1:
3
- metadata.gz: 26a779e0658cce584ace850ad214ad99b8590c08
4
- data.tar.gz: d6f9d9f97090b0a37eeeee405e5f3fbf30ce3c71
3
+ metadata.gz: 5227cd81c0ab72a5764f6e0f0d9f34fdc0619838
4
+ data.tar.gz: d30f8ea5e36ec64c34aec2b9e85c9e313029d0f2
5
5
  SHA512:
6
- metadata.gz: 071eb0886b9e5f92be4479a64616ed68e1da4ce613e9d518c30c8db660abacd0b9cdab836f187e88c6e338e2a544314c1b5a69c85d1491e32adf8e89dc799475
7
- data.tar.gz: 1da07444c0d9766ba1c6b5a8abc1ee13671414a16f9f6d71699f3b6db7ca435d4462a2fc6f73579c6437f4dee2d17b39902a477277b14a4dc51f383072eaf770
6
+ metadata.gz: 81ffdd31a4ca269fcfccb636fa1800f8fb50590cdd070190384b979f1b3d00d61828abd3dc12f60d6081f5723a3529b7321ab200b21d8673799a562f22deb6ac
7
+ data.tar.gz: 8a570e966b5f190f3c594186a1151797b38d21dfd99a8eb2d60f5b8a03b5feac7a0a26d023e437e18f18c4347a2f204b36d748928aa1b2aa3f64b9f022cc0c96
@@ -204,25 +204,23 @@ module Effective
204
204
 
205
205
  respond_to do |format|
206
206
  if save_resource(resource, action, send(resource_params_method_name))
207
+ request.format = :html if specific_redirect_path?
208
+
207
209
  format.html do
208
210
  flash[:success] ||= resource_flash(:success, resource, action)
209
211
  redirect_to(resource_redirect_path)
210
212
  end
211
213
 
212
214
  format.js do
213
- if specific_redirect_path?
214
- flash[:success] ||= resource_flash(:success, resource, action)
215
- redirect_to(resource_redirect_path)
216
- else
217
- flash.now[:success] ||= resource_flash(:success, resource, action)
218
- reload_resource
219
- # create.js.erb
220
- end
215
+ flash.now[:success] ||= resource_flash(:success, resource, action)
216
+ reload_resource # create.js.erb
221
217
  end
222
218
  else
223
219
  flash.delete(:success)
224
220
  flash.now[:danger] ||= resource_flash(:danger, resource, action)
225
221
 
222
+ run_callbacks(:resource_render)
223
+
226
224
  format.html { render :new }
227
225
  format.js {} # create.js.erb
228
226
  end
@@ -258,25 +256,23 @@ module Effective
258
256
 
259
257
  respond_to do |format|
260
258
  if save_resource(resource, action, send(resource_params_method_name))
259
+ request.format = :html if specific_redirect_path?
260
+
261
261
  format.html do
262
262
  flash[:success] ||= resource_flash(:success, resource, action)
263
263
  redirect_to(resource_redirect_path)
264
264
  end
265
265
 
266
266
  format.js do
267
- if specific_redirect_path?
268
- flash[:success] ||= resource_flash(:success, resource, action)
269
- redirect_to(resource_redirect_path)
270
- else
271
- flash.now[:success] ||= resource_flash(:success, resource, action)
272
- reload_resource
273
- # update.js.erb
274
- end
267
+ flash.now[:success] ||= resource_flash(:success, resource, action)
268
+ reload_resource # update.js.erb
275
269
  end
276
270
  else
277
271
  flash.delete(:success)
278
272
  flash.now[:danger] ||= resource_flash(:danger, resource, action)
279
273
 
274
+ run_callbacks(:resource_render)
275
+
280
276
  format.html { render :edit }
281
277
  format.js { } # update.js.erb
282
278
  end
@@ -292,19 +288,16 @@ module Effective
292
288
 
293
289
  respond_to do |format|
294
290
  if save_resource(resource, action)
291
+ request.format = :html if specific_redirect_path?
292
+
295
293
  format.html do
296
294
  flash[:success] ||= resource_flash(:success, resource, action)
297
295
  redirect_to(resource_redirect_path(action))
298
296
  end
299
297
 
300
298
  format.js do
301
- if specific_redirect_path?
302
- flash[:success] ||= resource_flash(:success, resource, action)
303
- redirect_to(esource_redirect_path(action))
304
- else
305
- flash.now[:success] ||= resource_flash(:success, resource, action)
306
- # destroy.js.erb
307
- end
299
+ flash.now[:success] ||= resource_flash(:success, resource, action)
300
+ # destroy.js.erb
308
301
  end
309
302
  else
310
303
  flash.delete(:success)
@@ -327,25 +320,24 @@ module Effective
327
320
 
328
321
  respond_to do |format|
329
322
  if save_resource(resource, action, (send(resource_params_method_name) rescue {}))
323
+ request.format = :html if specific_redirect_path?
324
+
330
325
  format.html do
331
326
  flash[:success] ||= resource_flash(:success, resource, action)
332
327
  redirect_to(resource_redirect_path(action))
333
328
  end
334
329
 
335
330
  format.js do
336
- if specific_redirect_path?(action)
337
- flash[:success] ||= resource_flash(:success, resource, action)
338
- redirect_to(resource_redirect_path(action))
339
- else
340
- flash.now[:success] ||= resource_flash(:success, resource, action)
341
- reload_resource
342
- render_member_action(action)
343
- end
331
+ flash.now[:success] ||= resource_flash(:success, resource, action)
332
+ reload_resource
333
+ render_member_action(action)
344
334
  end
345
335
  else
346
336
  flash.delete(:success)
347
337
  flash.now[:danger] ||= resource_flash(:danger, resource, action)
348
338
 
339
+ run_callbacks(:resource_render)
340
+
349
341
  format.html do
350
342
  if resource_edit_path && (referer_redirect_path || '').end_with?(resource_edit_path)
351
343
  @page_title ||= "Edit #{resource}"
@@ -413,6 +405,7 @@ module Effective
413
405
  end
414
406
 
415
407
  yield if block_given?
408
+
416
409
  run_callbacks(:resource_save)
417
410
  return true
418
411
  rescue => e
@@ -442,9 +435,9 @@ module Effective
442
435
  def resource_flash(status, resource, action)
443
436
  submit = commit_action(action)
444
437
  message = submit[status].respond_to?(:call) ? instance_exec(&submit[status]) : submit[status]
445
- return message if message.present?
438
+ return if message.present?
446
439
 
447
- message || case status
440
+ case status
448
441
  when :success then flash_success(resource, action)
449
442
  when :danger then flash_danger(resource, action)
450
443
  else
@@ -565,10 +558,6 @@ module Effective
565
558
  effective_resource.plural_name
566
559
  end
567
560
 
568
- def action_verb(action)
569
- (action.to_s + (action.to_s.end_with?('e') ? 'd' : 'ed'))
570
- end
571
-
572
561
  # Based on the incoming params[:commit] or passed action
573
562
  def commit_action(action = nil)
574
563
  self.class.submits[params[:commit].to_s] ||
@@ -6,11 +6,9 @@ module Effective
6
6
  def flash_success(resource, action = nil, name: nil)
7
7
  raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
8
8
 
9
- name ||= resource.class.model_name.human
9
+ name ||= resource.class.model_name.human.downcase
10
10
 
11
- action = (action || :save).to_s.gsub('_', ' ')
12
-
13
- "#{name.to_s.titleize} was successfully #{action}#{(action == 'submit' ? 't' : '')}#{(action.end_with?('e') ? 'd' : 'ed')}"
11
+ "Successfully #{action_verb(action)} #{name}"
14
12
  end
15
13
 
16
14
  # flash.now[:danger] = flash_danger(@post)
@@ -19,10 +17,11 @@ module Effective
19
17
 
20
18
  action ||= resource.respond_to?(:new_record?) ? (resource.new_record? ? :create : :update) : :save
21
19
  action = action.to_s.gsub('_', ' ')
22
- name ||= resource.class.model_name.human
20
+
21
+ name ||= resource.class.model_name.human.downcase
23
22
  messages = flash_errors(resource, e: e)
24
23
 
25
- ["Unable to #{action} #{name.to_s.downcase}", (": #{messages}." if messages)].compact.join.html_safe
24
+ ["Unable to #{action} #{name}", (": #{messages}." if messages)].compact.join.html_safe
26
25
  end
27
26
 
28
27
  # flash.now[:danger] = "Unable to accept: #{flash_errors(@post)}"
@@ -45,5 +44,17 @@ module Effective
45
44
 
46
45
  messages.to_sentence.presence
47
46
  end
47
+
48
+ def action_verb(action)
49
+ action = action.to_s.gsub('_', ' ')
50
+ word = action.split(' ').first
51
+
52
+ if word.end_with?('e')
53
+ action.sub(word, word + 'd')
54
+ else
55
+ action.sub(word, word + 'ed')
56
+ end
57
+ end
58
+
48
59
  end
49
60
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.8.18'.freeze
2
+ VERSION = '0.8.19'.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: 0.8.18
4
+ version: 0.8.19
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: 2018-05-28 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails