# frozen_string_literal: true require 'drillbit/authorizers/parameters' # :reek:UnusedPrivateMethod module Drillbit module Authorizers class Parameters class Resource < Authorizers::Parameters def call params.permit(*authorized_params) end private def authorized_params @authorized_params ||= [ data: [ :type, :id, { attributes: [ {}, ], relationships: [ {}, ], }, ], ] end def add_authorized_attribute(name) param = params.fetch(:data, {}). fetch(:attributes, {}). fetch(name, nil) if param.class == Array authorized_params[0][:data][:attributes][0][name] = [] else authorized_params[0][:data][2][:attributes] << name end end def add_authorized_attributes(*names) names.each do |name| add_authorized_attribute(name) end end def add_authorized_relationship(name) param = params.fetch(:data, {}). fetch(:relationships, {}). fetch(name, nil) if param.class == Array authorized_params[0][:data][:relationships][0][name] = [] else authorized_params[0][:data][2][:relationships] << name end end def add_authorized_relationships(*names) names.each do |name| add_authorized_relationship(name) end end end end end end