Module: Recurso::Controller

Defined in:
lib/recurso/concerns/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/recurso/concerns/controller.rb', line 5

def self.included(base)
  base.helper_method :policy if base.respond_to?(:helper_method)
end

Instance Method Details

#authorize(resource, action = default_authorize_action) ⇒ Object

Raises:



9
10
11
# File 'lib/recurso/concerns/controller.rb', line 9

def authorize(resource, action = default_authorize_action)
  raise Recurso::Forbidden unless policy(resource).public_send(action)
end

#policy(resource = default_policy_resource) ⇒ Object



13
14
15
16
17
# File 'lib/recurso/concerns/controller.rb', line 13

def policy(resource = default_policy_resource)
  return Recurso::NilClassPolicy.new unless default_policy_identity.present?

  default_policy_identity.policy(resource)
end