Module: Mongoid::Roles::Subject
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid/roles/subject.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#has_role!(role, auth_object = nil) ⇒ Object
Assigns a role for the object to the subject.
Instance Method Details
#has_role!(role, auth_object = nil) ⇒ Object
Assigns a role for the object to the subject. Does nothing is subject already has such a role.
45 46 47 48 49 50 51 |
# File 'lib/mongoid/roles/subject.rb', line 45 def has_role! (role, auth_object = nil) # p roles.find(:role => role, :auth_object => auth_object).first auth_object ? roles.find_or_create_by(:role => role, :auth_object_id => auth_object.id.to_s, :auth_object_type => auth_object.class.name) : roles.find_or_create_by(:role => role, :auth_object_id => nil, :auth_object_type => nil) end |