Sha256: f6dffd32d77372f0b508d2d6b6db538698522d727104181983a73973c1faed16
Contents?: true
Size: 1.2 KB
Versions: 7
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true require 'drillbit/utilities/string' module Drillbit module Authorizers class Scope attr_accessor :token, :user, :params, :scope_root # rubocop:disable Metrics/ParameterLists def initialize(token:, user:, issuer:, params:, scope_root:, **other) self.token = token self.user = user self.params = params self.scope_root = scope_root other.each do |name, value| public_send("#{name}=", value) end end # rubocop:enable Metrics/ParameterLists def user_scope scope_root.public_send("for_#{user_underscored_class_name}", scope_user_id) end def public_scope scope_root.none end def call if scope_user_id user_scope else public_scope end end private def scope_user_id @scope_user_id ||= params. fetch(:filter, {}). fetch(user_underscored_class_name, nil) end def user_underscored_class_name @user_underscored_class_name ||= begin base_user_class_name = user.class.name[/([^:]+)\z/, 1] Utilities::String.underscore(base_user_class_name).downcase end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems