effective_resources 0.6.0 → 0.6.1

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
  SHA1:
3
- metadata.gz: 835582267c27e57dd956b47f7f4ee16611761471
4
- data.tar.gz: 6502e8942e9c05ed2f8fa9b4b253540ee6961255
3
+ metadata.gz: a656240359f56e13c1bfb238df45835f1c52be5f
4
+ data.tar.gz: 2bf2cd4ee1efb59ad3645098f42eb37811bd589f
5
5
  SHA512:
6
- metadata.gz: be0a71e0ee416a1c91c8b42e0b9a5194cf469ecde22d73155ba42ff9fb978f63f54ff0ca9c981b87650e2bafe921137963e351b639256fc11b2e48902dcc58e7
7
- data.tar.gz: c6f43d75ad754c5403ceed17ccf91b07234d7fe82c87a34e8f7c2c8d2ea22b36169d202b49669ee69229eae73e1ab35d30017c43ddfa9ca81086c142190d6e37
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...'}, 'Save and Continue': {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 ||= (
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect