Module: Authority::Controller

Extended by:
ActiveSupport::Concern
Includes:
ActiveSupport::Rescuable
Defined in:
lib/authority/controller.rb

Overview

Gets included into the app’s controllers automatically by the railtie

Defined Under Namespace

Modules: ClassMethods Classes: AuthorizationNotPerformed, MissingAction, MissingResource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorization_performed=(value) ⇒ Object (writeonly)

Sets the attribute authorization_performed

Parameters:

  • value

    the value to set the attribute authorization_performed to.



22
23
24
# File 'lib/authority/controller.rb', line 22

def authorization_performed=(value)
  @authorization_performed = value
end

Class Method Details

.security_violation_callbackObject



8
9
10
11
12
13
14
# File 'lib/authority/controller.rb', line 8

def self.security_violation_callback
  Proc.new do |exception|
    # Through the magic of `instance_exec` `ActionController::Base#rescue_from`
    # can call this proc and make `self` the actual controller instance
    self.send(Authority.configuration.security_violation_handler, exception)
  end
end

Instance Method Details

#authorization_performed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/authority/controller.rb', line 24

def authorization_performed?
  !!@authorization_performed
end

#ensure_authorization_performed(options = {}) ⇒ Object



28
29
30
31
32
33
# File 'lib/authority/controller.rb', line 28

def ensure_authorization_performed(options = {})
  return if authorization_performed?
  return if options[:if]     && !send(options[:if])
  return if options[:unless] && send(options[:unless])
  raise AuthorizationNotPerformed, "No authorization was performed for #{self.class.to_s}##{self.action_name}"
end