Class: Mongoid::Roles::Role
- Inherits:
-
Object
- Object
- Mongoid::Roles::Role
- Includes:
- Document
- Defined in:
- lib/mongoid/roles/role.rb
Class Method Summary collapse
-
.has_no_role!(role, object = nil) ⇒ Object
subject.has_no_role!(role, object = nil).
-
.has_no_roles! ⇒ Object
subject.has_no_roles!.
-
.has_no_roles_for!(object) ⇒ Object
subject.has_no_roles_for!(object).
-
.has_role?(role, object = nil) ⇒ Boolean
subject.has_role?(role, object = nil).
-
.has_role_for?(object) ⇒ Boolean
subject.has_role_for?(object).
-
.has_roles_for?(object) ⇒ Boolean
subject.has_roles_for?(object).
-
.roles_for(object) ⇒ Object
subject.roles_for(object).
Instance Method Summary collapse
Class Method Details
.has_no_role!(role, object = nil) ⇒ Object
subject.has_no_role!(role, object = nil). Unassigns a role from the subject.
30 31 32 |
# File 'lib/mongoid/roles/role.rb', line 30 def has_no_role! (role, object = nil) find_role(role,object).destroy_all end |
.has_no_roles! ⇒ Object
subject.has_no_roles!. Unassign all roles from subject.
56 57 58 |
# File 'lib/mongoid/roles/role.rb', line 56 def has_no_roles! criteria.destroy_all end |
.has_no_roles_for!(object) ⇒ Object
subject.has_no_roles_for!(object). Unassign any subject ’s roles for a given object.
51 52 53 |
# File 'lib/mongoid/roles/role.rb', line 51 def has_no_roles_for! (object) find_object(object).destroy_all end |
.has_role?(role, object = nil) ⇒ Boolean
subject.has_role?(role, object = nil). Returns true of false (has or has not).
21 22 23 |
# File 'lib/mongoid/roles/role.rb', line 21 def has_role? (role, object = nil) find_role(role,object).count == 1 end |
.has_role_for?(object) ⇒ Boolean
subject.has_role_for?(object). Same as has_roles_for?.
40 41 42 |
# File 'lib/mongoid/roles/role.rb', line 40 def has_role_for? (object) has_roles_for?(object) end |
.has_roles_for?(object) ⇒ Boolean
subject.has_roles_for?(object). Does the subject has any roles for object? (true of false)
35 36 37 |
# File 'lib/mongoid/roles/role.rb', line 35 def has_roles_for? (object) find_object(object).count > 0 end |
.roles_for(object) ⇒ Object
subject.roles_for(object). Returns an array of Role instances, corresponding to subject ’s roles on object. E.g. subject.roles_for(object).map(&:name).sort will give you role names in alphabetical order.
46 47 48 |
# File 'lib/mongoid/roles/role.rb', line 46 def roles_for (object) find_object(object) end |
Instance Method Details
#auth_object ⇒ Object
67 68 69 70 71 |
# File 'lib/mongoid/roles/role.rb', line 67 def auth_object @auth_object ||= if auth_object_type && auth_object_id auth_object_type.constantize.find(auth_object_id) end end |
#auth_object=(auth_object) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/mongoid/roles/role.rb', line 73 def auth_object=(auth_object) return unless auth_object self.auth_object_type = auth_object.class.name self.auth_object_id = auth_object.id end |