Module: Roleable::Resource
- Defined in:
- lib/roleable/resource.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#subjects_with_role(role_name) ⇒ Object
Return a list of users that have the given role for this resource.
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/roleable/resource.rb', line 3 def self.included(base) base.has_many :applied_roles, :as => :resource, :dependent => :destroy end |
Instance Method Details
#subjects_with_role(role_name) ⇒ Object
Return a list of users that have the given role for this resource. If a list of role names is given, return users with any of those roles for this resource.
Examples
page.subjects_with_role(:editor) # => [user1, user2, ...]
page.subjects_with_role([:editor, :author]) # => [user1, user2, ...]
15 16 17 18 |
# File 'lib/roleable/resource.rb', line 15 def subjects_with_role(role_name) subject_class.joins(:applied_roles). merge( ::AppliedRole.with_role_name(role_name).with_resource(self) ) end |