Skip to content

Roles strategy configuration

theunraveler edited this page Apr 7, 2011 · 2 revisions

The strategies using an inline attribute on the User class are: admin_flag, role_string, role_strings, roles_string, roles_mask

Example: admin_flag

class User
  include Roles::Generic
  strategy :admin_flag   
  valid_roles_are :guest, :admin
end

The include Roles::Generic can be substituted with another module if you are using an ORM implementation of Roles. The call to #strategy sets up the User with the given strategy and the default option means that the default name for the attribute is used. The call _#valid_roles_are is used to define which roles are valid and can be assigned to the user (using fx user.role = :guest)

Separate Role model strategies

The strategies using a separate Role class to hold the role(s) are: one_role, many_roles For some document stores supporting embedded documents the following are also available: embed_one_role, embed_many_roles

Example: many_roles

class User
  include Roles::Generic
  strategy :many_roles
  valid_roles_are :guest, :admin, :editor
end

The Roles are configured just the same. All the magic of linking everything together is done behind the scenes ;)

Clone this wiki locally