Module: Authorization::Base::ControllerInstanceMethods

Includes:
EvalParser
Defined in:
lib/authorization.rb

Instance Method Summary collapse

Methods included from EvalParser

#parse_authorization_expression, #process_role, #process_role_of_model, #replace_role, #replace_role_of_model, #replace_temporarily_role_of_model

Instance Method Details

#permit(authorization_expression, *args) ⇒ Object

Allow method-level authorization checks. permit (without a question mark ending) calls redirect on denial by default. Specify :redirect => false to turn off redirection.



60
61
62
63
64
65
66
67
68
69
# File 'lib/authorization.rb', line 60

def permit( authorization_expression, *args )
  @options = { :allow_guests => false, :redirect => true }
  @options.merge!( args.last.is_a?( Hash ) ? args.last : {} )

  if has_permission?( authorization_expression )
    yield if block_given?
  elsif @options[:redirect]
    handle_redirection
  end
end

#permit?(authorization_expression, *args) ⇒ Boolean

Permit? turns off redirection by default and takes no blocks

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/authorization.rb', line 50

def permit?( authorization_expression, *args )
  @options = { :allow_guests => false, :redirect => false }
  @options.merge!( args.last.is_a?( Hash ) ? args.last : {} )

  has_permission?( authorization_expression )
end