Class: Drillbit::Authorizers::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/drillbit/authorizers/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, user:, params:, scope_root:, **other) ⇒ Scope

Returns a new instance of Scope.



12
13
14
15
16
17
18
19
20
21
# File 'lib/drillbit/authorizers/scope.rb', line 12

def initialize(token:, user:, 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

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



7
8
9
# File 'lib/drillbit/authorizers/scope.rb', line 7

def params
  @params
end

#scope_rootObject

Returns the value of attribute scope_root.



7
8
9
# File 'lib/drillbit/authorizers/scope.rb', line 7

def scope_root
  @scope_root
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/drillbit/authorizers/scope.rb', line 7

def token
  @token
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/drillbit/authorizers/scope.rb', line 7

def user
  @user
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
# File 'lib/drillbit/authorizers/scope.rb', line 31

def call
  if scope_user_id
    user_scope
  else
    public_scope
  end
end

#public_scopeObject



27
28
29
# File 'lib/drillbit/authorizers/scope.rb', line 27

def public_scope
  scope_root.none
end

#user_scopeObject



23
24
25
# File 'lib/drillbit/authorizers/scope.rb', line 23

def user_scope
  scope_root.public_send("for_#{user_underscored_class_name}", scope_user_id)
end