# frozen_string_literal: true require 'drillbit/authorizers/parameters' module Drillbit module Authorizers class Parameters class Resource < Authorizers::Parameters def call params.permit(*authorized_params) end private def authorized_params @authorized_params ||= [ :id, 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[1][:data][:attributes][0][name] = [] else authorized_params[1][: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[1][:data][:relationships][0][name] = [] else authorized_params[1][: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