effective_resources 1.2.14 → 1.2.15

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: b5e70fee638a428f79f18157693b709b98012619
4
- data.tar.gz: 90598b13782b0538c1553181e00c822456c14914
3
+ metadata.gz: a9c1374e91be1d5cc6a59a84d3bf3101b6f070e3
4
+ data.tar.gz: 54937ae6e523329f6078a89bd9f013978e0cbfb2
5
5
  SHA512:
6
- metadata.gz: 9012ba03094e3701829fbdf23259c2d119287c57025bba3c44a074436011b01ff9f43fac36202e3a34d41a689324c164e07c4815a9473eee0075ecb7b7a147eb
7
- data.tar.gz: 9b15ace87c1582da176f84c737246052086858a4d3971a40368bae80c9ab70dde5255f4ebd85e009d4e6ea5c13b1c3b868e29ca132646cbd688d415ab156dc5c
6
+ metadata.gz: 105eef30f447c6623b55b0073a3456ad89fad27ab8e0db2589e8402b8b7a491d31f319fc59554b4a8c44e0486ac26112eb54903014c29ce512e5be84ae84c5f3
7
+ data.tar.gz: 1e1d91e424de80e48c73b630813f9b9b3cf4704b1d4ff60d847672608331de5ae1427d270e93cf202654111125791d8a894f8a4cfe8f565e13f38c3d1d0341d1
data/README.md CHANGED
@@ -148,7 +148,7 @@ class PostsController < ApplicationController
148
148
  # Sets the @page_title in a before_filter
149
149
  page_title 'My Posts', only: [:index]
150
150
 
151
- # Callbacks: before_save, after_save, resource_error
151
+ # Callbacks: before_render, before_save, after_save, after_error, after_commit
152
152
  before_render(only: :new) do
153
153
  resource.client = current_user.clients.first
154
154
  end
@@ -166,20 +166,6 @@ class PostsController < ApplicationController
166
166
  Post.active.where(user: current_user)
167
167
  end
168
168
 
169
- # The following methods are discovered from the routes.rb and defined automatically.
170
- # But you could also define them like this if you wanted.
171
-
172
- # When GET request, will render the approve page
173
- # When POST|PATCH|PUT request, will call @post.approve! and do the right thing
174
- member_action :approve
175
-
176
- # When GET request, will render an index page scoped to this method (if it's a scope on the model i.e. Post.approved)
177
- collection_action :approved
178
-
179
- # When POST|PATCH|PUT request, will call @post.approve! on each post as per params[:ids]
180
- # Created with effective_datatables bulk actions in mind
181
- collection_action :bulk_approve
182
-
183
169
  protected
184
170
 
185
171
  # The post_params are discovered from the model effective_resource do ... end block.
@@ -69,12 +69,10 @@ module Effective
69
69
  EffectiveResources.authorize!(self, action, resource)
70
70
  @page_title ||= "New #{resource_name.titleize}"
71
71
 
72
- respond_to do |format|
73
- if save_resource(resource, action)
74
- respond_with_success(format, resource, action)
75
- else
76
- respond_with_error(format, resource, action)
77
- end
72
+ if save_resource(resource, action)
73
+ respond_with_success(resource, action)
74
+ else
75
+ respond_with_error(resource, action)
78
76
  end
79
77
  end
80
78
 
@@ -123,12 +121,10 @@ module Effective
123
121
 
124
122
  resource.assign_attributes(send(resource_params_method_name))
125
123
 
126
- respond_to do |format|
127
- if save_resource(resource, action)
128
- respond_with_success(format, resource, action)
129
- else
130
- respond_with_error(format, resource, action)
131
- end
124
+ if save_resource(resource, action)
125
+ respond_with_success(resource, action)
126
+ else
127
+ respond_with_error(resource, action)
132
128
  end
133
129
  end
134
130
 
