Class: Pragma::Policy::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/pragma/policy/scope.rb

Overview

Authorizes AR scopes and other relations by only returning the records accessible by the current user. Used, for instance, in index operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope) ⇒ Scope

Initializes the scope.

Parameters:

  • user (Object)

    the user accessing the records

  • scope (Object)

    the relation to use as a base



20
21
22
23
# File 'lib/pragma/policy/scope.rb', line 20

def initialize(user, scope)
  @user = user
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



13
# File 'lib/pragma/policy/scope.rb', line 13

attr_reader :user, :scope

#userObject (readonly) Also known as: context

Returns the user accessing the records.

Returns:

  • (Object)

    the user accessing the records



13
14
15
# File 'lib/pragma/policy/scope.rb', line 13

def user
  @user
end

Instance Method Details

#resolveObject

This method is abstract.

Override to implement retrieving the accessible records

Returns the records accessible by the given user.

Returns:

  • (Object)


30
31
32
# File 'lib/pragma/policy/scope.rb', line 30

def resolve
  fail NotImplementedError
end