8
9
10
11
12
13
14
15
16
|
# File 'lib/roles/role.rb', line 8
def with_role(role_name, resource = nil)
if resource.nil?
self.includes(:roles).where("roles.name LIKE '%s'", role_name.to_s).where("roles.resource_type IS NULL").where("roles.resource_id IS NULL")
elsif resource.is_a? Class
self.includes(:roles).where("roles.name LIKE '%s'", role_name.to_s).where("roles.resource_type LIKE '%s'", resource.to_s).where("roles.resource_id IS NULL")
else
self.includes(:roles).where("roles.name LIKE '%s'", role_name.to_s).where("roles.resource_type LIKE '%s'", resource.class.to_s).where("roles.resource_id = %s", resource.id)
end
end
|