lib/sn_foil/contexts/update_context.rb in snfoil-0.8.0 vs lib/sn_foil/contexts/update_context.rb in snfoil-0.8.1
- old
+ new
@@ -15,10 +15,11 @@
end
class_methods do
attr_reader :i_setup_update_hooks, :i_before_update_hooks, :i_after_update_hooks,
:i_after_update_success_hooks, :i_after_update_failure_hooks
+
def update(id:, params:, entity: nil, **options)
new(entity).update(**options, id: id, params: params)
end
def setup_update(method = nil, **options, &block)
@@ -54,20 +55,20 @@
def setup_update_object(params: {}, id: nil, object: nil, **options)
raise ArgumentError, 'one of the following keywords is required: id, object' unless id || object
object = wrap_object(object || scope.resolve.find(id))
- authorize(object, options.fetch(:authorize) { :update? }, **options)
+ authorize(object, options.fetch(:authorize, :update?), **options)
object.attributes = params
options.merge! object: object
end
def update(**options)
options[:action] = :update
options = before_setup_update_object(**options)
options = setup_update_object(**options)
- authorize(options[:object], options.fetch(:authorize) { :update? }, **options)
+ authorize(options[:object], options.fetch(:authorize, :update?), **options)
options = update_hooks(**options)
options[:object]
end
def setup_update(**options)