Module: RightOn::RoleModel

Defined in:
lib/right_on/role_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
# File 'lib/right_on/role_model.rb', line 3

def self.included(base)
  base.module_eval 'has_and_belongs_to_many :roles, :class_name => "RightOn::Role"'
  Role.module_eval "has_and_belongs_to_many :#{base.table_name}"
end

Instance Method Details

#has_privileges_of?(other_user) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/right_on/role_model.rb', line 16

def has_privileges_of?(other_user)
  (other_user.rights - rights).empty?
end

#rightsObject



8
9
10
11
12
13
14
# File 'lib/right_on/role_model.rb', line 8

def rights
  @rights ||=
    Right
      .select('distinct rights.*')
      .joins(:roles)
      .where('rights_roles.role_id IN (?)', role_ids)
end