Module: Pragma::Operation::Authorization::ClassMethods

Defined in:
lib/pragma/operation/authorization.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#policy(klass = nil) { ... } ⇒ Object

Sets the policy to use for authorizing this operation.

Parameters:

  • klass (Class) (defaults to: nil)

    a subclass of Pragma::Policy::Base

Yields:

  • A block which will be called with the operation’s context which should return the policy class. The block can also return nil if authorization should be skipped.



20
21
22
23
24
25
26
# File 'lib/pragma/operation/authorization.rb', line 20

def policy(klass = nil, &block)
  if !klass && !block_given?
    fail ArgumentError, 'You must pass either a policy class or a block'
  end

  @policy = klass || block
end

#policy_klassClass

Returns the policy class.

Returns:

  • (Class)


31
32
33
# File 'lib/pragma/operation/authorization.rb', line 31

def policy_klass
  @policy
end