module Ratify::ClassMethods

The methods in this module are added to the object's class methods when {Ratify} is included.

Public Instance Methods

permissions() click to toggle source

All of the permissions for the object.

@return [Array<Permission>] List of permissions.

# File lib/ratify.rb, line 29
def permissions
  @permissions ||= []
end
permit(object, *actions, **conditions) click to toggle source

Creates a new permission for the object.

@example Basic usage

include Ratify
permit User, :create, :read, :update, :destroy, if: :admin?

@return [Array<Permission>] All of the permissions after they're updated.

# File lib/ratify.rb, line 40
def permit(object, *actions, **conditions)
  permissions << Permission.new(object, *actions, **conditions)
end
permits?(object, *actions, scope: nil) click to toggle source

Checks if the given object is allowed to perform the requested action(s).

@param [Object] object The object requesting the action(s). @param [*Symbol] actions The action(s) being requested. @param [Object] scope The scope of permissible object. @return [true | false] Whether or not the object is permitted.

# File lib/ratify.rb, line 50
def permits?(object, *actions, scope: nil)
  permissions.any? { |m| m.permits?(object, *actions, scope: scope) }
end