Class: ApplicationPolicy

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

Overview

Default access to all objects in the application.

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, record) ⇒ ApplicationPolicy

Returns a new instance of ApplicationPolicy.


7
8
9
10
# File 'app/policies/application_policy.rb', line 7

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

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record


5
6
7
# File 'app/policies/application_policy.rb', line 5

def record
  @record
end

#userObject (readonly)

Returns the value of attribute user


5
6
7
# File 'app/policies/application_policy.rb', line 5

def user
  @user
end

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'app/policies/application_policy.rb', line 20

def create?
  @user.present? && @user.admin?
end

#destroy?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/policies/application_policy.rb', line 36

def destroy?
  @user.present? && @user.admin?
end

#edit?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'app/policies/application_policy.rb', line 32

def edit?
  update?
end

#index?Boolean

Returns:

  • (Boolean)

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

def index?
  true
end

#new?Boolean

Returns:

  • (Boolean)

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

def new?
  create?
end

#show?Boolean

Returns:

  • (Boolean)

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

def show?
  true
end

#update?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'app/policies/application_policy.rb', line 28

def update?
  @user.present? && @user.admin?
end