Class: CollectionPolicy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope = nil) ⇒ CollectionPolicy

Returns a new instance of CollectionPolicy


8
9
10
11
# File 'app/policies/collection_policy.rb', line 8

def initialize(user, scope = nil)
  @user = user
  @scope = scope || base_scope
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user


6
7
8
# File 'app/policies/collection_policy.rb', line 6

def user
  @user
end

Instance Method Details

#authorize!(action, message = nil) ⇒ Object

Raises:


29
30
31
# File 'app/policies/collection_policy.rb', line 29

def authorize!(action, message = nil)
  raise NotAuthorizedError, message unless public_send(action)
end

#base_scopeObject


13
14
15
# File 'app/policies/collection_policy.rb', line 13

def base_scope
  ApplicationRecord.none
end

#create?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'app/policies/collection_policy.rb', line 25

def create?
  false
end

#index?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'app/policies/collection_policy.rb', line 21

def index?
  false
end

#resolveObject


17
18
19
# File 'app/policies/collection_policy.rb', line 17

def resolve
  scope
end