Class: Proclaim::PostPolicy

Inherits:
ApplicationPolicy show all
Defined in:
app/policies/proclaim/post_policy.rb

Defined Under Namespace

Classes: Scope

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#record, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#edit?, #initialize, #new?, #scope

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/policies/proclaim/post_policy.rb', line 15

def create?
	not @user.nil? # As long as there's a user, it can create posts
end

#destroy?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/policies/proclaim/post_policy.rb', line 23

def destroy?
	not @user.nil? # As long as there's a user, it can destroy posts
end

#index?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'app/policies/proclaim/post_policy.rb', line 3

def index?
	true # Anyone can list posts
end

#show?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'app/policies/proclaim/post_policy.rb', line 7

def show?
	if @user
		true # A logged in user can see anything
	else
		@record.published? # Guests can see published posts
	end
end

#update?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/policies/proclaim/post_policy.rb', line 19

def update?
	not @user.nil? # As long as there's a user, it can update posts
end