Sha256: c7ec22401e9986aa97d8c4cd331d8d52d3dadbba312c26e98803ecfb5ef69e58
Contents?: true
Size: 1.27 KB
Versions: 115
Compression:
Stored size: 1.27 KB
Contents
module ForestLiana class ResourceUpdater attr_accessor :record attr_accessor :errors def initialize(resource, params, forest_user) @resource = resource @params = params @errors = nil @user = forest_user end def perform begin collection_name = ForestLiana.name_for(@resource) scoped_records = ForestLiana::ScopeManager.apply_scopes_on_records(@resource, @user, collection_name, @params[:timezone]) @record = scoped_records.find(@params[:id]) if has_strong_parameter @record.update(resource_params) else @record.update(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!).arity == 1 end end end
Version data entries
115 entries across 115 versions & 1 rubygems