Module: Jwtauth::Policy

Defined in:
lib/jwtauth.rb

Overview

require use Pundit (gem <<pundit>>)

Defined Under Namespace

Modules: ClassMethods, LevelsOfAccess, Privileges Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



395
396
397
# File 'lib/jwtauth.rb', line 395

def record
  @record
end

#userObject (readonly)

Returns the value of attribute user.



395
396
397
# File 'lib/jwtauth.rb', line 395

def user
  @user
end

Instance Method Details

#_entity_classObject



434
435
436
# File 'lib/jwtauth.rb', line 434

def _entity_class
  @record.is_a?(Class) ? @record.name.underscore : @record.class.name.underscore
end

#create?Boolean

Returns:

  • (Boolean)


410
411
412
# File 'lib/jwtauth.rb', line 410

def create?
  record_action?(get_level_of_access(Privileges::CREATE))
end

#destroy?Boolean

Returns:

  • (Boolean)


426
427
428
# File 'lib/jwtauth.rb', line 426

def destroy?
  record_action?(get_level_of_access(Privileges::DELETE))
end

#edit?Boolean

Returns:

  • (Boolean)


422
423
424
# File 'lib/jwtauth.rb', line 422

def edit?
  update?
end

#index?Boolean

Returns:

  • (Boolean)


402
403
404
# File 'lib/jwtauth.rb', line 402

def index?
  get_level_of_access(Privileges::READ) != LevelsOfAccess::NONE
end

#initialize(user, record) ⇒ Object



397
398
399
400
# File 'lib/jwtauth.rb', line 397

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

#new?Boolean

Returns:

  • (Boolean)


414
415
416
# File 'lib/jwtauth.rb', line 414

def new?
  create?
end

#scopeObject



430
431
432
# File 'lib/jwtauth.rb', line 430

def scope
  Pundit.policy_scope!(user, record.class)
end

#show?Boolean

Returns:

  • (Boolean)


406
407
408
# File 'lib/jwtauth.rb', line 406

def show?
  record_action?(get_level_of_access(Privileges::READ))
end

#update?Boolean

Returns:

  • (Boolean)


418
419
420
# File 'lib/jwtauth.rb', line 418

def update?
  record_action?(get_level_of_access(Privileges::UPDATE))
end