Sha256: ab71bf88eafd3512d633295502983eb2394393ad6b4a84af8f3ee97680ab3191
Contents?: true
Size: 1.05 KB
Versions: 152
Compression:
Stored size: 1.05 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 @resource.instance_method(:update_attributes!).arity == 1 end end end
Version data entries
152 entries across 152 versions & 1 rubygems