@@ -145,12 +141,10 @@ module Effective
145
141
  EffectiveResources.authorize!(self, action, resource)
146
142
  @page_title ||= "Destroy #{resource}"
147
143
 
148
- respond_to do |format|
149
- if save_resource(resource, action)
150
- respond_with_success(format, resource, action)
151
- else
152
- respond_with_error(format, resource, action)
153
- end
144
+ if save_resource(resource, action)
145
+ respond_with_success(resource, action)
146
+ else
147
+ respond_with_error(resource, action)
154
148
  end
155
149
  end
156
150
 
@@ -176,12 +170,10 @@ module Effective
176
170
  to_assign = (send(resource_params_method_name) rescue {})
177
171
  resource.assign_attributes(to_assign) if to_assign.present? && to_assign.permitted?
178
172
 
179
- respond_to do |format|
180
- if save_resource(resource, action)
181
- respond_with_success(format, resource, action)
182
- else
183
- respond_with_error(format, resource, action)
184
- end
173
+ if save_resource(resource, action)
174
+ respond_with_success(resource, action)
175
+ else
176
+ respond_with_error(resource, action)
185
177
  end
186
178
  end
187
179
 
@@ -1,86 +1,94 @@
1
1
  module Effective
2
2
  module CrudController
3
3
  module Respond
4
- def respond_with_success(format, resource, action)
4
+ def respond_with_success(resource, action)
5
+ return if response.body.present?
6
+
5
7
  if specific_redirect_path?(action)
6
- format.html do
7
- flash[:success] ||= resource_flash(:success, resource, action)
8
- redirect_to(resource_redirect_path(action))
9
- end
8
+ respond_to do |format|
9
+ format.html do
10
+ flash[:success] ||= resource_flash(:success, resource, action)
11
+ redirect_to(resource_redirect_path(action))
12
+ end
10
13
 
11
- format.js do
12
- flash[:success] ||= resource_flash(:success, resource, action)
13
- redirect_to(resource_redirect_path(action))
14
+ format.js do
15
+ flash[:success] ||= resource_flash(:success, resource, action)
16
+ redirect_to(resource_redirect_path(action))
17
+ end
14
18
  end
15
19
  elsif template_present?(action)
16
- format.html do
17
- flash.now[:success] ||= resource_flash(:success, resource, action)
18
- render(action) # action.html.haml
19
- end
20
+ respond_to do |format|
21
+ format.html do
22
+ flash.now[:success] ||= resource_flash(:success, resource, action)
23
+ render(action) # action.html.haml
24
+ end
20
25
 
21
- format.js do
22
- flash.now[:success] ||= resource_flash(:success, resource, action)
23
- #reload_resource unless action == :destroy # Removed.
24
- render(action) # action.js.erb
26
+ format.js do
27
+ flash.now[:success] ||= resource_flash(:success, resource, action)
28
+ #reload_resource unless action == :destroy # Removed.
29
+ render(action) # action.js.erb
30
+ end
25
31
  end
26
- elsif response_body.present? # We might have done something weird like send_data in an after_save
27
- format.html { flash.now[:success] ||= resource_flash(:success, resource, action) }
28
- format.js { flash.now[:success] ||= resource_flash(:success, resource, action) }
29
32
  else # Default
30
- format.html do
31
- flash[:success] ||= resource_flash(:success, resource, action)
32
- redirect_to(resource_redirect_path(action))
33
- end
33
+ respond_to do |format|
34
+ format.html do
35
+ flash[:success] ||= resource_flash(:success, resource, action)
36
+ redirect_to(resource_redirect_path(action))
37
+ end
34
38
 
35
- format.js do
36
- flash.now[:success] ||= resource_flash(:success, resource, action)
37
- render(:member_action, locals: { action: action })
39
+ format.js do
40
+ flash.now[:success] ||= resource_flash(:success, resource, action)
41
+ render(:member_action, locals: { action: action })
42
+ end
38
43
  end
