Sha256: 24fcd8fc5259ad60e73f03bdb2e4a575f362948840994fbd995ca7ddccdc11f2
Contents?: true
Size: 1.08 KB
Versions: 26
Compression:
Stored size: 1.08 KB
Contents
module ForestLiana class ResourceUpdater attr_accessor :record attr_accessor :errors def initialize(resource, params) @resource = resource @params = params @errors = nil end def perform begin @record = @resource.find(@params[:id]) if has_strong_parameter @record.update_attributes(resource_params) else @record.update_attributes(resource_params, without_protection: true) end rescue ActiveRecord::StatementInvalid => exception # NOTICE: SQLÂ request cannot be executed properly @errors = [{ detail: exception.cause.error }] rescue ForestLiana::Errors::SerializeAttributeBadFormat => exception @errors = [{ detail: exception.message }] rescue => exception @errors = [{ detail: exception.message }] end end def resource_params ResourceDeserializer.new(@resource, @params, false).perform end def has_strong_parameter Rails::VERSION::MAJOR > 5 || @resource.instance_method(:update_attributes!).arity == 1 end end end
Version data entries
26 entries across 26 versions & 1 rubygems