module ActionControl

@author Tobias Feistmantl

Helper methods for your controller to identify RESTful actions.

@author Tobias Feistmantl

Constants

VERSION

Public Instance Methods

authenticate!() click to toggle source

Authenticates the user

# File lib/action_control.rb, line 30
def authenticate!
        # Raise an error if the #authenticate? action isn't defined.
        #
        # This ensures that you actually do authentication in your controller.
        raise ActionControl::AuthenticationNotPerformedError unless defined?(authenticated?)
        
        error = {}
        is_authenticated = nil

        if method(:authenticated?).arity > 0
                is_authenticated = authenticated?(error)
        else
                is_authenticated = authenticated?
        end
        
        # If the authenticated? method returns not true
        # it raises the ActionControl::NotAuthenticatedError.
        #
        # Use the .rescue_from method from ActionController::Base
        # to catch the exception and show the user a proper error message.
        raise ActionControl::NotAuthenticatedError.new(error) unless is_authenticated == true
end
authorize!() click to toggle source

Authorizes the user.

# File lib/action_control.rb, line 6
def authorize!
        # Raise an error if the #authorize? action isn't defined.
        #
        # This ensures that you actually do authorization in your controller.
        raise ActionControl::AuthorizationNotPerformedError unless defined?(authorized?)
        
        error = {}
        is_authorized = nil

        if method(:authorized?).arity > 0
                is_authorized = authorized?(error)
        else
                is_authorized = authorized?
        end

        # If the authorized? method does not return true
        # it raises the ActionControl::NotAuthorizedError
        #
        # Use the .rescue_from method from ActionController::Base
        # to catch the exception and show the user a proper error message.
        raise ActionControl::NotAuthorizedError.new(error) unless is_authorized == true
end
change_action?() click to toggle source

@return [Boolean]

True if the called action
is a change action.
# File lib/action_control/controller_methods.rb, line 28
def change_action?
        action_name == 'edit' ||
        action_name == 'update' ||
        action_name == 'destroy'
end
create_action?() click to toggle source

@note

Also true for the pseudo
update action `new`.

@note

Only true for create methods
such as new and create.

@return [Boolean]

True if the called action
is a create action.
# File lib/action_control/controller_methods.rb, line 59
def create_action?
        action_name == 'new' ||
        action_name == 'create'
end
delete_action?()
Alias for: destroy_action?
destroy_action?() click to toggle source

@return [Boolean]

True if it's a destroy action.
# File lib/action_control/controller_methods.rb, line 78
def destroy_action?
        action_name == 'destroy'
end
Also aliased as: delete_action?
index_action?() click to toggle source

@return [Boolean]

True if the called action
is the index action.
# File lib/action_control/controller_methods.rb, line 37
def index_action?
        action_name == 'index'
end
read_action?() click to toggle source

@return [Boolean]

True if the called action
is a only-read action.
# File lib/action_control/controller_methods.rb, line 9
def read_action?
        action_name == 'index' ||
        action_name == 'show'
end
show_action?() click to toggle source

@return [Boolean]

True if the called action
is the show action.
# File lib/action_control/controller_methods.rb, line 44
def show_action?
        action_name == 'show'
end
update_action?() click to toggle source

@note

Also true for the pseudo
update action `edit`.

@return [Boolean]

True if the called action
is a update action.
# File lib/action_control/controller_methods.rb, line 71
def update_action?
        action_name == 'edit' ||
        action_name == 'update'
end
write_action?() click to toggle source

@return [Boolean]

True if the called action
is a write action.
# File lib/action_control/controller_methods.rb, line 17
def write_action?
        action_name == 'new' ||
        action_name == 'create' ||
        action_name == 'edit' ||
        action_name == 'update' ||
        action_name == 'destroy'
end