class Drillbit::Authorizers::Scope

Attributes

action[RW]
params[RW]
scope_root[RW]
token[RW]
user[RW]

Public Class Methods

new(action:, token:, user:, issuer:, params:, scope_root:, **other) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/drillbit/authorizers/scope.rb, line 15
def initialize(action:, token:, user:, issuer:, params:, scope_root:, **other)
  self.action     = action
  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

Public Instance Methods

call() click to toggle source
# File lib/drillbit/authorizers/scope.rb, line 36
def call
  if scope_user_id
    user_scope
  else
    public_scope
  end
end
public_scope() click to toggle source
# File lib/drillbit/authorizers/scope.rb, line 32
def public_scope
  scope_root.none
end
user_scope() click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/drillbit/authorizers/scope.rb, line 28
def user_scope
  scope_root.public_send("for_#{user_underscored_class_name}", scope_user_id)
end

Private Instance Methods

scope_user_id() click to toggle source
# File lib/drillbit/authorizers/scope.rb, line 46
def scope_user_id
  @scope_user_id ||= params
                       .fetch(:filter, {})
                       .fetch(user_underscored_class_name, nil)
end
user_underscored_class_name() click to toggle source
# File lib/drillbit/authorizers/scope.rb, line 52
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