39
44
  end
40
45
  end
41
46
 
42
- def respond_with_error(format, resource, action)
47
+ def respond_with_error(resource, action)
48
+ return if response.body.present?
49
+
43
50
  flash.delete(:success)
44
51
  flash.now[:danger] ||= resource_flash(:danger, resource, action)
45
52
 
46
- run_callbacks(:resource_render)
47
-
48
- # HTML responder
49
- case action.to_sym
50
- when :create
51
- format.html { render :new }
52
- when :update
53
- format.html { render :edit }
54
- when :destroy
55
- format.html do
56
- redirect_flash
57
- redirect_to(resource_redirect_path(action))
58
- end
59
- else # member action
60
- format.html do
61
- if resource_edit_path && referer_redirect_path.to_s.end_with?(resource_edit_path)
62
- @page_title ||= "Edit #{resource}"
63
- render :edit
64
- elsif resource_new_path && referer_redirect_path.to_s.end_with?(resource_new_path)
65
- @page_title ||= "New #{resource_name.titleize}"
66
- render :new
67
- elsif resource_action_path(action) && referer_redirect_path.to_s.end_with?(resource_action_path(action)) && template_present?(action)
68
- @page_title ||= "#{action.to_s.titleize} #{resource}"
69
- render(action, locals: { action: action })
70
- elsif resource_show_path && referer_redirect_path.to_s.end_with?(resource_show_path)
71
- @page_title ||= resource_name.titleize
72
- render :show
73
- else
74
- @page_title ||= resource.to_s
53
+ respond_to do |format|
54
+ case action.to_sym
55
+ when :create
56
+ format.html { render :new }
57
+ when :update
58
+ format.html { render :edit }
59
+ when :destroy
60
+ format.html do
75
61
  redirect_flash
76
- redirect_to(referer_redirect_path || resource_redirect_path(action))
62
+ redirect_to(resource_redirect_path(action))
63
+ end
64
+ else # member action
65
+ from_path = referer_redirect_path.to_s
66
+
67
+ format.html do
68
+ if resource_edit_path && from_path.end_with?(resource_edit_path)
69
+ @page_title ||= "Edit #{resource}"
70
+ render :edit
71
+ elsif resource_new_path && from_path.end_with?(resource_new_path)
72
+ @page_title ||= "New #{resource_name.titleize}"
73
+ render :new
74
+ elsif resource_action_path(action) && from_path.end_with?(resource_action_path(action)) && template_present?(action)
75
+ @page_title ||= "#{action.to_s.titleize} #{resource}"
76
+ render(action, locals: { action: action })
77
+ elsif resource_show_path && from_path.end_with?(resource_show_path)
78
+ @page_title ||= resource_name.titleize
79
+ render :show
80
+ else
81
+ @page_title ||= resource.to_s
82
+ redirect_flash
83
+ redirect_to(from_path.presence || resource_redirect_path(action))
84
+ end
77
85
  end
78
86
  end
79
- end
80
87
 
81
- format.js do
82
- view = template_present?(action) ? action : :member_action
83
- render(view, locals: { action: action }) # action.js.erb
88
+ format.js do
89
+ view = template_present?(action) ? action : :member_action
90
+ render(view, locals: { action: action }) # action.js.erb
91
+ end
84
92
  end
85
93
  end
86
94
 
@@ -64,8 +64,7 @@ module Effective
64
64
  end
65
65
  end
66
66
 
67
- run_callbacks(:resource_error) unless success
68
- run_callbacks(:resource_after_commit) if success
67
+ run_callbacks(success ? :resource_after_commit : :resource_error)
69
68
 
70
69
  success
71
70
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.2.14'.freeze
2
+ VERSION = '1.2.15'.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: 1.2.14
4
+ version: 1.2.15
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: 2019-05-03 00:00:00.000000000 Z
11
+ date: 2019-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails