Class: Archangel::ApplicationPolicy

Inherits:
Object
  • Object
show all
Defined in:
app/policies/archangel/application_policy.rb

Overview

Application base policy

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, record) ⇒ ApplicationPolicy

Policy initializer

Parameters:

  • user (Object)

    the user

  • record (Object)

    the record



24
25
26
27
# File 'app/policies/archangel/application_policy.rb', line 24

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

Instance Attribute Details

#recordObject (readonly)

Record to check



11
12
13
# File 'app/policies/archangel/application_policy.rb', line 11

def record
  @record
end

#userObject (readonly)

User to check policy for



16
17
18
# File 'app/policies/archangel/application_policy.rb', line 16

def user
  @user
end

Instance Method Details

#create?Boolean

Check if ‘#create` action is authorized for current user

Returns:

  • (Boolean)

    true for all roles



52
53
54
# File 'app/policies/archangel/application_policy.rb', line 52

def create?
  true
end

#destroy?Boolean

Check if ‘#destroy` action is authorized for current user

Returns:

  • (Boolean)

    true for all roles



88
89
90
# File 'app/policies/archangel/application_policy.rb', line 88

def destroy?
  true
end

#edit?Boolean

Check if ‘#edit` action is authorized for current user

Returns:

  • (Boolean)

    true if also able to update record



79
80
81
# File 'app/policies/archangel/application_policy.rb', line 79

def edit?
  update?
end

#index?Boolean

Check if ‘#index` action is authorized for current user

Returns:

  • (Boolean)

    true for all roles



34
35
36
# File 'app/policies/archangel/application_policy.rb', line 34

def index?
  true
end

#new?Boolean

Check if ‘#new` action is authorized for current user

Returns:

  • (Boolean)

    true if also able to create record



61
62
63
# File 'app/policies/archangel/application_policy.rb', line 61

def new?
  create?
end

#scopeBoolean

Nested scope

Returns:

  • (Boolean)

    if scaoped action is authorized



97
98
99
# File 'app/policies/archangel/application_policy.rb', line 97

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

#show?Boolean

Check if ‘#show` action is authorized for current user

Returns:

  • (Boolean)

    true if record exists



43
44
45
# File 'app/policies/archangel/application_policy.rb', line 43

def show?
  scope.where(id: record.id).exists?
end

#update?Boolean

Check if ‘#update` action is authorized for current user

Returns:

  • (Boolean)

    true for all roles



70
71
72
# File 'app/policies/archangel/application_policy.rb', line 70

def update?
  true
end