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.



56
57
58
59
60
61
62
63
64
65
# File 'lib/authorization.rb', line 56

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)


46
47
48
49
50
51
# File 'lib/authorization.rb', line 46

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