module Padrino::Access::InstanceMethods

Public Instance Methods

access_action?(action = nil, object = nil, &block) click to toggle source

Checks if current visitor is allowed to to the action with object. Can accept a block.

# File lib/padrino-auth/access.rb, line 117
def access_action?(action = nil, object = nil, &block)
  return true if response.status/100 == 4 && settings.access_errors
  if respond_to?(:request) && action.nil? && object.nil?
    object = request.controller
    action = request.action
    if object.nil? && action.present? && action.to_s.index('/')
      object, action = request.env['PATH_INFO'].to_s.scan(/\/([^\/]*)/).map(&:first)
    end
    object ||= :''
    action ||= :index
    object = object.to_sym
    action = action.to_sym
  end
  settings.permissions.check(access_subject, :allow => action, :with => object, &block)
end
access_object?(object = nil, action = nil, &block) click to toggle source

Check if current visitor is allowed to interact with object by action. Can accept a block.

# File lib/padrino-auth/access.rb, line 136
def access_object?(object = nil, action = nil, &block)
  allow_action action, object, &block
end
access_objects(subject = access_subject, action = nil) click to toggle source

Populates the list of objects the current visitor is allowed to interact with.

# File lib/padrino-auth/access.rb, line 143
def access_objects(subject = access_subject, action = nil)
  settings.permissions.find_objects(subject, action)
end
access_role?(*roles, &block) click to toggle source

Checks if current visitor is one of the specified roles. Can accept a block.

# File lib/padrino-auth/access.rb, line 110
def access_role?(*roles, &block)
  settings.permissions.check(access_subject, :have => roles, &block)
end
access_subject() click to toggle source

Returns current visitor.

# File lib/padrino-auth/access.rb, line 103
def access_subject
  send settings.credentials_reader
end
authorized?() click to toggle source

Checks if current visitor has access to current action with current controller.

# File lib/padrino-auth/access.rb, line 96
def authorized?
  access_action?
end