effective_resources 0.6.0 → 0.6.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
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a656240359f56e13c1bfb238df45835f1c52be5f
|
|
4
|
+
data.tar.gz: 2bf2cd4ee1efb59ad3645098f42eb37811bd589f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1e02bd43eac4a53a4bb4d5895254ff86a9ce7b211803e70bcf749a4403afaa1f5ef5bcbb3176b3225864a22d16663f314ce6049023396c023c706576baeb959
|
|
7
|
+
data.tar.gz: 2cf16278075484bdeeda965a38eb00812552b7973bfe7cfb051f10e15db555f3d989c32dab967ba7bbb2955ae06757568903a4c3dfd2cceac633c3d65e5fb1c6
|
|
@@ -136,6 +136,9 @@ module Effective
|
|
|
136
136
|
action = resource_commit_action[:action]
|
|
137
137
|
EffectiveResources.authorized?(self, action, resource) unless action == :save
|
|
138
138
|
|
|
139
|
+
resource.assign_attributes(send(resource_params_method_name))
|
|
140
|
+
resource.created_by ||= current_user if resource.respond_to?(:created_by=)
|
|
141
|
+
|
|
139
142
|
if save_resource(resource, action)
|
|
140
143
|
flash[:success] ||= flash_success(resource, action)
|
|
141
144
|
redirect_to(resource_redirect_path)
|
|
@@ -168,6 +171,8 @@ module Effective
|
|
|
168
171
|
action = resource_commit_action[:action]
|
|
169
172
|
EffectiveResources.authorized?(self, action, resource) unless action == :save
|
|
170
173
|
|
|
174
|
+
resource.assign_attributes(send(resource_params_method_name))
|
|
175
|
+
|
|
171
176
|
if save_resource(resource, action)
|
|
172
177
|
flash[:success] ||= flash_success(resource, action)
|
|
173
178
|
redirect_to(resource_redirect_path)
|
|
@@ -196,6 +201,7 @@ module Effective
|
|
|
196
201
|
end
|
|
197
202
|
end
|
|
198
203
|
|
|
204
|
+
# No attributes are assigned or saved. We purely call action! on the resource.
|
|
199
205
|
def member_post_action(action)
|
|
200
206
|
raise 'expected post, patch or put http action' unless (request.post? || request.patch? || request.put?)
|
|
201
207
|
|
|
@@ -222,6 +228,7 @@ module Effective
|
|
|
222
228
|
end
|
|
223
229
|
end
|
|
224
230
|
|
|
231
|
+
# No attributes are assigned or saved. We purely call action! on the resource
|
|
225
232
|
def collection_post_action(action)
|
|
226
233
|
action = action.to_s.gsub('bulk_', '').to_sym
|
|
227
234
|
|
|
@@ -245,7 +252,7 @@ module Effective
|
|
|
245
252
|
|
|
246
253
|
# Here we look at all available (class level) member actions, see which ones apply to the current resource
|
|
247
254
|
# This feeds into the helper simple_form_submit(f)
|
|
248
|
-
# Returns a Hash of {'Save': {data-disable-with: 'Saving...'}, '
|
|
255
|
+
# Returns a Hash of {'Save': {data-disable-with: 'Saving...'}, 'Approve': {data-disable-with: 'Approve'}}
|
|
249
256
|
def member_actions_for(obj)
|
|
250
257
|
self.class.member_actions.select do |commit, args|
|
|
251
258
|
(args.key?(:if) ? obj.instance_exec(&args[:if]) : true) &&
|
|
@@ -253,13 +260,12 @@ module Effective
|
|
|
253
260
|
end.inject({}) { |h, (commit, args)| h[commit] = args.except(:action, :if, :unless, :redirect); h }
|
|
254
261
|
end
|
|
255
262
|
|
|
263
|
+
protected
|
|
264
|
+
|
|
256
265
|
# This calls the appropriate member action, probably save!, on the resource.
|
|
257
266
|
def save_resource(resource, action = :save)
|
|
258
267
|
raise "expected @#{resource_name} to respond to #{action}!" unless resource.respond_to?("#{action}!")
|
|
259
268
|
|
|
260
|
-
resource.assign_attributes(send(resource_params_method_name))
|
|
261
|
-
|
|
262
|
-
resource.created_by ||= current_user if resource.respond_to?(:created_by=)
|
|
263
269
|
resource.current_user ||= current_user if resource.respond_to?(:current_user=)
|
|
264
270
|
|
|
265
271
|
resource_klass.transaction do
|
|
@@ -276,12 +282,6 @@ module Effective
|
|
|
276
282
|
false
|
|
277
283
|
end
|
|
278
284
|
|
|
279
|
-
protected
|
|
280
|
-
|
|
281
|
-
def resource_commit_action
|
|
282
|
-
self.class.member_actions[params[:commit].to_s] || self.class.member_actions['Save'] || raise("expected member_actions['Save'] to be present")
|
|
283
|
-
end
|
|
284
|
-
|
|
285
285
|
def resource_redirect_path
|
|
286
286
|
commit_action_redirect = case resource_commit_action[:redirect]
|
|
287
287
|
when :index ; resource_index_path
|
|
@@ -303,7 +303,7 @@ module Effective
|
|
|
303
303
|
resource_index_path
|
|
304
304
|
else
|
|
305
305
|
[referer_redirect_path, resource_index_path].compact.first
|
|
306
|
-
end
|
|
306
|
+
end.presence || root_path
|
|
307
307
|
end
|
|
308
308
|
|
|
309
309
|
def referer_redirect_path
|
|
@@ -378,6 +378,10 @@ module Effective
|
|
|
378
378
|
(action.to_s + (action.to_s.end_with?('e') ? 'd' : 'ed'))
|
|
379
379
|
end
|
|
380
380
|
|
|
381
|
+
def resource_commit_action
|
|
382
|
+
self.class.member_actions[params[:commit].to_s] || self.class.member_actions['Save'] || raise("expected member_actions['Save'] to be present")
|
|
383
|
+
end
|
|
384
|
+
|
|
381
385
|
# Returns an ActiveRecord relation based on the computed value of `resource_scope` dsl method
|
|
382
386
|
def resource_scope # Thing
|
|
383
387
|
@_effective_resource_relation ||= (
|